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 "remoting/host/event_executor.h" | 5 #include "remoting/host/event_executor.h" |
6 | 6 |
7 #include <X11/Xlib.h> | 7 #include <X11/Xlib.h> |
8 #include <X11/extensions/XTest.h> | 8 #include <X11/extensions/XTest.h> |
9 #include <X11/extensions/XInput.h> | 9 #include <X11/extensions/XInput.h> |
10 | 10 |
(...skipping 15 matching lines...) Expand all Loading... |
26 | 26 |
27 using protocol::ClipboardEvent; | 27 using protocol::ClipboardEvent; |
28 using protocol::KeyEvent; | 28 using protocol::KeyEvent; |
29 using protocol::MouseEvent; | 29 using protocol::MouseEvent; |
30 | 30 |
31 // USB to XKB keycode map table. | 31 // USB to XKB keycode map table. |
32 #define USB_KEYMAP(usb, xkb, win, mac) {usb, xkb} | 32 #define USB_KEYMAP(usb, xkb, win, mac) {usb, xkb} |
33 #include "ui/base/keycodes/usb_keycode_map.h" | 33 #include "ui/base/keycodes/usb_keycode_map.h" |
34 #undef USB_KEYMAP | 34 #undef USB_KEYMAP |
35 | 35 |
| 36 // Pixel-to-wheel-ticks conversion ratio used by GTK. |
| 37 // From Source/WebKit/chromium/src/gtk/WebInputFactory.cc. |
| 38 const float kWheelTicksPerPixel = 3.0f / 160.0f; |
| 39 |
36 // A class to generate events on Linux. | 40 // A class to generate events on Linux. |
37 class EventExecutorLinux : public EventExecutor { | 41 class EventExecutorLinux : public EventExecutor { |
38 public: | 42 public: |
39 explicit EventExecutorLinux( | 43 explicit EventExecutorLinux( |
40 scoped_refptr<base::SingleThreadTaskRunner> task_runner); | 44 scoped_refptr<base::SingleThreadTaskRunner> task_runner); |
41 virtual ~EventExecutorLinux(); | 45 virtual ~EventExecutorLinux(); |
42 | 46 |
43 bool Init(); | 47 bool Init(); |
44 | 48 |
45 // Clipboard stub interface. | 49 // Clipboard stub interface. |
(...skipping 24 matching lines...) Expand all Loading... |
70 // Compensates for global button mappings and resets the XTest device mapping. | 74 // Compensates for global button mappings and resets the XTest device mapping. |
71 void InitMouseButtonMap(); | 75 void InitMouseButtonMap(); |
72 int MouseButtonToX11ButtonNumber(MouseEvent::MouseButton button); | 76 int MouseButtonToX11ButtonNumber(MouseEvent::MouseButton button); |
73 int HorizontalScrollWheelToX11ButtonNumber(int dx); | 77 int HorizontalScrollWheelToX11ButtonNumber(int dx); |
74 int VerticalScrollWheelToX11ButtonNumber(int dy); | 78 int VerticalScrollWheelToX11ButtonNumber(int dy); |
75 | 79 |
76 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 80 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
77 | 81 |
78 std::set<int> pressed_keys_; | 82 std::set<int> pressed_keys_; |
79 SkIPoint latest_mouse_position_; | 83 SkIPoint latest_mouse_position_; |
| 84 float wheel_ticks_x_; |
| 85 float wheel_ticks_y_; |
80 | 86 |
81 // X11 graphics context. | 87 // X11 graphics context. |
82 Display* display_; | 88 Display* display_; |
83 Window root_window_; | 89 Window root_window_; |
84 | 90 |
85 int test_event_base_; | 91 int test_event_base_; |
86 int test_error_base_; | 92 int test_error_base_; |
87 | 93 |
88 int pointer_button_map_[kNumPointerButtons]; | 94 int pointer_button_map_[kNumPointerButtons]; |
89 | 95 |
90 scoped_ptr<Clipboard> clipboard_; | 96 scoped_ptr<Clipboard> clipboard_; |
91 | 97 |
92 DISALLOW_COPY_AND_ASSIGN(EventExecutorLinux); | 98 DISALLOW_COPY_AND_ASSIGN(EventExecutorLinux); |
93 }; | 99 }; |
94 | 100 |
95 EventExecutorLinux::EventExecutorLinux( | 101 EventExecutorLinux::EventExecutorLinux( |
96 scoped_refptr<base::SingleThreadTaskRunner> task_runner) | 102 scoped_refptr<base::SingleThreadTaskRunner> task_runner) |
97 : task_runner_(task_runner), | 103 : task_runner_(task_runner), |
98 latest_mouse_position_(SkIPoint::Make(-1, -1)), | 104 latest_mouse_position_(SkIPoint::Make(-1, -1)), |
| 105 wheel_ticks_x_(0.0f), |
| 106 wheel_ticks_y_(0.0f), |
99 display_(XOpenDisplay(NULL)), | 107 display_(XOpenDisplay(NULL)), |
100 root_window_(BadValue) { | 108 root_window_(BadValue) { |
101 #if defined(REMOTING_HOST_LINUX_CLIPBOARD) | 109 #if defined(REMOTING_HOST_LINUX_CLIPBOARD) |
102 if (!task_runner_->BelongsToCurrentThread()) { | 110 if (!task_runner_->BelongsToCurrentThread()) { |
103 task_runner_->PostTask( | 111 task_runner_->PostTask( |
104 FROM_HERE, | 112 FROM_HERE, |
105 base::Bind(&EventExecutorLinux::InitClipboard, base::Unretained(this))); | 113 base::Bind(&EventExecutorLinux::InitClipboard, base::Unretained(this))); |
106 } | 114 } |
107 #endif // REMOTING_HOST_LINUX_CLIPBOARD | 115 #endif // REMOTING_HOST_LINUX_CLIPBOARD |
108 } | 116 } |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 } | 265 } |
258 | 266 |
259 VLOG(3) << "Button " << event.button() | 267 VLOG(3) << "Button " << event.button() |
260 << " received, sending " | 268 << " received, sending " |
261 << (event.button_down() ? "down " : "up ") | 269 << (event.button_down() ? "down " : "up ") |
262 << button_number; | 270 << button_number; |
263 XTestFakeButtonEvent(display_, button_number, event.button_down(), | 271 XTestFakeButtonEvent(display_, button_number, event.button_down(), |
264 CurrentTime); | 272 CurrentTime); |
265 } | 273 } |
266 | 274 |
267 if (event.has_wheel_offset_y() && event.wheel_offset_y() != 0) { | 275 int ticks_y = 0; |
268 int dy = event.wheel_offset_y(); | 276 if (event.has_wheel_delta_y()) { |
269 InjectScrollWheelClicks(VerticalScrollWheelToX11ButtonNumber(dy), abs(dy)); | 277 wheel_ticks_y_ += event.wheel_delta_y() * kWheelTicksPerPixel; |
| 278 ticks_y = static_cast<int>(wheel_ticks_y_); |
| 279 wheel_ticks_y_ -= ticks_y; |
| 280 } else if (event.has_wheel_offset_y()) { |
| 281 ticks_y = event.wheel_offset_y(); |
270 } | 282 } |
271 if (event.has_wheel_offset_x() && event.wheel_offset_x() != 0) { | 283 if (ticks_y != 0) { |
272 int dx = event.wheel_offset_x(); | 284 InjectScrollWheelClicks(VerticalScrollWheelToX11ButtonNumber(ticks_y), |
273 InjectScrollWheelClicks(HorizontalScrollWheelToX11ButtonNumber(dx), | 285 abs(ticks_y)); |
274 abs(dx)); | 286 } |
| 287 |
| 288 int ticks_x = 0; |
| 289 if (event.has_wheel_delta_x()) { |
| 290 wheel_ticks_x_ += event.wheel_delta_x() * kWheelTicksPerPixel; |
| 291 ticks_x = static_cast<int>(wheel_ticks_x_); |
| 292 wheel_ticks_x_ -= ticks_x; |
| 293 } else if (event.has_wheel_offset_x()) { |
| 294 ticks_x = event.wheel_offset_x(); |
| 295 } |
| 296 if (ticks_x != 0) { |
| 297 InjectScrollWheelClicks(HorizontalScrollWheelToX11ButtonNumber(ticks_x), |
| 298 abs(ticks_x)); |
275 } | 299 } |
276 | 300 |
277 XFlush(display_); | 301 XFlush(display_); |
278 } | 302 } |
279 | 303 |
280 void EventExecutorLinux::InitMouseButtonMap() { | 304 void EventExecutorLinux::InitMouseButtonMap() { |
281 // TODO(rmsousa): Run this on global/device mapping change events. | 305 // TODO(rmsousa): Run this on global/device mapping change events. |
282 | 306 |
283 // Do not touch global pointer mapping, since this may affect the local user. | 307 // Do not touch global pointer mapping, since this may affect the local user. |
284 // Instead, try to work around it by reversing the mapping. | 308 // Instead, try to work around it by reversing the mapping. |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
410 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, | 434 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, |
411 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner) { | 435 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner) { |
412 scoped_ptr<EventExecutorLinux> executor( | 436 scoped_ptr<EventExecutorLinux> executor( |
413 new EventExecutorLinux(main_task_runner)); | 437 new EventExecutorLinux(main_task_runner)); |
414 if (!executor->Init()) | 438 if (!executor->Init()) |
415 return scoped_ptr<EventExecutor>(NULL); | 439 return scoped_ptr<EventExecutor>(NULL); |
416 return executor.PassAs<EventExecutor>(); | 440 return executor.PassAs<EventExecutor>(); |
417 } | 441 } |
418 | 442 |
419 } // namespace remoting | 443 } // namespace remoting |
OLD | NEW |