OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/aura/desktop/desktop_screen.h" | |
6 | |
7 #include <X11/Xlib.h> | |
8 | |
9 // It clashes with out RootWindow. | |
Daniel Erat
2012/05/01 22:51:48
nit: s/out/our/
| |
10 #undef RootWindow | |
11 | |
5 #include "base/logging.h" | 12 #include "base/logging.h" |
6 #include "ui/aura/desktop/desktop_screen.h" | 13 #include "ui/aura/root_window.h" |
14 #include "ui/aura/root_window_host.h" | |
15 #include "ui/base/x/x11_util.h" | |
16 #include "ui/gfx/monitor.h" | |
17 #include "ui/gfx/native_widget_types.h" | |
18 #include "ui/gfx/screen_impl.h" | |
19 | |
20 namespace { | |
21 | |
22 // TODO(erg): This method is a temporary hack, until we can reliably extract | |
23 // location data out of Xinerama. | |
Daniel Erat
2012/05/01 22:51:48
s/Xinerama/XRandR, i think
| |
24 gfx::Size GetPrimaryMonitorSize() { | |
25 ::Display* display = ui::GetXDisplay(); | |
26 ::Screen* screen = DefaultScreenOfDisplay(display); | |
27 int width = WidthOfScreen(screen); | |
28 int height = HeightOfScreen(screen); | |
29 | |
30 return gfx::Size(width, height); | |
31 } | |
32 | |
33 class DesktopScreenX11 : public gfx::ScreenImpl { | |
34 public: | |
Ben Goodger (Google)
2012/05/01 22:38:41
nit: lead with 1 space
| |
35 DesktopScreenX11(); | |
36 virtual ~DesktopScreenX11(); | |
37 | |
38 // Overridden from gfx::ScreenImpl: | |
39 virtual gfx::Point GetCursorScreenPoint() OVERRIDE; | |
40 virtual gfx::NativeWindow GetWindowAtCursorScreenPoint() OVERRIDE; | |
41 virtual int GetNumMonitors() OVERRIDE; | |
42 virtual gfx::Monitor GetMonitorNearestWindow( | |
43 gfx::NativeView window) const OVERRIDE; | |
44 virtual gfx::Monitor GetMonitorNearestPoint( | |
45 const gfx::Point& point) const OVERRIDE; | |
46 virtual gfx::Monitor GetPrimaryMonitor() const OVERRIDE; | |
47 | |
48 private: | |
Ben Goodger (Google)
2012/05/01 22:38:41
ditto
| |
49 DISALLOW_COPY_AND_ASSIGN(DesktopScreenX11); | |
50 }; | |
51 | |
52 //////////////////////////////////////////////////////////////////////////////// | |
53 // DesktopScreenX11, public: | |
54 | |
55 DesktopScreenX11::DesktopScreenX11() { | |
56 } | |
57 | |
58 DesktopScreenX11::~DesktopScreenX11() { | |
59 } | |
60 | |
61 //////////////////////////////////////////////////////////////////////////////// | |
62 // DesktopScreenX11, gfx::ScreenImpl implementation: | |
63 | |
64 gfx::Point DesktopScreenX11::GetCursorScreenPoint() { | |
Daniel Erat
2012/05/01 22:51:48
i'm a bit worried that this method gets called wit
| |
65 Display* display = ui::GetXDisplay(); | |
66 | |
67 // Unsure if I can leave these as NULL. | |
Daniel Erat
2012/05/01 22:51:48
pretty sure you can't
| |
68 ::Window root, child; | |
69 int root_x, root_y, win_x, win_y; | |
70 unsigned int mask; | |
71 XQueryPointer(display, | |
72 DefaultRootWindow(display), | |
73 &root, | |
74 &child, | |
75 &root_x, | |
76 &root_y, | |
77 &win_x, | |
78 &win_y, | |
79 &mask); | |
80 | |
81 return gfx::Point(root_x, root_y); | |
82 } | |
83 | |
84 gfx::NativeWindow DesktopScreenX11::GetWindowAtCursorScreenPoint() { | |
85 gfx::Point cursor = GetCursorScreenPoint(); | |
86 gfx::NativeWindow out_window = NULL; | |
87 | |
88 // Iterate across the return values of XQuerryTree() here, which are sorted | |
Daniel Erat
2012/05/01 22:51:48
nit: s/XQuerryTree/XQueryTree/
| |
89 // in z-order. | |
Daniel Erat
2012/05/01 22:51:48
nit: mention in the comment that they're in bottom
| |
90 Display* display = ui::GetXDisplay(); | |
91 ::Window root, parent; | |
92 unsigned int num_children = 0; | |
93 ::Window *children = NULL; | |
94 | |
95 if (XQueryTree(display, DefaultRootWindow(display), &root, &parent, | |
Daniel Erat
2012/05/01 22:51:48
note that if you intend to use this to find window
| |
96 &children, &num_children)) { | |
Daniel Erat
2012/05/01 22:51:48
nit: return early on failure instead of indenting
| |
97 for (unsigned int i = 0; i < num_children; ++i) { | |
98 aura::RootWindowHost* host = | |
99 aura::RootWindowHost::GetForAcceleratedWidget(children[i]); | |
Daniel Erat
2012/05/01 22:51:48
actually, is this backwards? you want the topmost
| |
100 if (host) { | |
101 out_window = host->GetRootWindow(); | |
102 break; | |
103 } | |
104 } | |
105 | |
106 if (children) | |
107 XFree(children); | |
108 } | |
109 | |
110 return out_window; | |
111 } | |
112 | |
113 int DesktopScreenX11::GetNumMonitors() { | |
114 // TODO(erg): Figure this out with oshima or piman because I have no clue | |
115 // about the Xinerama implications here. | |
116 return 1; | |
117 } | |
118 | |
119 gfx::Monitor DesktopScreenX11::GetMonitorNearestWindow( | |
120 gfx::NativeView window) const { | |
121 // TODO(erg): Do the right thing once we know what that is. | |
122 return gfx::Monitor(0, gfx::Rect(GetPrimaryMonitorSize())); | |
123 } | |
124 | |
125 gfx::Monitor DesktopScreenX11::GetMonitorNearestPoint( | |
126 const gfx::Point& point) const { | |
127 // TODO(erg): Do the right thing once we know what that is. | |
128 return gfx::Monitor(0, gfx::Rect(GetPrimaryMonitorSize())); | |
129 } | |
130 | |
131 gfx::Monitor DesktopScreenX11::GetPrimaryMonitor() const { | |
132 // TODO(erg): Do the right thing once we know what that is. | |
133 return gfx::Monitor(0, gfx::Rect(GetPrimaryMonitorSize())); | |
134 } | |
135 | |
136 } // namespace | |
137 | |
138 //////////////////////////////////////////////////////////////////////////////// | |
7 | 139 |
8 namespace aura { | 140 namespace aura { |
9 | 141 |
10 //////////////////////////////////////////////////////////////////////////////// | |
11 | |
12 gfx::ScreenImpl* CreateDesktopScreen() { | 142 gfx::ScreenImpl* CreateDesktopScreen() { |
13 NOTIMPLEMENTED(); // TODO(erg): implement me! | 143 return new DesktopScreenX11; |
14 return NULL; | |
15 } | 144 } |
16 | 145 |
17 } // namespace aura | 146 } // namespace aura |
OLD | NEW |