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/x11_whole_screen_move_loop.h" | 5 #include "ui/views/widget/desktop_aura/x11_whole_screen_move_loop.h" |
6 | 6 |
7 #include <X11/keysym.h> | 7 #include <X11/keysym.h> |
8 #include <X11/Xlib.h> | 8 #include <X11/Xlib.h> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
12 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
13 #include "ui/aura/client/capture_client.h" | 13 #include "ui/aura/client/capture_client.h" |
14 #include "ui/aura/env.h" | 14 #include "ui/aura/env.h" |
15 #include "ui/aura/window.h" | 15 #include "ui/aura/window.h" |
16 #include "ui/aura/window_event_dispatcher.h" | 16 #include "ui/aura/window_event_dispatcher.h" |
17 #include "ui/aura/window_tree_host.h" | 17 #include "ui/aura/window_tree_host.h" |
18 #include "ui/base/x/x11_util.h" | 18 #include "ui/base/x/x11_util.h" |
19 #include "ui/events/event.h" | 19 #include "ui/events/event.h" |
20 #include "ui/events/event_utils.h" | 20 #include "ui/events/event_utils.h" |
21 #include "ui/events/keycodes/keyboard_code_conversion_x.h" | 21 #include "ui/events/keycodes/keyboard_code_conversion_x.h" |
22 #include "ui/events/platform/scoped_event_dispatcher.h" | 22 #include "ui/events/platform/scoped_event_dispatcher.h" |
23 #include "ui/events/platform/x11/x11_event_source.h" | 23 #include "ui/events/platform/x11/x11_event_source.h" |
| 24 #include "ui/views/widget/desktop_aura/x11_pointer_grab.h" |
24 | 25 |
25 namespace views { | 26 namespace views { |
26 | 27 |
27 // XGrabKey requires the modifier mask to explicitly be specified. | 28 // XGrabKey requires the modifier mask to explicitly be specified. |
28 const unsigned int kModifiersMasks[] = { | 29 const unsigned int kModifiersMasks[] = { |
29 0, // No additional modifier. | 30 0, // No additional modifier. |
30 Mod2Mask, // Num lock | 31 Mod2Mask, // Num lock |
31 LockMask, // Caps lock | 32 LockMask, // Caps lock |
32 Mod5Mask, // Scroll lock | 33 Mod5Mask, // Scroll lock |
33 Mod2Mask | LockMask, | 34 Mod2Mask | LockMask, |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 run_loop.Run(); | 180 run_loop.Run(); |
180 | 181 |
181 if (!alive) | 182 if (!alive) |
182 return false; | 183 return false; |
183 | 184 |
184 nested_dispatcher_ = old_dispatcher.Pass(); | 185 nested_dispatcher_ = old_dispatcher.Pass(); |
185 return !canceled_; | 186 return !canceled_; |
186 } | 187 } |
187 | 188 |
188 void X11WholeScreenMoveLoop::UpdateCursor(gfx::NativeCursor cursor) { | 189 void X11WholeScreenMoveLoop::UpdateCursor(gfx::NativeCursor cursor) { |
189 if (in_move_loop_) { | 190 if (in_move_loop_) |
190 // We cannot call GrabPointer() because we do not want to change the | 191 ChangeActivePointerGrabCursor(cursor.platform()); |
191 // "owner_events" property of the active pointer grab. | |
192 XChangeActivePointerGrab( | |
193 gfx::GetXDisplay(), | |
194 ButtonPressMask | ButtonReleaseMask | PointerMotionMask, | |
195 cursor.platform(), | |
196 CurrentTime); | |
197 } | |
198 } | 192 } |
199 | 193 |
200 void X11WholeScreenMoveLoop::EndMoveLoop() { | 194 void X11WholeScreenMoveLoop::EndMoveLoop() { |
201 if (!in_move_loop_) | 195 if (!in_move_loop_) |
202 return; | 196 return; |
203 | 197 |
204 // Prevent DispatchMouseMovement from dispatching any posted motion event. | 198 // Prevent DispatchMouseMovement from dispatching any posted motion event. |
205 last_motion_in_screen_.reset(); | 199 last_motion_in_screen_.reset(); |
206 | 200 |
207 // We undo our emulated mouse click from RunMoveLoop(); | 201 // We undo our emulated mouse click from RunMoveLoop(); |
208 if (should_reset_mouse_flags_) { | 202 if (should_reset_mouse_flags_) { |
209 aura::Env::GetInstance()->set_mouse_button_flags(0); | 203 aura::Env::GetInstance()->set_mouse_button_flags(0); |
210 should_reset_mouse_flags_ = false; | 204 should_reset_mouse_flags_ = false; |
211 } | 205 } |
212 | 206 |
213 // TODO(erg): Is this ungrab the cause of having to click to give input focus | 207 // TODO(erg): Is this ungrab the cause of having to click to give input focus |
214 // on drawn out windows? Not ungrabbing here screws the X server until I kill | 208 // on drawn out windows? Not ungrabbing here screws the X server until I kill |
215 // the chrome process. | 209 // the chrome process. |
216 | 210 |
217 // Ungrab before we let go of the window. | 211 // Ungrab before we let go of the window. |
218 XDisplay* display = gfx::GetXDisplay(); | |
219 if (grabbed_pointer_) | 212 if (grabbed_pointer_) |
220 XUngrabPointer(display, CurrentTime); | 213 UngrabPointer(); |
221 else | 214 else |
222 UpdateCursor(initial_cursor_); | 215 UpdateCursor(initial_cursor_); |
223 | 216 |
| 217 XDisplay* display = gfx::GetXDisplay(); |
224 unsigned int esc_keycode = XKeysymToKeycode(display, XK_Escape); | 218 unsigned int esc_keycode = XKeysymToKeycode(display, XK_Escape); |
225 for (size_t i = 0; i < arraysize(kModifiersMasks); ++i) { | 219 for (size_t i = 0; i < arraysize(kModifiersMasks); ++i) { |
226 XUngrabKey(display, esc_keycode, kModifiersMasks[i], grab_input_window_); | 220 XUngrabKey(display, esc_keycode, kModifiersMasks[i], grab_input_window_); |
227 } | 221 } |
228 | 222 |
229 // Restore the previous dispatcher. | 223 // Restore the previous dispatcher. |
230 nested_dispatcher_.reset(); | 224 nested_dispatcher_.reset(); |
231 delegate_->OnMoveLoopEnded(); | 225 delegate_->OnMoveLoopEnded(); |
232 XDestroyWindow(display, grab_input_window_); | 226 XDestroyWindow(display, grab_input_window_); |
233 grab_input_window_ = None; | 227 grab_input_window_ = None; |
234 | 228 |
235 in_move_loop_ = false; | 229 in_move_loop_ = false; |
236 quit_closure_.Run(); | 230 quit_closure_.Run(); |
237 } | 231 } |
238 | 232 |
239 bool X11WholeScreenMoveLoop::GrabPointer(gfx::NativeCursor cursor) { | 233 bool X11WholeScreenMoveLoop::GrabPointer(gfx::NativeCursor cursor) { |
240 XDisplay* display = gfx::GetXDisplay(); | 234 XDisplay* display = gfx::GetXDisplay(); |
241 XGrabServer(display); | 235 XGrabServer(display); |
242 | 236 |
243 // Pass "owner_events" as false so that X sends all mouse events to | 237 // Pass "owner_events" as false so that X sends all mouse events to |
244 // |grab_input_window_|. | 238 // |grab_input_window_|. |
245 int ret = XGrabPointer( | 239 int ret = ::views::GrabPointer(grab_input_window_, false, cursor.platform()); |
246 display, | |
247 grab_input_window_, | |
248 False, // owner_events | |
249 ButtonPressMask | ButtonReleaseMask | PointerMotionMask, | |
250 GrabModeAsync, | |
251 GrabModeAsync, | |
252 None, | |
253 cursor.platform(), | |
254 CurrentTime); | |
255 if (ret != GrabSuccess) { | 240 if (ret != GrabSuccess) { |
256 DLOG(ERROR) << "Grabbing pointer for dragging failed: " | 241 DLOG(ERROR) << "Grabbing pointer for dragging failed: " |
257 << ui::GetX11ErrorString(display, ret); | 242 << ui::GetX11ErrorString(display, ret); |
258 } | 243 } |
259 XUngrabServer(display); | 244 XUngrabServer(display); |
260 XFlush(display); | 245 XFlush(display); |
261 return ret == GrabSuccess; | 246 return ret == GrabSuccess; |
262 } | 247 } |
263 | 248 |
264 void X11WholeScreenMoveLoop::GrabEscKey() { | 249 void X11WholeScreenMoveLoop::GrabEscKey() { |
(...skipping 16 matching lines...) Expand all Loading... |
281 DefaultRootWindow(display), | 266 DefaultRootWindow(display), |
282 -100, -100, 10, 10, | 267 -100, -100, 10, 10, |
283 0, CopyFromParent, InputOnly, CopyFromParent, | 268 0, CopyFromParent, InputOnly, CopyFromParent, |
284 attribute_mask, &swa); | 269 attribute_mask, &swa); |
285 XMapRaised(display, window); | 270 XMapRaised(display, window); |
286 ui::X11EventSource::GetInstance()->BlockUntilWindowMapped(window); | 271 ui::X11EventSource::GetInstance()->BlockUntilWindowMapped(window); |
287 return window; | 272 return window; |
288 } | 273 } |
289 | 274 |
290 } // namespace views | 275 } // namespace views |
OLD | NEW |