Chromium Code Reviews| 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/logging.h" | 17 #include "base/logging.h" |
| 18 #include "base/message_loop.h" | 18 #include "base/message_loop.h" |
| 19 #include "remoting/proto/internal.pb.h" | 19 #include "remoting/proto/internal.pb.h" |
| 20 | 20 |
| 21 namespace remoting { | 21 namespace remoting { |
| 22 | 22 |
| 23 using protocol::ClipboardEvent; | |
|
Sergey Ulanov
2012/03/14 20:27:07
nit: no need to have it here.
simonmorris
2012/03/14 21:20:21
Done.
| |
| 24 using protocol::KeyEvent; | |
| 23 using protocol::MouseEvent; | 25 using protocol::MouseEvent; |
| 24 using protocol::KeyEvent; | |
| 25 | 26 |
| 26 namespace { | 27 namespace { |
| 27 | 28 |
| 28 // A class to generate events on Linux. | 29 // A class to generate events on Linux. |
| 29 class EventExecutorLinux : public EventExecutor { | 30 class EventExecutorLinux : public EventExecutor { |
| 30 public: | 31 public: |
| 31 EventExecutorLinux(MessageLoop* message_loop, Capturer* capturer); | 32 EventExecutorLinux(MessageLoop* message_loop, Capturer* capturer); |
| 32 virtual ~EventExecutorLinux(); | 33 virtual ~EventExecutorLinux(); |
| 33 | 34 |
| 34 bool Init(); | 35 bool Init(); |
| 35 | 36 |
| 37 virtual void InjectClipboardEvent(const ClipboardEvent& event) OVERRIDE; | |
| 36 virtual void InjectKeyEvent(const KeyEvent& event) OVERRIDE; | 38 virtual void InjectKeyEvent(const KeyEvent& event) OVERRIDE; |
|
Sergey Ulanov
2012/03/14 20:27:07
nit: better to separate implementation of Clipboar
simonmorris
2012/03/14 21:20:21
Done.
| |
| 37 virtual void InjectMouseEvent(const MouseEvent& event) OVERRIDE; | 39 virtual void InjectMouseEvent(const MouseEvent& event) OVERRIDE; |
| 38 | 40 |
| 39 private: | 41 private: |
| 40 // |mode| is one of the AutoRepeatModeOn, AutoRepeatModeOff, | 42 // |mode| is one of the AutoRepeatModeOn, AutoRepeatModeOff, |
| 41 // AutoRepeatModeDefault constants defined by the XChangeKeyboardControl() | 43 // AutoRepeatModeDefault constants defined by the XChangeKeyboardControl() |
| 42 // API. | 44 // API. |
| 43 void SetAutoRepeatForKey(int keycode, int mode); | 45 void SetAutoRepeatForKey(int keycode, int mode); |
| 44 void InjectScrollWheelClicks(int button, int count); | 46 void InjectScrollWheelClicks(int button, int count); |
| 45 | 47 |
| 46 MessageLoop* message_loop_; | 48 MessageLoop* message_loop_; |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 292 if (!XGetWindowAttributes(display_, root_window_, &root_attr)) { | 294 if (!XGetWindowAttributes(display_, root_window_, &root_attr)) { |
| 293 LOG(ERROR) << "Unable to get window attributes"; | 295 LOG(ERROR) << "Unable to get window attributes"; |
| 294 return false; | 296 return false; |
| 295 } | 297 } |
| 296 | 298 |
| 297 width_ = root_attr.width; | 299 width_ = root_attr.width; |
| 298 height_ = root_attr.height; | 300 height_ = root_attr.height; |
| 299 return true; | 301 return true; |
| 300 } | 302 } |
| 301 | 303 |
| 304 void EventExecutorLinux::InjectClipboardEvent(const ClipboardEvent& event) { | |
| 305 // TODO(simonmorris): Implement clipboard injection. | |
| 306 } | |
| 307 | |
| 302 void EventExecutorLinux::InjectKeyEvent(const KeyEvent& event) { | 308 void EventExecutorLinux::InjectKeyEvent(const KeyEvent& event) { |
| 303 if (MessageLoop::current() != message_loop_) { | 309 if (MessageLoop::current() != message_loop_) { |
| 304 message_loop_->PostTask( | 310 message_loop_->PostTask( |
| 305 FROM_HERE, | 311 FROM_HERE, |
| 306 base::Bind(&EventExecutorLinux::InjectKeyEvent, base::Unretained(this), | 312 base::Bind(&EventExecutorLinux::InjectKeyEvent, base::Unretained(this), |
| 307 event)); | 313 event)); |
| 308 return; | 314 return; |
| 309 } | 315 } |
| 310 | 316 |
| 311 // TODO(ajwong): This will only work for QWERTY keyboards. | 317 // TODO(ajwong): This will only work for QWERTY keyboards. |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 430 Capturer* capturer) { | 436 Capturer* capturer) { |
| 431 EventExecutorLinux* executor = new EventExecutorLinux(message_loop, capturer); | 437 EventExecutorLinux* executor = new EventExecutorLinux(message_loop, capturer); |
| 432 if (!executor->Init()) { | 438 if (!executor->Init()) { |
| 433 delete executor; | 439 delete executor; |
| 434 executor = NULL; | 440 executor = NULL; |
| 435 } | 441 } |
| 436 return executor; | 442 return executor; |
| 437 } | 443 } |
| 438 | 444 |
| 439 } // namespace remoting | 445 } // namespace remoting |
| OLD | NEW |