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 // 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 |
11 #include <ctype.h> | 11 #include <ctype.h> |
12 #include <sys/ipc.h> | 12 #include <sys/ipc.h> |
13 #include <sys/shm.h> | 13 #include <sys/shm.h> |
14 | 14 |
15 #include <list> | 15 #include <list> |
16 #include <map> | 16 #include <map> |
17 #include <utility> | 17 #include <utility> |
18 #include <vector> | 18 #include <vector> |
19 | 19 |
20 #include <X11/extensions/XInput2.h> | |
21 #include <X11/extensions/Xrandr.h> | 20 #include <X11/extensions/Xrandr.h> |
22 #include <X11/extensions/randr.h> | 21 #include <X11/extensions/randr.h> |
23 #include <X11/extensions/shape.h> | 22 #include <X11/extensions/shape.h> |
24 | 23 |
25 #include "base/bind.h" | 24 #include "base/bind.h" |
26 #include "base/command_line.h" | 25 #include "base/command_line.h" |
27 #include "base/logging.h" | 26 #include "base/logging.h" |
28 #include "base/memory/scoped_ptr.h" | 27 #include "base/memory/scoped_ptr.h" |
29 #include "base/memory/singleton.h" | 28 #include "base/memory/singleton.h" |
30 #include "base/message_loop.h" | 29 #include "base/message_loop.h" |
31 #include "base/string_number_conversions.h" | 30 #include "base/string_number_conversions.h" |
32 #include "base/string_util.h" | 31 #include "base/string_util.h" |
33 #include "base/stringprintf.h" | 32 #include "base/stringprintf.h" |
34 #include "base/sys_byteorder.h" | 33 #include "base/sys_byteorder.h" |
35 #include "base/threading/thread.h" | 34 #include "base/threading/thread.h" |
36 #include "ui/base/keycodes/keyboard_code_conversion_x.h" | 35 #include "ui/base/keycodes/keyboard_code_conversion_x.h" |
37 #include "ui/base/touch/touch_factory.h" | |
38 #include "ui/base/x/x11_util_internal.h" | 36 #include "ui/base/x/x11_util_internal.h" |
39 #include "ui/gfx/point_conversions.h" | 37 #include "ui/gfx/point_conversions.h" |
40 #include "ui/gfx/rect.h" | 38 #include "ui/gfx/rect.h" |
41 #include "ui/gfx/size.h" | 39 #include "ui/gfx/size.h" |
42 | 40 |
43 #if defined(OS_FREEBSD) | 41 #if defined(OS_FREEBSD) |
44 #include <sys/sysctl.h> | 42 #include <sys/sysctl.h> |
45 #include <sys/types.h> | 43 #include <sys/types.h> |
46 #endif | 44 #endif |
47 | 45 |
(...skipping 1381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1429 #endif | 1427 #endif |
1430 } | 1428 } |
1431 | 1429 |
1432 bool IsMotionEvent(XEvent* event) { | 1430 bool IsMotionEvent(XEvent* event) { |
1433 int type = event->type; | 1431 int type = event->type; |
1434 if (type == GenericEvent) | 1432 if (type == GenericEvent) |
1435 type = event->xgeneric.evtype; | 1433 type = event->xgeneric.evtype; |
1436 return type == MotionNotify; | 1434 return type == MotionNotify; |
1437 } | 1435 } |
1438 | 1436 |
1439 int CoalescePendingMotionEvents(const XEvent* xev, | |
1440 XEvent* last_event) { | |
1441 XIDeviceEvent* xievent = static_cast<XIDeviceEvent*>(xev->xcookie.data); | |
1442 int num_coalesed = 0; | |
1443 Display* display = xev->xany.display; | |
1444 int event_type = xev->xgeneric.evtype; | |
1445 | |
1446 #if defined(USE_XI2_MT) | |
1447 float tracking_id = -1; | |
1448 if (event_type == XI_TouchUpdate) { | |
1449 if (!ui::ValuatorTracker::GetInstance()->ExtractValuator(*xev, | |
1450 ui::ValuatorTracker::VAL_TRACKING_ID, &tracking_id)) | |
1451 tracking_id = -1; | |
1452 } | |
1453 #endif | |
1454 | |
1455 while (XPending(display)) { | |
1456 XEvent next_event; | |
1457 XPeekEvent(display, &next_event); | |
1458 | |
1459 // If we can't get the cookie, abort the check. | |
1460 if (!XGetEventData(next_event.xgeneric.display, &next_event.xcookie)) | |
1461 return num_coalesed; | |
1462 | |
1463 // If this isn't from a valid device, throw the event away, as | |
1464 // that's what the message pump would do. Device events come in pairs | |
1465 // with one from the master and one from the slave so there will | |
1466 // always be at least one pending. | |
1467 if (!ui::TouchFactory::GetInstance()->ShouldProcessXI2Event(&next_event)) { | |
1468 XFreeEventData(display, &next_event.xcookie); | |
1469 XNextEvent(display, &next_event); | |
1470 continue; | |
1471 } | |
1472 | |
1473 if (next_event.type == GenericEvent && | |
1474 next_event.xgeneric.evtype == event_type && | |
1475 !ui::GetScrollOffsets(&next_event, NULL, NULL)) { | |
1476 XIDeviceEvent* next_xievent = | |
1477 static_cast<XIDeviceEvent*>(next_event.xcookie.data); | |
1478 #if defined(USE_XI2_MT) | |
1479 float next_tracking_id = -1; | |
1480 if (event_type == XI_TouchUpdate) { | |
1481 // If this is a touch motion event (as opposed to mouse motion event), | |
1482 // then make sure the events are from the same touch-point. | |
1483 if (!ui::ValuatorTracker::GetInstance()->ExtractValuator(next_event, | |
1484 ui::ValuatorTracker::VAL_TRACKING_ID, &next_tracking_id)) | |
1485 next_tracking_id = -1; | |
1486 } | |
1487 #endif | |
1488 // Confirm that the motion event is targeted at the same window | |
1489 // and that no buttons or modifiers have changed. | |
1490 if (xievent->event == next_xievent->event && | |
1491 xievent->child == next_xievent->child && | |
1492 #if defined(USE_XI2_MT) | |
1493 (event_type == XI_Motion || tracking_id == next_tracking_id) && | |
1494 #endif | |
1495 xievent->buttons.mask_len == next_xievent->buttons.mask_len && | |
1496 (memcmp(xievent->buttons.mask, | |
1497 next_xievent->buttons.mask, | |
1498 xievent->buttons.mask_len) == 0) && | |
1499 xievent->mods.base == next_xievent->mods.base && | |
1500 xievent->mods.latched == next_xievent->mods.latched && | |
1501 xievent->mods.locked == next_xievent->mods.locked && | |
1502 xievent->mods.effective == next_xievent->mods.effective) { | |
1503 XFreeEventData(display, &next_event.xcookie); | |
1504 // Free the previous cookie. | |
1505 if (num_coalesed > 0) | |
1506 XFreeEventData(display, &last_event->xcookie); | |
1507 // Get the event and its cookie data. | |
1508 XNextEvent(display, last_event); | |
1509 XGetEventData(display, &last_event->xcookie); | |
1510 ++num_coalesed; | |
1511 continue; | |
1512 } else { | |
1513 // This isn't an event we want so free its cookie data. | |
1514 XFreeEventData(display, &next_event.xcookie); | |
1515 } | |
1516 } | |
1517 break; | |
1518 } | |
1519 return num_coalesed; | |
1520 } | |
1521 | |
1522 int GetMappedButton(int button) { | 1437 int GetMappedButton(int button) { |
1523 return XButtonMap::GetInstance()->GetMappedButton(button); | 1438 return XButtonMap::GetInstance()->GetMappedButton(button); |
1524 } | 1439 } |
1525 | 1440 |
1526 void UpdateButtonMap() { | 1441 void UpdateButtonMap() { |
1527 XButtonMap::GetInstance()->UpdateMapping(); | 1442 XButtonMap::GetInstance()->UpdateMapping(); |
1528 } | 1443 } |
1529 | 1444 |
1530 void InitXKeyEventForTesting(EventType type, | 1445 void InitXKeyEventForTesting(EventType type, |
1531 KeyboardCode key_code, | 1446 KeyboardCode key_code, |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1712 << "request_code " << static_cast<int>(error_event.request_code) << ", " | 1627 << "request_code " << static_cast<int>(error_event.request_code) << ", " |
1713 << "minor_code " << static_cast<int>(error_event.minor_code) | 1628 << "minor_code " << static_cast<int>(error_event.minor_code) |
1714 << " (" << request_str << ")"; | 1629 << " (" << request_str << ")"; |
1715 } | 1630 } |
1716 | 1631 |
1717 // ---------------------------------------------------------------------------- | 1632 // ---------------------------------------------------------------------------- |
1718 // End of x11_util_internal.h | 1633 // End of x11_util_internal.h |
1719 | 1634 |
1720 | 1635 |
1721 } // namespace ui | 1636 } // namespace ui |
OLD | NEW |