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/views/widget/desktop_aura/desktop_screen.h" | 5 #include "ui/views/widget/desktop_aura/desktop_screen.h" |
6 | 6 |
7 #include <X11/Xlib.h> | |
8 | |
9 // It clashes with out RootWindow. | |
10 #undef RootWindow | |
11 | |
12 #include "base/logging.h" | 7 #include "base/logging.h" |
13 #include "ui/aura/root_window.h" | 8 #include "ui/aura/root_window.h" |
14 #include "ui/aura/root_window_host.h" | 9 #include "ui/aura/root_window_host.h" |
15 #include "ui/base/x/x11_util.h" | |
16 #include "ui/gfx/display.h" | 10 #include "ui/gfx/display.h" |
17 #include "ui/gfx/native_widget_types.h" | 11 #include "ui/gfx/native_widget_types.h" |
18 #include "ui/gfx/screen.h" | 12 #include "ui/gfx/screen.h" |
| 13 #include "ui/wayland/wayland_display.h" |
| 14 #include "ui/wayland/wayland_screen.h" |
19 | 15 |
20 namespace { | 16 namespace { |
21 | 17 |
22 // TODO(erg): This method is a temporary hack, until we can reliably extract | |
23 // location data out of XRandR. | |
24 gfx::Size GetPrimaryDisplaySize() { | 18 gfx::Size GetPrimaryDisplaySize() { |
25 ::Display* display = ui::GetXDisplay(); | 19 ui::WaylandDisplay* display = ui::WaylandDisplay::GetDisplay(); |
26 ::Screen* screen = DefaultScreenOfDisplay(display); | 20 std::list<ui::WaylandScreen*> screens = display->GetScreenList(); |
27 int width = WidthOfScreen(screen); | 21 return screens.empty() ? gfx::Size() : screens.front()->GetAllocation().size()
; |
28 int height = HeightOfScreen(screen); | |
29 | |
30 return gfx::Size(width, height); | |
31 } | 22 } |
32 | 23 |
33 class DesktopScreenX11 : public gfx::Screen { | 24 class DesktopScreenWayland : public gfx::Screen { |
34 public: | 25 public: |
35 DesktopScreenX11(); | 26 DesktopScreenWayland(); |
36 virtual ~DesktopScreenX11(); | 27 virtual ~DesktopScreenWayland(); |
37 | 28 |
38 // Overridden from gfx::Screen: | 29 // Overridden from gfx::Screen: |
39 virtual bool IsDIPEnabled() OVERRIDE; | 30 virtual bool IsDIPEnabled() OVERRIDE; |
40 virtual gfx::Point GetCursorScreenPoint() OVERRIDE; | 31 virtual gfx::Point GetCursorScreenPoint() OVERRIDE; |
41 virtual gfx::NativeWindow GetWindowAtCursorScreenPoint() OVERRIDE; | 32 virtual gfx::NativeWindow GetWindowAtCursorScreenPoint() OVERRIDE; |
42 virtual int GetNumDisplays() OVERRIDE; | 33 virtual int GetNumDisplays() OVERRIDE; |
43 virtual gfx::Display GetDisplayNearestWindow( | 34 virtual gfx::Display GetDisplayNearestWindow( |
44 gfx::NativeView window) const OVERRIDE; | 35 gfx::NativeView window) const OVERRIDE; |
45 virtual gfx::Display GetDisplayNearestPoint( | 36 virtual gfx::Display GetDisplayNearestPoint( |
46 const gfx::Point& point) const OVERRIDE; | 37 const gfx::Point& point) const OVERRIDE; |
47 virtual gfx::Display GetDisplayMatching( | 38 virtual gfx::Display GetDisplayMatching( |
48 const gfx::Rect& match_rect) const OVERRIDE; | 39 const gfx::Rect& match_rect) const OVERRIDE; |
49 virtual gfx::Display GetPrimaryDisplay() const OVERRIDE; | 40 virtual gfx::Display GetPrimaryDisplay() const OVERRIDE; |
50 virtual void AddObserver(gfx::DisplayObserver* observer) OVERRIDE; | 41 virtual void AddObserver(gfx::DisplayObserver* observer) OVERRIDE; |
51 virtual void RemoveObserver(gfx::DisplayObserver* observer) OVERRIDE; | 42 virtual void RemoveObserver(gfx::DisplayObserver* observer) OVERRIDE; |
52 | 43 |
53 private: | 44 private: |
54 DISALLOW_COPY_AND_ASSIGN(DesktopScreenX11); | 45 DISALLOW_COPY_AND_ASSIGN(DesktopScreenWayland); |
55 }; | 46 }; |
56 | 47 |
57 //////////////////////////////////////////////////////////////////////////////// | 48 //////////////////////////////////////////////////////////////////////////////// |
58 // DesktopScreenX11, public: | 49 // DesktopScreenWayland, public: |
59 | 50 |
60 DesktopScreenX11::DesktopScreenX11() { | 51 DesktopScreenWayland::DesktopScreenWayland() { |
61 } | 52 } |
62 | 53 |
63 DesktopScreenX11::~DesktopScreenX11() { | 54 DesktopScreenWayland::~DesktopScreenWayland() { |
64 } | 55 } |
65 | 56 |
66 //////////////////////////////////////////////////////////////////////////////// | 57 //////////////////////////////////////////////////////////////////////////////// |
67 // DesktopScreenX11, gfx::Screen implementation: | 58 // DesktopScreenWayland, gfx::Screen implementation: |
68 | 59 |
69 bool DesktopScreenX11::IsDIPEnabled() { | 60 bool DesktopScreenWayland::IsDIPEnabled() { |
70 return false; | 61 return false; |
71 } | 62 } |
72 | 63 |
73 gfx::Point DesktopScreenX11::GetCursorScreenPoint() { | 64 gfx::Point DesktopScreenWayland::GetCursorScreenPoint() { |
74 Display* display = ui::GetXDisplay(); | 65 return gfx::Point(); |
75 | |
76 ::Window root, child; | |
77 int root_x, root_y, win_x, win_y; | |
78 unsigned int mask; | |
79 XQueryPointer(display, | |
80 DefaultRootWindow(display), | |
81 &root, | |
82 &child, | |
83 &root_x, | |
84 &root_y, | |
85 &win_x, | |
86 &win_y, | |
87 &mask); | |
88 | |
89 return gfx::Point(root_x, root_y); | |
90 } | 66 } |
91 | 67 |
92 gfx::NativeWindow DesktopScreenX11::GetWindowAtCursorScreenPoint() { | 68 gfx::NativeWindow DesktopScreenWayland::GetWindowAtCursorScreenPoint() { |
93 // TODO(erg): Implement using the discussion at | 69 // TODO(erg): Implement using the discussion at |
94 // http://codereview.chromium.org/10279005/ | 70 // http://codereview.chromium.org/10279005/ |
95 return NULL; | 71 return NULL; |
96 } | 72 } |
97 | 73 |
98 int DesktopScreenX11::GetNumDisplays() { | 74 int DesktopScreenWayland::GetNumDisplays() { |
99 // TODO(erg): Figure this out with oshima or piman because I have no clue | 75 // TODO(erg): Figure this out with oshima or piman because I have no clue |
100 // about the XRandR implications here. | 76 // about the XRandR implications here. |
101 return 1; | 77 return 1; |
102 } | 78 } |
103 | 79 |
104 gfx::Display DesktopScreenX11::GetDisplayNearestWindow( | 80 gfx::Display DesktopScreenWayland::GetDisplayNearestWindow( |
105 gfx::NativeView window) const { | 81 gfx::NativeView window) const { |
106 // TODO(erg): Do the right thing once we know what that is. | 82 // TODO(erg): Do the right thing once we know what that is. |
107 return gfx::Display(0, gfx::Rect(GetPrimaryDisplaySize())); | 83 return gfx::Display(0, gfx::Rect(GetPrimaryDisplaySize())); |
108 } | 84 } |
109 | 85 |
110 gfx::Display DesktopScreenX11::GetDisplayNearestPoint( | 86 gfx::Display DesktopScreenWayland::GetDisplayNearestPoint( |
111 const gfx::Point& point) const { | 87 const gfx::Point& point) const { |
112 // TODO(erg): Do the right thing once we know what that is. | 88 // TODO(erg): Do the right thing once we know what that is. |
113 return gfx::Display(0, gfx::Rect(GetPrimaryDisplaySize())); | 89 return gfx::Display(0, gfx::Rect(GetPrimaryDisplaySize())); |
114 } | 90 } |
115 | 91 |
116 gfx::Display DesktopScreenX11::GetDisplayMatching( | 92 gfx::Display DesktopScreenWayland::GetDisplayMatching( |
117 const gfx::Rect& match_rect) const { | 93 const gfx::Rect& match_rect) const { |
118 // TODO(erg): Do the right thing once we know what that is. | 94 // TODO(erg): Do the right thing once we know what that is. |
119 return gfx::Display(0, gfx::Rect(GetPrimaryDisplaySize())); | 95 return gfx::Display(0, gfx::Rect(GetPrimaryDisplaySize())); |
120 } | 96 } |
121 | 97 |
122 gfx::Display DesktopScreenX11::GetPrimaryDisplay() const { | 98 gfx::Display DesktopScreenWayland::GetPrimaryDisplay() const { |
123 // TODO(erg): Do the right thing once we know what that is. | 99 // TODO(erg): Do the right thing once we know what that is. |
124 return gfx::Display(0, gfx::Rect(GetPrimaryDisplaySize())); | 100 return gfx::Display(0, gfx::Rect(GetPrimaryDisplaySize())); |
125 } | 101 } |
126 | 102 |
127 void DesktopScreenX11::AddObserver(gfx::DisplayObserver* observer) { | 103 void DesktopScreenWayland::AddObserver(gfx::DisplayObserver* observer) { |
128 // TODO(erg|oshima): Do the right thing once we know what that is. | 104 // TODO(erg|oshima): Do the right thing once we know what that is. |
129 // crbug.com/122863 | 105 // crbug.com/122863 |
130 } | 106 } |
131 void DesktopScreenX11::RemoveObserver(gfx::DisplayObserver* observer) { | 107 void DesktopScreenWayland::RemoveObserver(gfx::DisplayObserver* observer) { |
132 // TODO(erg|oshima): Do the right thing once we know what that is. | 108 // TODO(erg|oshima): Do the right thing once we know what that is. |
133 // crbug.com/122863 | 109 // crbug.com/122863 |
134 } | 110 } |
135 | 111 |
136 } // namespace | 112 } // namespace |
137 | 113 |
138 //////////////////////////////////////////////////////////////////////////////// | 114 //////////////////////////////////////////////////////////////////////////////// |
139 | 115 |
140 namespace views { | 116 namespace views { |
141 | 117 |
142 gfx::Screen* CreateDesktopScreen() { | 118 gfx::Screen* CreateDesktopScreen() { |
143 return new DesktopScreenX11; | 119 return new DesktopScreenWayland; |
144 } | 120 } |
145 | 121 |
146 } // namespace views | 122 } // namespace views |
OLD | NEW |