Index: ui/aura/desktop/desktop_screen_x11.cc |
diff --git a/ui/aura/desktop/desktop_screen_x11.cc b/ui/aura/desktop/desktop_screen_x11.cc |
index a001df0e9d857933ebb1061fc98f1c095c08f0fd..9a3707d915187fb704c650999b7638a0a7b2e046 100644 |
--- a/ui/aura/desktop/desktop_screen_x11.cc |
+++ b/ui/aura/desktop/desktop_screen_x11.cc |
@@ -2,16 +2,145 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-#include "base/logging.h" |
#include "ui/aura/desktop/desktop_screen.h" |
-namespace aura { |
+#include <X11/Xlib.h> |
+ |
+// It clashes with out RootWindow. |
Daniel Erat
2012/05/01 22:51:48
nit: s/out/our/
|
+#undef RootWindow |
+ |
+#include "base/logging.h" |
+#include "ui/aura/root_window.h" |
+#include "ui/aura/root_window_host.h" |
+#include "ui/base/x/x11_util.h" |
+#include "ui/gfx/monitor.h" |
+#include "ui/gfx/native_widget_types.h" |
+#include "ui/gfx/screen_impl.h" |
+ |
+namespace { |
+ |
+// TODO(erg): This method is a temporary hack, until we can reliably extract |
+// location data out of Xinerama. |
Daniel Erat
2012/05/01 22:51:48
s/Xinerama/XRandR, i think
|
+gfx::Size GetPrimaryMonitorSize() { |
+ ::Display* display = ui::GetXDisplay(); |
+ ::Screen* screen = DefaultScreenOfDisplay(display); |
+ int width = WidthOfScreen(screen); |
+ int height = HeightOfScreen(screen); |
+ |
+ return gfx::Size(width, height); |
+} |
+ |
+class DesktopScreenX11 : public gfx::ScreenImpl { |
+public: |
Ben Goodger (Google)
2012/05/01 22:38:41
nit: lead with 1 space
|
+ DesktopScreenX11(); |
+ virtual ~DesktopScreenX11(); |
+ |
+ // Overridden from gfx::ScreenImpl: |
+ virtual gfx::Point GetCursorScreenPoint() OVERRIDE; |
+ virtual gfx::NativeWindow GetWindowAtCursorScreenPoint() OVERRIDE; |
+ virtual int GetNumMonitors() OVERRIDE; |
+ virtual gfx::Monitor GetMonitorNearestWindow( |
+ gfx::NativeView window) const OVERRIDE; |
+ virtual gfx::Monitor GetMonitorNearestPoint( |
+ const gfx::Point& point) const OVERRIDE; |
+ virtual gfx::Monitor GetPrimaryMonitor() const OVERRIDE; |
+ |
+private: |
Ben Goodger (Google)
2012/05/01 22:38:41
ditto
|
+ DISALLOW_COPY_AND_ASSIGN(DesktopScreenX11); |
+}; |
+ |
+//////////////////////////////////////////////////////////////////////////////// |
+// DesktopScreenX11, public: |
+ |
+DesktopScreenX11::DesktopScreenX11() { |
+} |
+ |
+DesktopScreenX11::~DesktopScreenX11() { |
+} |
//////////////////////////////////////////////////////////////////////////////// |
+// DesktopScreenX11, gfx::ScreenImpl implementation: |
+ |
+gfx::Point DesktopScreenX11::GetCursorScreenPoint() { |
Daniel Erat
2012/05/01 22:51:48
i'm a bit worried that this method gets called wit
|
+ Display* display = ui::GetXDisplay(); |
+ |
+ // Unsure if I can leave these as NULL. |
Daniel Erat
2012/05/01 22:51:48
pretty sure you can't
|
+ ::Window root, child; |
+ int root_x, root_y, win_x, win_y; |
+ unsigned int mask; |
+ XQueryPointer(display, |
+ DefaultRootWindow(display), |
+ &root, |
+ &child, |
+ &root_x, |
+ &root_y, |
+ &win_x, |
+ &win_y, |
+ &mask); |
+ |
+ return gfx::Point(root_x, root_y); |
+} |
+ |
+gfx::NativeWindow DesktopScreenX11::GetWindowAtCursorScreenPoint() { |
+ gfx::Point cursor = GetCursorScreenPoint(); |
+ gfx::NativeWindow out_window = NULL; |
+ |
+ // Iterate across the return values of XQuerryTree() here, which are sorted |
Daniel Erat
2012/05/01 22:51:48
nit: s/XQuerryTree/XQueryTree/
|
+ // in z-order. |
Daniel Erat
2012/05/01 22:51:48
nit: mention in the comment that they're in bottom
|
+ Display* display = ui::GetXDisplay(); |
+ ::Window root, parent; |
+ unsigned int num_children = 0; |
+ ::Window *children = NULL; |
+ |
+ 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
|
+ &children, &num_children)) { |
Daniel Erat
2012/05/01 22:51:48
nit: return early on failure instead of indenting
|
+ for (unsigned int i = 0; i < num_children; ++i) { |
+ aura::RootWindowHost* host = |
+ aura::RootWindowHost::GetForAcceleratedWidget(children[i]); |
Daniel Erat
2012/05/01 22:51:48
actually, is this backwards? you want the topmost
|
+ if (host) { |
+ out_window = host->GetRootWindow(); |
+ break; |
+ } |
+ } |
+ |
+ if (children) |
+ XFree(children); |
+ } |
+ |
+ return out_window; |
+} |
+ |
+int DesktopScreenX11::GetNumMonitors() { |
+ // TODO(erg): Figure this out with oshima or piman because I have no clue |
+ // about the Xinerama implications here. |
+ return 1; |
+} |
+ |
+gfx::Monitor DesktopScreenX11::GetMonitorNearestWindow( |
+ gfx::NativeView window) const { |
+ // TODO(erg): Do the right thing once we know what that is. |
+ return gfx::Monitor(0, gfx::Rect(GetPrimaryMonitorSize())); |
+} |
+ |
+gfx::Monitor DesktopScreenX11::GetMonitorNearestPoint( |
+ const gfx::Point& point) const { |
+ // TODO(erg): Do the right thing once we know what that is. |
+ return gfx::Monitor(0, gfx::Rect(GetPrimaryMonitorSize())); |
+} |
+ |
+gfx::Monitor DesktopScreenX11::GetPrimaryMonitor() const { |
+ // TODO(erg): Do the right thing once we know what that is. |
+ return gfx::Monitor(0, gfx::Rect(GetPrimaryMonitorSize())); |
+} |
+ |
+} // namespace |
+ |
+//////////////////////////////////////////////////////////////////////////////// |
+ |
+namespace aura { |
gfx::ScreenImpl* CreateDesktopScreen() { |
- NOTIMPLEMENTED(); // TODO(erg): implement me! |
- return NULL; |
+ return new DesktopScreenX11; |
} |
} // namespace aura |