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/base/events.h" | 5 #include "ui/base/events.h" |
6 | 6 |
7 #include <X11/Xlib.h> | 7 #include <X11/Xlib.h> |
8 #include <X11/extensions/XInput.h> | 8 #include <X11/extensions/XInput.h> |
9 #include <X11/extensions/XInput2.h> | 9 #include <X11/extensions/XInput2.h> |
10 #include <string.h> | 10 #include <string.h> |
11 | 11 |
| 12 #include "base/command_line.h" |
12 #include "base/logging.h" | 13 #include "base/logging.h" |
13 #include "base/message_pump_x.h" | 14 #include "base/message_pump_x.h" |
14 #include "ui/base/keycodes/keyboard_code_conversion_x.h" | 15 #include "ui/base/keycodes/keyboard_code_conversion_x.h" |
| 16 #include "ui/base/ui_base_switches.h" |
15 #include "ui/base/touch/touch_factory.h" | 17 #include "ui/base/touch/touch_factory.h" |
16 #include "ui/base/x/x11_util.h" | 18 #include "ui/base/x/x11_util.h" |
17 #include "ui/gfx/point.h" | 19 #include "ui/gfx/point.h" |
| 20 #include "ui/gfx/monitor.h" |
| 21 #include "ui/gfx/rect.h" |
| 22 #include "ui/gfx/screen.h" |
18 | 23 |
19 // Copied from xserver-properties.h | 24 // Copied from xserver-properties.h |
20 #define AXIS_LABEL_PROP_REL_HWHEEL "Rel Horiz Wheel" | 25 #define AXIS_LABEL_PROP_REL_HWHEEL "Rel Horiz Wheel" |
21 #define AXIS_LABEL_PROP_REL_WHEEL "Rel Vert Wheel" | 26 #define AXIS_LABEL_PROP_REL_WHEEL "Rel Vert Wheel" |
22 | 27 |
23 // CMT specific timings | 28 // CMT specific timings |
24 #define AXIS_LABEL_PROP_ABS_START_TIME "Abs Start Timestamp" | 29 #define AXIS_LABEL_PROP_ABS_START_TIME "Abs Start Timestamp" |
25 #define AXIS_LABEL_PROP_ABS_END_TIME "Abs End Timestamp" | 30 #define AXIS_LABEL_PROP_ABS_END_TIME "Abs End Timestamp" |
26 | 31 |
27 // Fling properties | 32 // Fling properties |
(...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
504 ui::TouchFactory::GetInstance()->ExtractTouchParam(*xev, tp, &default_value); | 509 ui::TouchFactory::GetInstance()->ExtractTouchParam(*xev, tp, &default_value); |
505 return default_value; | 510 return default_value; |
506 } | 511 } |
507 | 512 |
508 Atom GetNoopEventAtom() { | 513 Atom GetNoopEventAtom() { |
509 return XInternAtom( | 514 return XInternAtom( |
510 base::MessagePumpX::GetDefaultXDisplay(), | 515 base::MessagePumpX::GetDefaultXDisplay(), |
511 "noop", False); | 516 "noop", False); |
512 } | 517 } |
513 | 518 |
| 519 #if defined(USE_XI2_MT) |
| 520 gfx::Point CalibrateTouchCoordinates( |
| 521 const XIDeviceEvent* xievent) { |
| 522 int x = static_cast<int>(xievent->event_x); |
| 523 int y = static_cast<int>(xievent->event_y); |
| 524 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 525 switches::kDisableTouchCalibration)) |
| 526 return gfx::Point(x, y); |
| 527 // TODO(skuhne): Find a new home for these hardware dependent touch |
| 528 // constants. |
| 529 // Note: These values have been found to be correct for the device I was |
| 530 // testing with. I have the feeling that the DPI resolution of the bezel is |
| 531 // less then the dpi resolution over the visible part - which would explain |
| 532 // why the small value (50) is so wide compared to the entire area. |
| 533 gfx::Rect bounds = gfx::Screen::GetPrimaryMonitor().bounds_in_pixel(); |
| 534 const int kLeftBorder = 50; |
| 535 const int kRightBorder = 50; |
| 536 const int kBottomBorder = 50; |
| 537 const int kTopBorder = 0; |
| 538 const int resolution_x = bounds.width(); |
| 539 const int resolution_y = bounds.height(); |
| 540 // The "grace area" (10% in this case) is to make it easier for the user to |
| 541 // navigate to the corner. |
| 542 const double kGraceAreaFraction = 0.1; |
| 543 // Offset the x position to the real |
| 544 x -= kLeftBorder; |
| 545 // Check if we are in the grace area of the left side. |
| 546 // Note: We might not want to do this when the gesture is locked? |
| 547 if (x < 0 && x > -kLeftBorder * kGraceAreaFraction) |
| 548 x = 0; |
| 549 // Check if we are in the grace area of the right side. |
| 550 // Note: We might not want to do this when the gesture is locked? |
| 551 if (x > resolution_x - kLeftBorder && |
| 552 x < resolution_x - kLeftBorder + kRightBorder * kGraceAreaFraction) |
| 553 x = resolution_x - kLeftBorder; |
| 554 // Scale the screen area back to the full resolution of the screen. |
| 555 x = (x * resolution_x) / (resolution_x - (kRightBorder + kLeftBorder)); |
| 556 // Offset the y position to the real |
| 557 y -= kTopBorder; |
| 558 // Check if we are in the grace area of the left side. |
| 559 // Note: We might not want to do this when the gesture is locked? |
| 560 if (y < 0 && y > -kTopBorder * kGraceAreaFraction) |
| 561 y = 0; |
| 562 // Check if we are in the grace area of the right side. |
| 563 // Note: We might not want to do this when the gesture is locked? |
| 564 if (y > resolution_y - kTopBorder && |
| 565 y < resolution_y - kTopBorder + kBottomBorder * kGraceAreaFraction) |
| 566 y = resolution_y - kTopBorder; |
| 567 // Scale the screen area back to the full resolution of the screen. |
| 568 y = (y * resolution_y) / (resolution_y - (kBottomBorder + kTopBorder)); |
| 569 // Set the modified coordinate back to the event. |
| 570 return gfx::Point(x, y); |
| 571 } |
| 572 #endif // defined(USE_XI2_MT) |
| 573 |
514 } // namespace | 574 } // namespace |
515 | 575 |
516 namespace ui { | 576 namespace ui { |
517 | 577 |
518 void UpdateDeviceList() { | 578 void UpdateDeviceList() { |
519 Display* display = GetXDisplay(); | 579 Display* display = GetXDisplay(); |
520 CMTEventData::GetInstance()->UpdateDeviceList(display); | 580 CMTEventData::GetInstance()->UpdateDeviceList(display); |
521 TouchFactory::GetInstance()->UpdateDeviceList(display); | 581 TouchFactory::GetInstance()->UpdateDeviceList(display); |
522 } | 582 } |
523 | 583 |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
685 case GenericEvent: { | 745 case GenericEvent: { |
686 XIDeviceEvent* xievent = | 746 XIDeviceEvent* xievent = |
687 static_cast<XIDeviceEvent*>(native_event->xcookie.data); | 747 static_cast<XIDeviceEvent*>(native_event->xcookie.data); |
688 | 748 |
689 #if defined(USE_XI2_MT) | 749 #if defined(USE_XI2_MT) |
690 // Touch event valuators aren't coordinates. | 750 // Touch event valuators aren't coordinates. |
691 // Return the |event_x|/|event_y| directly as event's position. | 751 // Return the |event_x|/|event_y| directly as event's position. |
692 if (xievent->evtype == XI_TouchBegin || | 752 if (xievent->evtype == XI_TouchBegin || |
693 xievent->evtype == XI_TouchUpdate || | 753 xievent->evtype == XI_TouchUpdate || |
694 xievent->evtype == XI_TouchEnd) | 754 xievent->evtype == XI_TouchEnd) |
695 return gfx::Point(static_cast<int>(xievent->event_x), | 755 // Note: Touch events are always touch screen events. |
696 static_cast<int>(xievent->event_y)); | 756 return CalibrateTouchCoordinates(xievent); |
697 #endif | 757 #endif |
698 // Read the position from the valuators, because the location reported in | 758 // Read the position from the valuators, because the location reported in |
699 // event_x/event_y seems to be different (and doesn't match for events | 759 // event_x/event_y seems to be different (and doesn't match for events |
700 // coming from slave device and master device) from the values in the | 760 // coming from slave device and master device) from the values in the |
701 // valuators. See more on crbug.com/103981. The position in the valuators | 761 // valuators. See more on crbug.com/103981. The position in the valuators |
702 // is in the global screen coordinates. But it is necessary to convert it | 762 // is in the global screen coordinates. But it is necessary to convert it |
703 // into the window's coordinates. If the valuator is not set, that means | 763 // into the window's coordinates. If the valuator is not set, that means |
704 // the value hasn't changed, and so we can use the value from | 764 // the value hasn't changed, and so we can use the value from |
705 // event_x/event_y (which are in the window's coordinates). | 765 // event_x/event_y (which are in the window's coordinates). |
706 double* valuators = xievent->valuators.values; | 766 double* valuators = xievent->valuators.values; |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
871 noop->xclient.format = 8; | 931 noop->xclient.format = 8; |
872 DCHECK(!noop->xclient.display); | 932 DCHECK(!noop->xclient.display); |
873 } | 933 } |
874 // Make sure we use atom from current xdisplay, which may | 934 // Make sure we use atom from current xdisplay, which may |
875 // change during the test. | 935 // change during the test. |
876 noop->xclient.message_type = GetNoopEventAtom(); | 936 noop->xclient.message_type = GetNoopEventAtom(); |
877 return noop; | 937 return noop; |
878 } | 938 } |
879 | 939 |
880 } // namespace ui | 940 } // namespace ui |
OLD | NEW |