OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "ash/host/ash_window_tree_host_x11.h" | 5 #include "ash/host/ash_window_tree_host_x11.h" |
6 | 6 |
7 #include <X11/extensions/Xfixes.h> | 7 #include <X11/extensions/Xfixes.h> |
8 #include <X11/extensions/XInput2.h> | 8 #include <X11/extensions/XInput2.h> |
9 #include <X11/Xatom.h> | 9 #include <X11/Xatom.h> |
10 #include <X11/Xlib.h> | 10 #include <X11/Xlib.h> |
(...skipping 26 matching lines...) Expand all Loading... |
37 : WindowTreeHostX11(initial_bounds), transformer_helper_(this) { | 37 : WindowTreeHostX11(initial_bounds), transformer_helper_(this) { |
38 transformer_helper_.Init(); | 38 transformer_helper_.Init(); |
39 aura::Env::GetInstance()->AddObserver(this); | 39 aura::Env::GetInstance()->AddObserver(this); |
40 } | 40 } |
41 | 41 |
42 AshWindowTreeHostX11::~AshWindowTreeHostX11() { | 42 AshWindowTreeHostX11::~AshWindowTreeHostX11() { |
43 aura::Env::GetInstance()->RemoveObserver(this); | 43 aura::Env::GetInstance()->RemoveObserver(this); |
44 UnConfineCursor(); | 44 UnConfineCursor(); |
45 } | 45 } |
46 | 46 |
47 void AshWindowTreeHostX11::ToggleFullScreen() { NOTIMPLEMENTED(); } | 47 void AshWindowTreeHostX11::ToggleFullScreen() { |
| 48 NOTIMPLEMENTED(); |
| 49 } |
48 | 50 |
49 bool AshWindowTreeHostX11::ConfineCursorToRootWindow() { | 51 bool AshWindowTreeHostX11::ConfineCursorToRootWindow() { |
50 #if XFIXES_MAJOR >= 5 | 52 #if XFIXES_MAJOR >= 5 |
51 DCHECK(!pointer_barriers_.get()); | 53 DCHECK(!pointer_barriers_.get()); |
52 if (pointer_barriers_) | 54 if (pointer_barriers_) |
53 return false; | 55 return false; |
54 pointer_barriers_.reset(new XID[4]); | 56 pointer_barriers_.reset(new XID[4]); |
55 gfx::Rect barrier(bounds()); | 57 gfx::Rect barrier(bounds()); |
56 barrier.Inset(transformer_helper_.GetHostInsets()); | 58 barrier.Inset(transformer_helper_.GetHostInsets()); |
57 // Horizontal, top barriers. | 59 // Horizontal, top barriers. |
58 pointer_barriers_[0] = XFixesCreatePointerBarrier(xdisplay(), | 60 pointer_barriers_[0] = XFixesCreatePointerBarrier( |
59 x_root_window(), | 61 xdisplay(), x_root_window(), barrier.x(), barrier.y(), barrier.right(), |
60 barrier.x(), | 62 barrier.y(), BarrierPositiveY, 0, XIAllDevices); |
61 barrier.y(), | |
62 barrier.right(), | |
63 barrier.y(), | |
64 BarrierPositiveY, | |
65 0, | |
66 XIAllDevices); | |
67 // Horizontal, bottom barriers. | 63 // Horizontal, bottom barriers. |
68 pointer_barriers_[1] = XFixesCreatePointerBarrier(xdisplay(), | 64 pointer_barriers_[1] = XFixesCreatePointerBarrier( |
69 x_root_window(), | 65 xdisplay(), x_root_window(), barrier.x(), barrier.bottom(), |
70 barrier.x(), | 66 barrier.right(), barrier.bottom(), BarrierNegativeY, 0, XIAllDevices); |
71 barrier.bottom(), | |
72 barrier.right(), | |
73 barrier.bottom(), | |
74 BarrierNegativeY, | |
75 0, | |
76 XIAllDevices); | |
77 // Vertical, left barriers. | 67 // Vertical, left barriers. |
78 pointer_barriers_[2] = XFixesCreatePointerBarrier(xdisplay(), | 68 pointer_barriers_[2] = XFixesCreatePointerBarrier( |
79 x_root_window(), | 69 xdisplay(), x_root_window(), barrier.x(), barrier.y(), barrier.x(), |
80 barrier.x(), | 70 barrier.bottom(), BarrierPositiveX, 0, XIAllDevices); |
81 barrier.y(), | |
82 barrier.x(), | |
83 barrier.bottom(), | |
84 BarrierPositiveX, | |
85 0, | |
86 XIAllDevices); | |
87 // Vertical, right barriers. | 71 // Vertical, right barriers. |
88 pointer_barriers_[3] = XFixesCreatePointerBarrier(xdisplay(), | 72 pointer_barriers_[3] = XFixesCreatePointerBarrier( |
89 x_root_window(), | 73 xdisplay(), x_root_window(), barrier.right(), barrier.y(), |
90 barrier.right(), | 74 barrier.right(), barrier.bottom(), BarrierNegativeX, 0, XIAllDevices); |
91 barrier.y(), | |
92 barrier.right(), | |
93 barrier.bottom(), | |
94 BarrierNegativeX, | |
95 0, | |
96 XIAllDevices); | |
97 #endif | 75 #endif |
98 return true; | 76 return true; |
99 } | 77 } |
100 | 78 |
101 void AshWindowTreeHostX11::UnConfineCursor() { | 79 void AshWindowTreeHostX11::UnConfineCursor() { |
102 #if XFIXES_MAJOR >= 5 | 80 #if XFIXES_MAJOR >= 5 |
103 if (pointer_barriers_) { | 81 if (pointer_barriers_) { |
104 XFixesDestroyPointerBarrier(xdisplay(), pointer_barriers_[0]); | 82 XFixesDestroyPointerBarrier(xdisplay(), pointer_barriers_[0]); |
105 XFixesDestroyPointerBarrier(xdisplay(), pointer_barriers_[1]); | 83 XFixesDestroyPointerBarrier(xdisplay(), pointer_barriers_[1]); |
106 XFixesDestroyPointerBarrier(xdisplay(), pointer_barriers_[2]); | 84 XFixesDestroyPointerBarrier(xdisplay(), pointer_barriers_[2]); |
107 XFixesDestroyPointerBarrier(xdisplay(), pointer_barriers_[3]); | 85 XFixesDestroyPointerBarrier(xdisplay(), pointer_barriers_[3]); |
108 pointer_barriers_.reset(); | 86 pointer_barriers_.reset(); |
109 } | 87 } |
110 #endif | 88 #endif |
111 } | 89 } |
112 | 90 |
113 void AshWindowTreeHostX11::SetRootWindowTransformer( | 91 void AshWindowTreeHostX11::SetRootWindowTransformer( |
114 std::unique_ptr<RootWindowTransformer> transformer) { | 92 std::unique_ptr<RootWindowTransformer> transformer) { |
115 transformer_helper_.SetRootWindowTransformer(std::move(transformer)); | 93 transformer_helper_.SetRootWindowTransformer(std::move(transformer)); |
116 if (pointer_barriers_) { | 94 if (pointer_barriers_) { |
117 UnConfineCursor(); | 95 UnConfineCursor(); |
118 ConfineCursorToRootWindow(); | 96 ConfineCursorToRootWindow(); |
119 } | 97 } |
120 } | 98 } |
121 | 99 |
122 gfx::Insets AshWindowTreeHostX11::GetHostInsets() const { | 100 gfx::Insets AshWindowTreeHostX11::GetHostInsets() const { |
123 return transformer_helper_.GetHostInsets(); | 101 return transformer_helper_.GetHostInsets(); |
124 } | 102 } |
125 | 103 |
126 aura::WindowTreeHost* AshWindowTreeHostX11::AsWindowTreeHost() { return this; } | 104 aura::WindowTreeHost* AshWindowTreeHostX11::AsWindowTreeHost() { |
| 105 return this; |
| 106 } |
127 | 107 |
128 void AshWindowTreeHostX11::PrepareForShutdown() { | 108 void AshWindowTreeHostX11::PrepareForShutdown() { |
129 // Block the root window from dispatching events because it is weird for a | 109 // Block the root window from dispatching events because it is weird for a |
130 // ScreenPositionClient not to be attached to the root window and for | 110 // ScreenPositionClient not to be attached to the root window and for |
131 // ui::EventHandlers to be unable to convert the event's location to screen | 111 // ui::EventHandlers to be unable to convert the event's location to screen |
132 // coordinates. | 112 // coordinates. |
133 window()->SetEventTargeter( | 113 window()->SetEventTargeter( |
134 std::unique_ptr<ui::EventTargeter>(new ui::NullEventTargeter)); | 114 std::unique_ptr<ui::EventTargeter>(new ui::NullEventTargeter)); |
135 | 115 |
136 if (ui::PlatformEventSource::GetInstance()) { | 116 if (ui::PlatformEventSource::GetInstance()) { |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 void AshWindowTreeHostX11::OnConfigureNotify() { | 166 void AshWindowTreeHostX11::OnConfigureNotify() { |
187 // Always update barrier and mouse location because |bounds_| might | 167 // Always update barrier and mouse location because |bounds_| might |
188 // have already been updated in |SetBounds|. | 168 // have already been updated in |SetBounds|. |
189 if (pointer_barriers_) { | 169 if (pointer_barriers_) { |
190 UnConfineCursor(); | 170 UnConfineCursor(); |
191 ConfineCursorToRootWindow(); | 171 ConfineCursorToRootWindow(); |
192 } | 172 } |
193 } | 173 } |
194 | 174 |
195 bool AshWindowTreeHostX11::CanDispatchEvent(const ui::PlatformEvent& event) { | 175 bool AshWindowTreeHostX11::CanDispatchEvent(const ui::PlatformEvent& event) { |
196 if(!WindowTreeHostX11::CanDispatchEvent(event)) | 176 if (!WindowTreeHostX11::CanDispatchEvent(event)) |
197 return false; | 177 return false; |
198 XEvent* xev = event; | 178 XEvent* xev = event; |
199 ui::EventType type = ui::EventTypeFromNative(xev); | 179 ui::EventType type = ui::EventTypeFromNative(xev); |
200 // For touch event, check if the root window is residing on the according | 180 // For touch event, check if the root window is residing on the according |
201 // touch display. | 181 // touch display. |
202 switch (type) { | 182 switch (type) { |
203 case ui::ET_TOUCH_MOVED: | 183 case ui::ET_TOUCH_MOVED: |
204 case ui::ET_TOUCH_PRESSED: | 184 case ui::ET_TOUCH_PRESSED: |
205 case ui::ET_TOUCH_CANCELLED: | 185 case ui::ET_TOUCH_CANCELLED: |
206 case ui::ET_TOUCH_RELEASED: { | 186 case ui::ET_TOUCH_RELEASED: { |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 const XIDeviceList& dev_list = | 235 const XIDeviceList& dev_list = |
256 ui::DeviceListCacheX11::GetInstance()->GetXI2DeviceList(xdisplay()); | 236 ui::DeviceListCacheX11::GetInstance()->GetXI2DeviceList(xdisplay()); |
257 | 237 |
258 // Only slave pointer devices could possibly have tap-paused property. | 238 // Only slave pointer devices could possibly have tap-paused property. |
259 for (int i = 0; i < dev_list.count; i++) { | 239 for (int i = 0; i < dev_list.count; i++) { |
260 if (dev_list[i].use == XISlavePointer) { | 240 if (dev_list[i].use == XISlavePointer) { |
261 Atom old_type; | 241 Atom old_type; |
262 int old_format; | 242 int old_format; |
263 unsigned long old_nvalues, bytes; | 243 unsigned long old_nvalues, bytes; |
264 unsigned char* data; | 244 unsigned char* data; |
265 int result = XIGetProperty(xdisplay(), | 245 int result = XIGetProperty(xdisplay(), dev_list[i].deviceid, prop, 0, 0, |
266 dev_list[i].deviceid, | 246 False, AnyPropertyType, &old_type, &old_format, |
267 prop, | 247 &old_nvalues, &bytes, &data); |
268 0, | |
269 0, | |
270 False, | |
271 AnyPropertyType, | |
272 &old_type, | |
273 &old_format, | |
274 &old_nvalues, | |
275 &bytes, | |
276 &data); | |
277 if (result != Success) | 248 if (result != Success) |
278 continue; | 249 continue; |
279 XFree(data); | 250 XFree(data); |
280 XIChangeProperty(xdisplay(), | 251 XIChangeProperty(xdisplay(), dev_list[i].deviceid, prop, XA_INTEGER, 8, |
281 dev_list[i].deviceid, | 252 PropModeReplace, &value, 1); |
282 prop, | |
283 XA_INTEGER, | |
284 8, | |
285 PropModeReplace, | |
286 &value, | |
287 1); | |
288 } | 253 } |
289 } | 254 } |
290 } | 255 } |
291 #endif // defined(OS_CHROMEOS) | 256 #endif // defined(OS_CHROMEOS) |
292 | 257 |
293 } // namespace ash | 258 } // namespace ash |
OLD | NEW |