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() { |
| 84 // TODO(erg): Implement using the discussion at |
| 85 // http://codereview.chromium.org/10279005/ |
| 86 return NULL; |
| 87 } |
| 88 |
| 89 int DesktopScreenX11::GetNumMonitors() { |
| 90 // TODO(erg): Figure this out with oshima or piman because I have no clue |
| 91 // about the XRandR implications here. |
| 92 return 1; |
| 93 } |
| 94 |
| 95 gfx::Monitor DesktopScreenX11::GetMonitorNearestWindow( |
| 96 gfx::NativeView window) const { |
| 97 // TODO(erg): Do the right thing once we know what that is. |
| 98 return gfx::Monitor(0, gfx::Rect(GetPrimaryMonitorSize())); |
| 99 } |
| 100 |
| 101 gfx::Monitor DesktopScreenX11::GetMonitorNearestPoint( |
| 102 const gfx::Point& point) const { |
| 103 // TODO(erg): Do the right thing once we know what that is. |
| 104 return gfx::Monitor(0, gfx::Rect(GetPrimaryMonitorSize())); |
| 105 } |
| 106 |
| 107 gfx::Monitor DesktopScreenX11::GetPrimaryMonitor() const { |
| 108 // TODO(erg): Do the right thing once we know what that is. |
| 109 return gfx::Monitor(0, gfx::Rect(GetPrimaryMonitorSize())); |
| 110 } |
| 111 |
| 112 } // namespace |
| 113 |
| 114 //////////////////////////////////////////////////////////////////////////////// |
7 | 115 |
8 namespace aura { | 116 namespace aura { |
9 | 117 |
10 //////////////////////////////////////////////////////////////////////////////// | |
11 | |
12 gfx::ScreenImpl* CreateDesktopScreen() { | 118 gfx::ScreenImpl* CreateDesktopScreen() { |
13 NOTIMPLEMENTED(); // TODO(erg): implement me! | 119 return new DesktopScreenX11; |
14 return NULL; | |
15 } | 120 } |
16 | 121 |
17 } // namespace aura | 122 } // namespace aura |
OLD | NEW |