| 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.h" | 5 #include "remoting/host/local_input_monitor.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> |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 | 118 |
| 119 LocalInputMonitorX11::Core::Core( | 119 LocalInputMonitorX11::Core::Core( |
| 120 scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner, | 120 scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner, |
| 121 scoped_refptr<base::SingleThreadTaskRunner> input_task_runner, | 121 scoped_refptr<base::SingleThreadTaskRunner> input_task_runner, |
| 122 base::WeakPtr<ClientSessionControl> client_session_control) | 122 base::WeakPtr<ClientSessionControl> client_session_control) |
| 123 : caller_task_runner_(caller_task_runner), | 123 : caller_task_runner_(caller_task_runner), |
| 124 input_task_runner_(input_task_runner), | 124 input_task_runner_(input_task_runner), |
| 125 client_session_control_(client_session_control), | 125 client_session_control_(client_session_control), |
| 126 alt_pressed_(false), | 126 alt_pressed_(false), |
| 127 ctrl_pressed_(false), | 127 ctrl_pressed_(false), |
| 128 display_(NULL), | 128 display_(nullptr), |
| 129 x_record_display_(NULL), | 129 x_record_display_(nullptr), |
| 130 x_record_context_(0) { | 130 x_record_context_(0) { |
| 131 DCHECK(caller_task_runner_->BelongsToCurrentThread()); | 131 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
| 132 DCHECK(client_session_control_.get()); | 132 DCHECK(client_session_control_.get()); |
| 133 | 133 |
| 134 x_record_range_[0] = NULL; | 134 x_record_range_[0] = nullptr; |
| 135 x_record_range_[1] = NULL; | 135 x_record_range_[1] = nullptr; |
| 136 } | 136 } |
| 137 | 137 |
| 138 void LocalInputMonitorX11::Core::Start() { | 138 void LocalInputMonitorX11::Core::Start() { |
| 139 DCHECK(caller_task_runner_->BelongsToCurrentThread()); | 139 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
| 140 | 140 |
| 141 input_task_runner_->PostTask(FROM_HERE, | 141 input_task_runner_->PostTask(FROM_HERE, |
| 142 base::Bind(&Core::StartOnInputThread, this)); | 142 base::Bind(&Core::StartOnInputThread, this)); |
| 143 } | 143 } |
| 144 | 144 |
| 145 void LocalInputMonitorX11::Core::Stop() { | 145 void LocalInputMonitorX11::Core::Stop() { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 163 DCHECK(!x_record_display_); | 163 DCHECK(!x_record_display_); |
| 164 DCHECK(!x_record_range_[0]); | 164 DCHECK(!x_record_range_[0]); |
| 165 DCHECK(!x_record_range_[1]); | 165 DCHECK(!x_record_range_[1]); |
| 166 DCHECK(!x_record_context_); | 166 DCHECK(!x_record_context_); |
| 167 | 167 |
| 168 // TODO(jamiewalch): We should pass the display in. At that point, since | 168 // TODO(jamiewalch): We should pass the display in. At that point, since |
| 169 // XRecord needs a private connection to the X Server for its data channel | 169 // XRecord needs a private connection to the X Server for its data channel |
| 170 // and both channels are used from a separate thread, we'll need to duplicate | 170 // and both channels are used from a separate thread, we'll need to duplicate |
| 171 // them with something like the following: | 171 // them with something like the following: |
| 172 // XOpenDisplay(DisplayString(display)); | 172 // XOpenDisplay(DisplayString(display)); |
| 173 display_ = XOpenDisplay(NULL); | 173 display_ = XOpenDisplay(nullptr); |
| 174 x_record_display_ = XOpenDisplay(NULL); | 174 x_record_display_ = XOpenDisplay(nullptr); |
| 175 if (!display_ || !x_record_display_) { | 175 if (!display_ || !x_record_display_) { |
| 176 LOG(ERROR) << "Couldn't open X display"; | 176 LOG(ERROR) << "Couldn't open X display"; |
| 177 return; | 177 return; |
| 178 } | 178 } |
| 179 | 179 |
| 180 int xr_opcode, xr_event, xr_error; | 180 int xr_opcode, xr_event, xr_error; |
| 181 if (!XQueryExtension(display_, "RECORD", &xr_opcode, &xr_event, &xr_error)) { | 181 if (!XQueryExtension(display_, "RECORD", &xr_opcode, &xr_event, &xr_error)) { |
| 182 LOG(ERROR) << "X Record extension not available."; | 182 LOG(ERROR) << "X Record extension not available."; |
| 183 return; | 183 return; |
| 184 } | 184 } |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 // any X protocol traffic over the data channel while it's recording. | 238 // any X protocol traffic over the data channel while it's recording. |
| 239 if (x_record_context_) { | 239 if (x_record_context_) { |
| 240 XRecordDisableContext(display_, x_record_context_); | 240 XRecordDisableContext(display_, x_record_context_); |
| 241 XFlush(display_); | 241 XFlush(display_); |
| 242 } | 242 } |
| 243 | 243 |
| 244 controller_.StopWatchingFileDescriptor(); | 244 controller_.StopWatchingFileDescriptor(); |
| 245 | 245 |
| 246 if (x_record_range_[0]) { | 246 if (x_record_range_[0]) { |
| 247 XFree(x_record_range_[0]); | 247 XFree(x_record_range_[0]); |
| 248 x_record_range_[0] = NULL; | 248 x_record_range_[0] = nullptr; |
| 249 } | 249 } |
| 250 if (x_record_range_[1]) { | 250 if (x_record_range_[1]) { |
| 251 XFree(x_record_range_[1]); | 251 XFree(x_record_range_[1]); |
| 252 x_record_range_[1] = NULL; | 252 x_record_range_[1] = nullptr; |
| 253 } | 253 } |
| 254 if (x_record_context_) { | 254 if (x_record_context_) { |
| 255 XRecordFreeContext(x_record_display_, x_record_context_); | 255 XRecordFreeContext(x_record_display_, x_record_context_); |
| 256 x_record_context_ = 0; | 256 x_record_context_ = 0; |
| 257 } | 257 } |
| 258 if (x_record_display_) { | 258 if (x_record_display_) { |
| 259 XCloseDisplay(x_record_display_); | 259 XCloseDisplay(x_record_display_); |
| 260 x_record_display_ = NULL; | 260 x_record_display_ = nullptr; |
| 261 } | 261 } |
| 262 if (display_) { | 262 if (display_) { |
| 263 XCloseDisplay(display_); | 263 XCloseDisplay(display_); |
| 264 display_ = NULL; | 264 display_ = nullptr; |
| 265 } | 265 } |
| 266 } | 266 } |
| 267 | 267 |
| 268 void LocalInputMonitorX11::Core::OnFileCanReadWithoutBlocking(int fd) { | 268 void LocalInputMonitorX11::Core::OnFileCanReadWithoutBlocking(int fd) { |
| 269 DCHECK(input_task_runner_->BelongsToCurrentThread()); | 269 DCHECK(input_task_runner_->BelongsToCurrentThread()); |
| 270 | 270 |
| 271 // Fetch pending events if any. | 271 // Fetch pending events if any. |
| 272 while (XPending(x_record_display_)) { | 272 while (XPending(x_record_display_)) { |
| 273 XEvent ev; | 273 XEvent ev; |
| 274 XNextEvent(x_record_display_, &ev); | 274 XNextEvent(x_record_display_, &ev); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 scoped_ptr<LocalInputMonitor> LocalInputMonitor::Create( | 320 scoped_ptr<LocalInputMonitor> LocalInputMonitor::Create( |
| 321 scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner, | 321 scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner, |
| 322 scoped_refptr<base::SingleThreadTaskRunner> input_task_runner, | 322 scoped_refptr<base::SingleThreadTaskRunner> input_task_runner, |
| 323 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner, | 323 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner, |
| 324 base::WeakPtr<ClientSessionControl> client_session_control) { | 324 base::WeakPtr<ClientSessionControl> client_session_control) { |
| 325 return make_scoped_ptr(new LocalInputMonitorX11( | 325 return make_scoped_ptr(new LocalInputMonitorX11( |
| 326 caller_task_runner, input_task_runner, client_session_control)); | 326 caller_task_runner, input_task_runner, client_session_control)); |
| 327 } | 327 } |
| 328 | 328 |
| 329 } // namespace remoting | 329 } // namespace remoting |
| OLD | NEW |