Chromium Code Reviews| 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. | |
| 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 XRandR. | |
| 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: | |
| 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: | |
| 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() { | |
| 65 Display* display = ui::GetXDisplay(); | |
| 66 | |
| 67 ::Window root, child; | |
| 68 int root_x, root_y, win_x, win_y; | |
| 69 unsigned int mask; | |
| 70 XQueryPointer(display, | |
| 71 DefaultRootWindow(display), | |
| 72 &root, | |
| 73 &child, | |
| 74 &root_x, | |
| 75 &root_y, | |
| 76 &win_x, | |
| 77 &win_y, | |
| 78 &mask); | |
| 79 | |
| 80 return gfx::Point(root_x, root_y); | |
| 81 } | |
| 82 | |
| 83 gfx::NativeWindow DesktopScreenX11::GetWindowAtCursorScreenPoint() { | |
|
Daniel Erat
2012/05/02 21:32:31
nit: add a comment mentioning that this is optiona
| |
| 84 return NULL; | |
| 85 } | |
| 86 | |
| 87 int DesktopScreenX11::GetNumMonitors() { | |
| 88 // TODO(erg): Figure this out with oshima or piman because I have no clue | |
| 89 // about the Xinerama implications here. | |
|
Daniel Erat
2012/05/02 21:32:31
nit: s/Xinerama/XRandR/
| |
| 90 return 1; | |
| 91 } | |
| 92 | |
| 93 gfx::Monitor DesktopScreenX11::GetMonitorNearestWindow( | |
| 94 gfx::NativeView window) const { | |
| 95 // TODO(erg): Do the right thing once we know what that is. | |
| 96 return gfx::Monitor(0, gfx::Rect(GetPrimaryMonitorSize())); | |
| 97 } | |
| 98 | |
| 99 gfx::Monitor DesktopScreenX11::GetMonitorNearestPoint( | |
| 100 const gfx::Point& point) const { | |
| 101 // TODO(erg): Do the right thing once we know what that is. | |
| 102 return gfx::Monitor(0, gfx::Rect(GetPrimaryMonitorSize())); | |
| 103 } | |
| 104 | |
| 105 gfx::Monitor DesktopScreenX11::GetPrimaryMonitor() const { | |
| 106 // TODO(erg): Do the right thing once we know what that is. | |
| 107 return gfx::Monitor(0, gfx::Rect(GetPrimaryMonitorSize())); | |
| 108 } | |
| 109 | |
| 110 } // namespace | |
| 111 | |
| 112 //////////////////////////////////////////////////////////////////////////////// | |
| 7 | 113 |
| 8 namespace aura { | 114 namespace aura { |
| 9 | 115 |
| 10 //////////////////////////////////////////////////////////////////////////////// | |
| 11 | |
| 12 gfx::ScreenImpl* CreateDesktopScreen() { | 116 gfx::ScreenImpl* CreateDesktopScreen() { |
| 13 NOTIMPLEMENTED(); // TODO(erg): implement me! | 117 return new DesktopScreenX11; |
| 14 return NULL; | |
| 15 } | 118 } |
| 16 | 119 |
| 17 } // namespace aura | 120 } // namespace aura |
| OLD | NEW |