| 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 <set> | 7 #include <set> |
| 8 | 8 |
| 9 #include <X11/Xlib.h> | 9 #include <X11/Xlib.h> |
| 10 #include <X11/XF86keysym.h> | 10 #include <X11/XF86keysym.h> |
| 11 #include <X11/keysym.h> | 11 #include <X11/keysym.h> |
| 12 #include <X11/extensions/XTest.h> | 12 #include <X11/extensions/XTest.h> |
| 13 | 13 |
| 14 #include "base/basictypes.h" | 14 #include "base/basictypes.h" |
| 15 #include "base/bind.h" | 15 #include "base/bind.h" |
| 16 #include "base/compiler_specific.h" | 16 #include "base/compiler_specific.h" |
| 17 #include "base/location.h" | 17 #include "base/location.h" |
| 18 #include "base/logging.h" | 18 #include "base/logging.h" |
| 19 #include "base/single_thread_task_runner.h" | 19 #include "base/single_thread_task_runner.h" |
| 20 #include "remoting/host/clipboard.h" |
| 20 #include "remoting/proto/internal.pb.h" | 21 #include "remoting/proto/internal.pb.h" |
| 21 #include "third_party/skia/include/core/SkPoint.h" | 22 #include "third_party/skia/include/core/SkPoint.h" |
| 22 | 23 |
| 23 namespace remoting { | 24 namespace remoting { |
| 24 | 25 |
| 25 namespace { | 26 namespace { |
| 26 | 27 |
| 27 using protocol::ClipboardEvent; | 28 using protocol::ClipboardEvent; |
| 28 using protocol::KeyEvent; | 29 using protocol::KeyEvent; |
| 29 using protocol::MouseEvent; | 30 using protocol::MouseEvent; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 std::set<int> pressed_keys_; | 67 std::set<int> pressed_keys_; |
| 67 SkIPoint latest_mouse_position_; | 68 SkIPoint latest_mouse_position_; |
| 68 | 69 |
| 69 // X11 graphics context. | 70 // X11 graphics context. |
| 70 Display* display_; | 71 Display* display_; |
| 71 Window root_window_; | 72 Window root_window_; |
| 72 | 73 |
| 73 int test_event_base_; | 74 int test_event_base_; |
| 74 int test_error_base_; | 75 int test_error_base_; |
| 75 | 76 |
| 77 scoped_ptr<Clipboard> clipboard_; |
| 78 |
| 76 DISALLOW_COPY_AND_ASSIGN(EventExecutorLinux); | 79 DISALLOW_COPY_AND_ASSIGN(EventExecutorLinux); |
| 77 }; | 80 }; |
| 78 | 81 |
| 79 int MouseButtonToX11ButtonNumber(MouseEvent::MouseButton button) { | 82 int MouseButtonToX11ButtonNumber(MouseEvent::MouseButton button) { |
| 80 switch (button) { | 83 switch (button) { |
| 81 case MouseEvent::BUTTON_LEFT: | 84 case MouseEvent::BUTTON_LEFT: |
| 82 return 1; | 85 return 1; |
| 83 | 86 |
| 84 case MouseEvent::BUTTON_RIGHT: | 87 case MouseEvent::BUTTON_RIGHT: |
| 85 return 3; | 88 return 3; |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 return kInvalidKeycode; | 271 return kInvalidKeycode; |
| 269 | 272 |
| 270 return kUsVkeyToKeysym[keycode]; | 273 return kUsVkeyToKeysym[keycode]; |
| 271 } | 274 } |
| 272 | 275 |
| 273 EventExecutorLinux::EventExecutorLinux( | 276 EventExecutorLinux::EventExecutorLinux( |
| 274 scoped_refptr<base::SingleThreadTaskRunner> task_runner) | 277 scoped_refptr<base::SingleThreadTaskRunner> task_runner) |
| 275 : task_runner_(task_runner), | 278 : task_runner_(task_runner), |
| 276 latest_mouse_position_(SkIPoint::Make(-1, -1)), | 279 latest_mouse_position_(SkIPoint::Make(-1, -1)), |
| 277 display_(XOpenDisplay(NULL)), | 280 display_(XOpenDisplay(NULL)), |
| 278 root_window_(BadValue) { | 281 root_window_(BadValue), |
| 282 clipboard_(Clipboard::Create()) { |
| 279 } | 283 } |
| 280 | 284 |
| 281 EventExecutorLinux::~EventExecutorLinux() { | 285 EventExecutorLinux::~EventExecutorLinux() { |
| 282 CHECK(pressed_keys_.empty()); | 286 CHECK(pressed_keys_.empty()); |
| 283 } | 287 } |
| 284 | 288 |
| 285 bool EventExecutorLinux::Init() { | 289 bool EventExecutorLinux::Init() { |
| 286 CHECK(display_); | 290 CHECK(display_); |
| 287 | 291 |
| 288 root_window_ = RootWindow(display_, DefaultScreen(display_)); | 292 root_window_ = RootWindow(display_, DefaultScreen(display_)); |
| 289 if (root_window_ == BadValue) { | 293 if (root_window_ == BadValue) { |
| 290 LOG(ERROR) << "Unable to get the root window"; | 294 LOG(ERROR) << "Unable to get the root window"; |
| 291 return false; | 295 return false; |
| 292 } | 296 } |
| 293 | 297 |
| 294 // TODO(ajwong): Do we want to check the major/minor version at all for XTest? | 298 // TODO(ajwong): Do we want to check the major/minor version at all for XTest? |
| 295 int major = 0; | 299 int major = 0; |
| 296 int minor = 0; | 300 int minor = 0; |
| 297 if (!XTestQueryExtension(display_, &test_event_base_, &test_error_base_, | 301 if (!XTestQueryExtension(display_, &test_event_base_, &test_error_base_, |
| 298 &major, &minor)) { | 302 &major, &minor)) { |
| 299 LOG(ERROR) << "Server does not support XTest."; | 303 LOG(ERROR) << "Server does not support XTest."; |
| 300 return false; | 304 return false; |
| 301 } | 305 } |
| 302 | 306 |
| 303 return true; | 307 return true; |
| 304 } | 308 } |
| 305 | 309 |
| 306 void EventExecutorLinux::InjectClipboardEvent(const ClipboardEvent& event) { | 310 void EventExecutorLinux::InjectClipboardEvent(const ClipboardEvent& event) { |
| 307 // TODO(simonmorris): Implement clipboard injection. | 311 clipboard_->InjectClipboardEvent(event); |
| 308 } | 312 } |
| 309 | 313 |
| 310 void EventExecutorLinux::InjectKeyEvent(const KeyEvent& event) { | 314 void EventExecutorLinux::InjectKeyEvent(const KeyEvent& event) { |
| 311 // HostEventDispatcher should filter events missing the pressed field. | 315 // HostEventDispatcher should filter events missing the pressed field. |
| 312 DCHECK(event.has_pressed()); | 316 DCHECK(event.has_pressed()); |
| 313 | 317 |
| 314 if (!task_runner_->BelongsToCurrentThread()) { | 318 if (!task_runner_->BelongsToCurrentThread()) { |
| 315 task_runner_->PostTask( | 319 task_runner_->PostTask( |
| 316 FROM_HERE, | 320 FROM_HERE, |
| 317 base::Bind(&EventExecutorLinux::InjectKeyEvent, base::Unretained(this), | 321 base::Bind(&EventExecutorLinux::InjectKeyEvent, base::Unretained(this), |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 434 int dx = event.wheel_offset_x(); | 438 int dx = event.wheel_offset_x(); |
| 435 InjectScrollWheelClicks(HorizontalScrollWheelToX11ButtonNumber(dx), | 439 InjectScrollWheelClicks(HorizontalScrollWheelToX11ButtonNumber(dx), |
| 436 abs(dx)); | 440 abs(dx)); |
| 437 } | 441 } |
| 438 | 442 |
| 439 XFlush(display_); | 443 XFlush(display_); |
| 440 } | 444 } |
| 441 | 445 |
| 442 void EventExecutorLinux::OnSessionStarted( | 446 void EventExecutorLinux::OnSessionStarted( |
| 443 scoped_ptr<protocol::ClipboardStub> client_clipboard) { | 447 scoped_ptr<protocol::ClipboardStub> client_clipboard) { |
| 444 return; | 448 clipboard_->Start(client_clipboard.Pass()); |
| 445 } | 449 } |
| 446 | 450 |
| 447 void EventExecutorLinux::OnSessionFinished() { | 451 void EventExecutorLinux::OnSessionFinished() { |
| 448 return; | 452 clipboard_->Stop(); |
| 449 } | 453 } |
| 450 | 454 |
| 451 } // namespace | 455 } // namespace |
| 452 | 456 |
| 453 scoped_ptr<EventExecutor> EventExecutor::Create( | 457 scoped_ptr<EventExecutor> EventExecutor::Create( |
| 454 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, | 458 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, |
| 455 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner) { | 459 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner) { |
| 456 scoped_ptr<EventExecutorLinux> executor( | 460 scoped_ptr<EventExecutorLinux> executor( |
| 457 new EventExecutorLinux(main_task_runner)); | 461 new EventExecutorLinux(main_task_runner)); |
| 458 if (!executor->Init()) | 462 if (!executor->Init()) |
| 459 return scoped_ptr<EventExecutor>(NULL); | 463 return scoped_ptr<EventExecutor>(NULL); |
| 460 return executor.PassAs<EventExecutor>(); | 464 return executor.PassAs<EventExecutor>(); |
| 461 } | 465 } |
| 462 | 466 |
| 463 } // namespace remoting | 467 } // namespace remoting |
| OLD | NEW |