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 const float kWheelTicksPerPixel = 3.0f / 160.0f; | |
garykac
2012/10/13 01:46:28
nit: Add // From Source/WebKit/chromium/src/gtk/We
Wez
2012/10/13 02:50:46
Done.
| |
38 | |
36 // A class to generate events on Linux. | 39 // A class to generate events on Linux. |
37 class EventExecutorLinux : public EventExecutor { | 40 class EventExecutorLinux : public EventExecutor { |
38 public: | 41 public: |
39 explicit EventExecutorLinux( | 42 explicit EventExecutorLinux( |
40 scoped_refptr<base::SingleThreadTaskRunner> task_runner); | 43 scoped_refptr<base::SingleThreadTaskRunner> task_runner); |
41 virtual ~EventExecutorLinux(); | 44 virtual ~EventExecutorLinux(); |
42 | 45 |
43 bool Init(); | 46 bool Init(); |
44 | 47 |
45 // Clipboard stub interface. | 48 // Clipboard stub interface. |
(...skipping 24 matching lines...) Expand all Loading... | |
70 // Compensates for global button mappings and resets the XTest device mapping. | 73 // Compensates for global button mappings and resets the XTest device mapping. |
71 void InitMouseButtonMap(); | 74 void InitMouseButtonMap(); |
72 int MouseButtonToX11ButtonNumber(MouseEvent::MouseButton button); | 75 int MouseButtonToX11ButtonNumber(MouseEvent::MouseButton button); |
73 int HorizontalScrollWheelToX11ButtonNumber(int dx); | 76 int HorizontalScrollWheelToX11ButtonNumber(int dx); |
74 int VerticalScrollWheelToX11ButtonNumber(int dy); | 77 int VerticalScrollWheelToX11ButtonNumber(int dy); |
75 | 78 |
76 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 79 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
77 | 80 |
78 std::set<int> pressed_keys_; | 81 std::set<int> pressed_keys_; |
79 SkIPoint latest_mouse_position_; | 82 SkIPoint latest_mouse_position_; |
83 float wheel_ticks_x_; | |
84 float wheel_ticks_y_; | |
80 | 85 |
81 // X11 graphics context. | 86 // X11 graphics context. |
82 Display* display_; | 87 Display* display_; |
83 Window root_window_; | 88 Window root_window_; |
84 | 89 |
85 int test_event_base_; | 90 int test_event_base_; |
86 int test_error_base_; | 91 int test_error_base_; |
87 | 92 |
88 int pointer_button_map_[kNumPointerButtons]; | 93 int pointer_button_map_[kNumPointerButtons]; |
89 | 94 |
90 scoped_ptr<Clipboard> clipboard_; | 95 scoped_ptr<Clipboard> clipboard_; |
91 | 96 |
92 DISALLOW_COPY_AND_ASSIGN(EventExecutorLinux); | 97 DISALLOW_COPY_AND_ASSIGN(EventExecutorLinux); |
93 }; | 98 }; |
94 | 99 |
95 EventExecutorLinux::EventExecutorLinux( | 100 EventExecutorLinux::EventExecutorLinux( |
96 scoped_refptr<base::SingleThreadTaskRunner> task_runner) | 101 scoped_refptr<base::SingleThreadTaskRunner> task_runner) |
97 : task_runner_(task_runner), | 102 : task_runner_(task_runner), |
98 latest_mouse_position_(SkIPoint::Make(-1, -1)), | 103 latest_mouse_position_(SkIPoint::Make(-1, -1)), |
104 wheel_ticks_x_(0.0f), | |
105 wheel_ticks_y_(0.0f), | |
99 display_(XOpenDisplay(NULL)), | 106 display_(XOpenDisplay(NULL)), |
100 root_window_(BadValue) { | 107 root_window_(BadValue) { |
101 #if defined(REMOTING_HOST_LINUX_CLIPBOARD) | 108 #if defined(REMOTING_HOST_LINUX_CLIPBOARD) |
102 if (!task_runner_->BelongsToCurrentThread()) { | 109 if (!task_runner_->BelongsToCurrentThread()) { |
103 task_runner_->PostTask( | 110 task_runner_->PostTask( |
104 FROM_HERE, | 111 FROM_HERE, |
105 base::Bind(&EventExecutorLinux::InitClipboard, base::Unretained(this))); | 112 base::Bind(&EventExecutorLinux::InitClipboard, base::Unretained(this))); |
106 } | 113 } |
107 #endif // REMOTING_HOST_LINUX_CLIPBOARD | 114 #endif // REMOTING_HOST_LINUX_CLIPBOARD |
108 } | 115 } |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
257 } | 264 } |
258 | 265 |
259 VLOG(3) << "Button " << event.button() | 266 VLOG(3) << "Button " << event.button() |
260 << " received, sending " | 267 << " received, sending " |
261 << (event.button_down() ? "down " : "up ") | 268 << (event.button_down() ? "down " : "up ") |
262 << button_number; | 269 << button_number; |
263 XTestFakeButtonEvent(display_, button_number, event.button_down(), | 270 XTestFakeButtonEvent(display_, button_number, event.button_down(), |
264 CurrentTime); | 271 CurrentTime); |
265 } | 272 } |
266 | 273 |
267 if (event.has_wheel_offset_y() && event.wheel_offset_y() != 0) { | 274 int ticks_y = 0; |
268 int dy = event.wheel_offset_y(); | 275 if (event.has_wheel_delta_y()) { |
269 InjectScrollWheelClicks(VerticalScrollWheelToX11ButtonNumber(dy), abs(dy)); | 276 wheel_ticks_y_ += event.wheel_delta_y() * kWheelTicksPerPixel; |
garykac
2012/10/13 01:46:28
Since we're using floats, do we need to be concern
Wez
2012/10/13 02:50:46
That sounds like a good improvement for a future C
| |
277 ticks_y = static_cast<int>(wheel_ticks_y_); | |
278 wheel_ticks_y_ -= ticks_y; | |
279 } else if (event.has_wheel_offset_y()) { | |
280 ticks_y = event.wheel_offset_y(); | |
270 } | 281 } |
271 if (event.has_wheel_offset_x() && event.wheel_offset_x() != 0) { | 282 if (ticks_y != 0) { |
272 int dx = event.wheel_offset_x(); | 283 InjectScrollWheelClicks(VerticalScrollWheelToX11ButtonNumber(ticks_y), |
273 InjectScrollWheelClicks(HorizontalScrollWheelToX11ButtonNumber(dx), | 284 abs(ticks_y)); |
274 abs(dx)); | 285 } |
286 | |
287 int ticks_x = 0; | |
288 if (event.has_wheel_delta_x()) { | |
289 wheel_ticks_x_ += event.wheel_delta_x() * kWheelTicksPerPixel; | |
290 ticks_x = static_cast<int>(wheel_ticks_x_); | |
291 wheel_ticks_x_ -= ticks_x; | |
292 } else if (event.has_wheel_offset_x()) { | |
293 ticks_x = event.wheel_offset_x(); | |
294 } | |
295 if (ticks_x != 0) { | |
296 InjectScrollWheelClicks(HorizontalScrollWheelToX11ButtonNumber(ticks_x), | |
297 abs(ticks_x)); | |
275 } | 298 } |
276 | 299 |
277 XFlush(display_); | 300 XFlush(display_); |
278 } | 301 } |
279 | 302 |
280 void EventExecutorLinux::InitMouseButtonMap() { | 303 void EventExecutorLinux::InitMouseButtonMap() { |
281 // TODO(rmsousa): Run this on global/device mapping change events. | 304 // TODO(rmsousa): Run this on global/device mapping change events. |
282 | 305 |
283 // Do not touch global pointer mapping, since this may affect the local user. | 306 // Do not touch global pointer mapping, since this may affect the local user. |
284 // Instead, try to work around it by reversing the mapping. | 307 // 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, | 433 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, |
411 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner) { | 434 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner) { |
412 scoped_ptr<EventExecutorLinux> executor( | 435 scoped_ptr<EventExecutorLinux> executor( |
413 new EventExecutorLinux(main_task_runner)); | 436 new EventExecutorLinux(main_task_runner)); |
414 if (!executor->Init()) | 437 if (!executor->Init()) |
415 return scoped_ptr<EventExecutor>(NULL); | 438 return scoped_ptr<EventExecutor>(NULL); |
416 return executor.PassAs<EventExecutor>(); | 439 return executor.PassAs<EventExecutor>(); |
417 } | 440 } |
418 | 441 |
419 } // namespace remoting | 442 } // namespace remoting |
OLD | NEW |