Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(59)

Side by Side Diff: ui/base/x/x11_util.cc

Issue 749063003: Fix grabbing capture when the mouse is pressed on Desktop Linux. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 // This file defines utility functions for X11 (Linux only). This code has been 5 // This file defines utility functions for X11 (Linux only). This code has been
6 // ported from XCB since we can't use XCB on Ubuntu while its 32-bit support 6 // ported from XCB since we can't use XCB on Ubuntu while its 32-bit support
7 // remains woefully incomplete. 7 // remains woefully incomplete.
8 8
9 #include "ui/base/x/x11_util.h" 9 #include "ui/base/x/x11_util.h"
10 10
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 std::map< ::Cursor, XCustomCursor*> cache_; 277 std::map< ::Cursor, XCustomCursor*> cache_;
278 DISALLOW_COPY_AND_ASSIGN(XCustomCursorCache); 278 DISALLOW_COPY_AND_ASSIGN(XCustomCursorCache);
279 }; 279 };
280 280
281 } // namespace 281 } // namespace
282 282
283 bool IsXInput2Available() { 283 bool IsXInput2Available() {
284 return DeviceDataManagerX11::GetInstance()->IsXInput2Available(); 284 return DeviceDataManagerX11::GetInstance()->IsXInput2Available();
285 } 285 }
286 286
287 int GrabPointer(XID window, bool owner_events, ::Cursor cursor) {
288 if (IsXInput2Available()) {
289 // Do an XINPUT2 pointer grab. If there is an active XINPUT2 pointer grab
290 // as a result of normal button press, XGrabPointer() will fail.
291 const std::vector<int>& master_pointers =
292 DeviceDataManagerX11::GetInstance()->master_pointers();
293 int success = GrabSuccess;
294 for (size_t i = 0; i < master_pointers.size(); ++i) {
295 unsigned char mask[XIMaskLen(XI_LASTEVENT)];
296 memset(mask, 0, sizeof(mask));
297 XISetMask(mask, XI_ButtonPress);
298 XISetMask(mask, XI_ButtonRelease);
299 XISetMask(mask, XI_Motion);
300 XIEventMask evmask;
301 evmask.deviceid = XIAllDevices;
sadrul 2014/12/22 21:08:59 Should you use master_pointers[i] here?
pkotwicz 2014/12/23 00:29:49 It seems to work either way. I haven't seen any do
302 evmask.mask_len = sizeof(mask);
303 evmask.mask = mask;
304 success = XIGrabDevice(gfx::GetXDisplay(), master_pointers[i], window,
305 CurrentTime, cursor, GrabModeAsync, GrabModeAsync,
306 owner_events, &evmask);
307 // Assume that the grab will succeed on either all or none of the master
308 // pointers.
309 if (success != GrabSuccess)
310 return success;
311 }
312 return success;
313 } else {
pkotwicz 2014/12/01 22:42:48 Should I try XGrabPointer() if XIGrabDevice() fail
sadrul 2014/12/22 21:08:59 Sure. Let's try that. Also, remove else.
pkotwicz 2014/12/23 00:29:49 Done.
314 int event_mask = PointerMotionMask | ButtonReleaseMask | ButtonPressMask;
315 return XGrabPointer(gfx::GetXDisplay(), window, owner_events, event_mask,
316 GrabModeAsync, GrabModeAsync, None,
317 cursor, CurrentTime);
318 }
319 }
320
321 void UngrabPointer() {
322 if (IsXInput2Available()) {
323 const std::vector<int>& master_pointers =
324 DeviceDataManagerX11::GetInstance()->master_pointers();
325 for (size_t i = 0; i < master_pointers.size(); ++i)
326 XIUngrabDevice(gfx::GetXDisplay(), master_pointers[i], CurrentTime);
327 } else {
328 XUngrabPointer(gfx::GetXDisplay(), CurrentTime);
329 }
330 }
331
287 static SharedMemorySupport DoQuerySharedMemorySupport(XDisplay* dpy) { 332 static SharedMemorySupport DoQuerySharedMemorySupport(XDisplay* dpy) {
288 int dummy; 333 int dummy;
289 Bool pixmaps_supported; 334 Bool pixmaps_supported;
290 // Query the server's support for XSHM. 335 // Query the server's support for XSHM.
291 if (!XShmQueryVersion(dpy, &dummy, &dummy, &pixmaps_supported)) 336 if (!XShmQueryVersion(dpy, &dummy, &dummy, &pixmaps_supported))
292 return SHARED_MEMORY_NONE; 337 return SHARED_MEMORY_NONE;
293 338
294 #if defined(OS_FREEBSD) 339 #if defined(OS_FREEBSD)
295 // On FreeBSD we can't access the shared memory after it was marked for 340 // On FreeBSD we can't access the shared memory after it was marked for
296 // deletion, unless this behaviour is explicitly enabled by the user. 341 // deletion, unless this behaviour is explicitly enabled by the user.
(...skipping 1198 matching lines...) Expand 10 before | Expand all | Expand 10 after
1495 << "request_code " << static_cast<int>(error_event.request_code) << ", " 1540 << "request_code " << static_cast<int>(error_event.request_code) << ", "
1496 << "minor_code " << static_cast<int>(error_event.minor_code) 1541 << "minor_code " << static_cast<int>(error_event.minor_code)
1497 << " (" << request_str << ")"; 1542 << " (" << request_str << ")";
1498 } 1543 }
1499 1544
1500 // ---------------------------------------------------------------------------- 1545 // ----------------------------------------------------------------------------
1501 // End of x11_util_internal.h 1546 // End of x11_util_internal.h
1502 1547
1503 1548
1504 } // namespace ui 1549 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698