Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/XF86keysym.h> | 8 #include <X11/XF86keysym.h> |
| 9 #include <X11/keysym.h> | 9 #include <X11/keysym.h> |
| 10 #include <X11/extensions/XTest.h> | 10 #include <X11/extensions/XTest.h> |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 61 | 61 |
| 62 case MouseEvent::BUTTON_MIDDLE: | 62 case MouseEvent::BUTTON_MIDDLE: |
| 63 return 2; | 63 return 2; |
| 64 | 64 |
| 65 case MouseEvent::BUTTON_UNDEFINED: | 65 case MouseEvent::BUTTON_UNDEFINED: |
| 66 default: | 66 default: |
| 67 return -1; | 67 return -1; |
| 68 } | 68 } |
| 69 } | 69 } |
| 70 | 70 |
| 71 int VerticalScrollWheelToX11ButtonNumber(int dy) { | |
|
Lambros
2011/10/13 00:56:06
Personally, I like "dy", but it might fall foul of
garykac
2011/10/13 21:18:53
^_^
| |
| 72 // Positive y-values are wheel down events (button 4), negative y-values are | |
| 73 // wheel up (button 5). | |
|
Lambros
2011/10/13 00:41:13
Is this comment the wrong way round? If I touch m
garykac
2011/10/13 21:18:53
Fixed.
| |
| 74 return (dy > 0 ? 4 : 5); | |
| 75 } | |
| 76 | |
| 71 // Hard-coded mapping from Virtual Key codes to X11 KeySyms. | 77 // Hard-coded mapping from Virtual Key codes to X11 KeySyms. |
| 72 // This mapping is only valid if both client and host are using a | 78 // This mapping is only valid if both client and host are using a |
| 73 // US English keyboard layout. | 79 // US English keyboard layout. |
| 74 // Because we're passing VK codes on the wire, with no Scancode, | 80 // Because we're passing VK codes on the wire, with no Scancode, |
| 75 // "extended" flag, etc, things like distinguishing left & right | 81 // "extended" flag, etc, things like distinguishing left & right |
| 76 // Shift keys doesn't work. | 82 // Shift keys doesn't work. |
| 77 // | 83 // |
| 78 // TODO(wez): Replace this with something more closely tied to what | 84 // TODO(wez): Replace this with something more closely tied to what |
| 79 // WebInputEventFactory does on Linux/GTK, and which respects the | 85 // WebInputEventFactory does on Linux/GTK, and which respects the |
| 80 // host's keyboard layout (see http://crbug.com/74550 ). | 86 // host's keyboard layout (see http://crbug.com/74550 ). |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 332 XTestFakeMotionEvent(display_, DefaultScreen(display_), | 338 XTestFakeMotionEvent(display_, DefaultScreen(display_), |
| 333 event.x(), event.y(), | 339 event.x(), event.y(), |
| 334 CurrentTime); | 340 CurrentTime); |
| 335 XFlush(display_); | 341 XFlush(display_); |
| 336 } | 342 } |
| 337 | 343 |
| 338 if (event.has_button() && event.has_button_down()) { | 344 if (event.has_button() && event.has_button_down()) { |
| 339 int button_number = MouseButtonToX11ButtonNumber(event.button()); | 345 int button_number = MouseButtonToX11ButtonNumber(event.button()); |
| 340 | 346 |
| 341 if (button_number < 0) { | 347 if (button_number < 0) { |
| 342 LOG(WARNING) << "Ignoring unknown button type: " | 348 LOG(WARNING) << "Ignoring unknown button type: " << event.button(); |
| 343 << event.button(); | |
| 344 return; | 349 return; |
| 345 } | 350 } |
| 346 | 351 |
| 347 VLOG(3) << "Button " << event.button() | 352 VLOG(3) << "Button " << event.button() |
| 348 << " received, sending " | 353 << " received, sending " |
| 349 << (event.button_down() ? "down " : "up ") | 354 << (event.button_down() ? "down " : "up ") |
| 350 << button_number; | 355 << button_number; |
| 351 XTestFakeButtonEvent(display_, button_number, event.button_down(), | 356 XTestFakeButtonEvent(display_, button_number, event.button_down(), |
| 352 CurrentTime); | 357 CurrentTime); |
| 353 XFlush(display_); | 358 XFlush(display_); |
| 354 } | 359 } |
| 355 | 360 |
| 356 if (event.has_wheel_offset_x() && event.has_wheel_offset_y()) { | 361 if (event.has_wheel_offset_x() && event.wheel_offset_x() != 0) { |
| 357 NOTIMPLEMENTED() << "No scroll wheel support yet."; | 362 NOTIMPLEMENTED() << "No horizontal scroll wheel support yet."; |
| 363 } | |
| 364 if (event.has_wheel_offset_y()) { | |
| 365 int dy = event.wheel_offset_y(); | |
| 366 int button_number = VerticalScrollWheelToX11ButtonNumber(dy); | |
| 367 if (dy < 0) | |
| 368 dy = -dy; | |
| 369 | |
| 370 for (int i = 0; i < dy; i++) { | |
| 371 // Generate a button-down and a button-up to simulate a wheel click. | |
| 372 XTestFakeButtonEvent(display_, button_number, true, CurrentTime); | |
| 373 XTestFakeButtonEvent(display_, button_number, false, CurrentTime); | |
| 374 } | |
| 375 XFlush(display_); | |
| 358 } | 376 } |
| 359 } | 377 } |
| 360 | 378 |
| 361 } // namespace | 379 } // namespace |
| 362 | 380 |
| 363 EventExecutor* EventExecutor::Create(MessageLoop* message_loop, | 381 EventExecutor* EventExecutor::Create(MessageLoop* message_loop, |
| 364 Capturer* capturer) { | 382 Capturer* capturer) { |
| 365 EventExecutorLinux* executor = new EventExecutorLinux(message_loop, capturer); | 383 EventExecutorLinux* executor = new EventExecutorLinux(message_loop, capturer); |
| 366 if (!executor->Init()) { | 384 if (!executor->Init()) { |
| 367 delete executor; | 385 delete executor; |
| 368 executor = NULL; | 386 executor = NULL; |
| 369 } | 387 } |
| 370 return executor; | 388 return executor; |
| 371 } | 389 } |
| 372 | 390 |
| 373 } // namespace remoting | 391 } // namespace remoting |
| OLD | NEW |