| 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/local_input_monitor_thread_linux.h" | 5 #include "remoting/host/local_input_monitor_thread_linux.h" |
| 6 | 6 |
| 7 #include <sys/select.h> | 7 #include <sys/select.h> |
| 8 #include <unistd.h> | 8 #include <unistd.h> |
| 9 #define XK_MISCELLANY | 9 #define XK_MISCELLANY |
| 10 #include <X11/keysymdef.h> | 10 #include <X11/keysymdef.h> |
| 11 | 11 |
| 12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 13 #include "base/callback.h" |
| 13 #include "base/eintr_wrapper.h" | 14 #include "base/eintr_wrapper.h" |
| 14 #include "remoting/host/chromoting_host.h" | 15 #include "base/logging.h" |
| 16 #include "remoting/host/mouse_move_observer.h" |
| 17 #include "third_party/skia/include/core/SkPoint.h" |
| 15 | 18 |
| 16 // These includes need to be later than dictated by the style guide due to | 19 // These includes need to be later than dictated by the style guide due to |
| 17 // Xlib header pollution, specifically the min, max, and Status macros. | 20 // Xlib header pollution, specifically the min, max, and Status macros. |
| 18 #include <X11/XKBlib.h> | 21 #include <X11/XKBlib.h> |
| 19 #include <X11/Xlibint.h> | 22 #include <X11/Xlibint.h> |
| 20 #include <X11/extensions/record.h> | 23 #include <X11/extensions/record.h> |
| 21 | 24 |
| 22 namespace { | 25 namespace { |
| 23 | 26 |
| 24 struct scoped_x_record_context { | 27 struct scoped_x_record_context { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 55 event->u.keyButtonPointer.rootY)); | 58 event->u.keyButtonPointer.rootY)); |
| 56 reinterpret_cast<LocalInputMonitorThread*>(thread)->LocalMouseMoved(pos); | 59 reinterpret_cast<LocalInputMonitorThread*>(thread)->LocalMouseMoved(pos); |
| 57 } else { | 60 } else { |
| 58 reinterpret_cast<LocalInputMonitorThread*>(thread)->LocalKeyPressed( | 61 reinterpret_cast<LocalInputMonitorThread*>(thread)->LocalKeyPressed( |
| 59 event->u.u.detail, event->u.u.type == KeyPress); | 62 event->u.u.detail, event->u.u.type == KeyPress); |
| 60 } | 63 } |
| 61 } | 64 } |
| 62 XRecordFreeData(data); | 65 XRecordFreeData(data); |
| 63 } | 66 } |
| 64 | 67 |
| 65 LocalInputMonitorThread::LocalInputMonitorThread(ChromotingHost* host) | 68 LocalInputMonitorThread::LocalInputMonitorThread( |
| 69 MouseMoveObserver* mouse_move_observer, |
| 70 const base::Closure& disconnect_callback) |
| 66 : base::SimpleThread("LocalInputMonitor"), | 71 : base::SimpleThread("LocalInputMonitor"), |
| 67 host_(host), display_(NULL), alt_pressed_(false), ctrl_pressed_(false) { | 72 mouse_move_observer_(mouse_move_observer), |
| 73 disconnect_callback_(disconnect_callback), |
| 74 display_(NULL), |
| 75 alt_pressed_(false), |
| 76 ctrl_pressed_(false) { |
| 68 wakeup_pipe_[0] = -1; | 77 wakeup_pipe_[0] = -1; |
| 69 wakeup_pipe_[1] = -1; | 78 wakeup_pipe_[1] = -1; |
| 70 CHECK_EQ(pipe(wakeup_pipe_), 0); | 79 CHECK_EQ(pipe(wakeup_pipe_), 0); |
| 71 } | 80 } |
| 72 | 81 |
| 73 LocalInputMonitorThread::~LocalInputMonitorThread() { | 82 LocalInputMonitorThread::~LocalInputMonitorThread() { |
| 74 close(wakeup_pipe_[0]); | 83 close(wakeup_pipe_[0]); |
| 75 close(wakeup_pipe_[1]); | 84 close(wakeup_pipe_[1]); |
| 76 } | 85 } |
| 77 | 86 |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 // any X protocol traffic over the data channel while it's recording. | 166 // any X protocol traffic over the data channel while it's recording. |
| 158 XRecordDisableContext(display_, scoper.context); | 167 XRecordDisableContext(display_, scoper.context); |
| 159 XFlush(display_); | 168 XFlush(display_); |
| 160 } | 169 } |
| 161 | 170 |
| 162 XCloseDisplay(display_); | 171 XCloseDisplay(display_); |
| 163 display_ = NULL; | 172 display_ = NULL; |
| 164 } | 173 } |
| 165 | 174 |
| 166 void LocalInputMonitorThread::LocalMouseMoved(const SkIPoint& pos) { | 175 void LocalInputMonitorThread::LocalMouseMoved(const SkIPoint& pos) { |
| 167 host_->LocalMouseMoved(pos); | 176 mouse_move_observer_->OnLocalMouseMoved(pos); |
| 168 } | 177 } |
| 169 | 178 |
| 170 void LocalInputMonitorThread::LocalKeyPressed(int key_code, bool down) { | 179 void LocalInputMonitorThread::LocalKeyPressed(int key_code, bool down) { |
| 171 KeySym key_sym = XkbKeycodeToKeysym(display_, key_code, 0, 0); | 180 KeySym key_sym = XkbKeycodeToKeysym(display_, key_code, 0, 0); |
| 172 if (key_sym == XK_Control_L || key_sym == XK_Control_R) { | 181 if (key_sym == XK_Control_L || key_sym == XK_Control_R) { |
| 173 ctrl_pressed_ = down; | 182 ctrl_pressed_ = down; |
| 174 } else if (key_sym == XK_Alt_L || key_sym == XK_Alt_R) { | 183 } else if (key_sym == XK_Alt_L || key_sym == XK_Alt_R) { |
| 175 alt_pressed_ = down; | 184 alt_pressed_ = down; |
| 176 } else if (alt_pressed_ && ctrl_pressed_ && key_sym == XK_Escape && down) { | 185 } else if (alt_pressed_ && ctrl_pressed_ && key_sym == XK_Escape && down) { |
| 177 host_->Shutdown(base::Closure()); | 186 disconnect_callback_.Run(); |
| 178 } | 187 } |
| 179 } | 188 } |
| 180 | 189 |
| 181 } // namespace remoting | 190 } // namespace remoting |
| OLD | NEW |