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/linux/x_server_clipboard.h" | 5 #include "remoting/host/linux/x_server_clipboard.h" |
| 6 | 6 |
| 7 #include <X11/extensions/Xfixes.h> | 7 #include <X11/extensions/Xfixes.h> |
| 8 | 8 |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "remoting/base/constants.h" | 11 #include "remoting/base/constants.h" |
| 12 #include "remoting/base/logging.h" | 12 #include "remoting/base/logging.h" |
| 13 #include "remoting/base/util.h" | 13 #include "remoting/base/util.h" |
| 14 #include "ui/base/x/x11_util.h" | |
| 14 | 15 |
| 15 namespace remoting { | 16 namespace remoting { |
| 16 | 17 |
| 17 XServerClipboard::XServerClipboard() | 18 XServerClipboard::XServerClipboard() |
| 18 : display_(nullptr), | 19 : display_(nullptr), |
| 19 clipboard_window_(BadValue), | 20 clipboard_window_(BadValue), |
| 20 xfixes_event_base_(-1), | 21 xfixes_event_base_(-1), |
| 21 clipboard_atom_(None), | 22 clipboard_atom_(None), |
| 22 large_selection_atom_(None), | 23 large_selection_atom_(None), |
| 23 selection_string_atom_(None), | 24 selection_string_atom_(None), |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 48 &xfixes_error_base)) { | 49 &xfixes_error_base)) { |
| 49 HOST_LOG << "X server does not support XFixes."; | 50 HOST_LOG << "X server does not support XFixes."; |
| 50 return; | 51 return; |
| 51 } | 52 } |
| 52 | 53 |
| 53 clipboard_window_ = XCreateSimpleWindow(display_, | 54 clipboard_window_ = XCreateSimpleWindow(display_, |
| 54 DefaultRootWindow(display_), | 55 DefaultRootWindow(display_), |
| 55 0, 0, 1, 1, // x, y, width, height | 56 0, 0, 1, 1, // x, y, width, height |
| 56 0, 0, 0); | 57 0, 0, 0); |
| 57 | 58 |
| 58 // TODO(lambroslambrou): Use ui::X11AtomCache for this, either by adding a | 59 clipboard_atom_ = ui::GetAtom("CLIPLBOARD"); |
|
Sergey Ulanov
2017/06/01 20:40:09
This uses a different X connection, so I don't thi
Tom Anderson
2017/06/01 21:20:42
Done.
| |
| 59 // dependency on ui/ or by moving X11AtomCache to base/. | 60 large_selection_atom_ = ui::GetAtom("INCR"); |
| 60 static const char* const kAtomNames[] = { | 61 selection_string_atom_ = ui::GetAtom("SELECTION_STRING"); |
| 61 "CLIPBOARD", | 62 targets_atom_ = ui::GetAtom("TARGETS"); |
| 62 "INCR", | 63 timestamp_atom_ = ui::GetAtom("TIMESTAMP"); |
| 63 "SELECTION_STRING", | 64 utf8_string_atom_ = ui::GetAtom("UTF8_STRING"); |
| 64 "TARGETS", | |
| 65 "TIMESTAMP", | |
| 66 "UTF8_STRING" | |
| 67 }; | |
| 68 static const int kNumAtomNames = arraysize(kAtomNames); | |
| 69 | |
| 70 Atom atoms[kNumAtomNames]; | |
| 71 if (XInternAtoms(display_, const_cast<char**>(kAtomNames), kNumAtomNames, | |
| 72 False, atoms)) { | |
| 73 clipboard_atom_ = atoms[0]; | |
| 74 large_selection_atom_ = atoms[1]; | |
| 75 selection_string_atom_ = atoms[2]; | |
| 76 targets_atom_ = atoms[3]; | |
| 77 timestamp_atom_ = atoms[4]; | |
| 78 utf8_string_atom_ = atoms[5]; | |
| 79 static_assert(kNumAtomNames >= 6, "kAtomNames is too small"); | |
| 80 } else { | |
| 81 LOG(ERROR) << "XInternAtoms failed"; | |
| 82 } | |
| 83 | 65 |
| 84 XFixesSelectSelectionInput(display_, clipboard_window_, clipboard_atom_, | 66 XFixesSelectSelectionInput(display_, clipboard_window_, clipboard_atom_, |
|
sadrul
2017/06/01 20:45:30
Same here. Looks like this |display_| is one initi
Tom Anderson
2017/06/01 21:20:42
Done.
| |
| 85 XFixesSetSelectionOwnerNotifyMask); | 67 XFixesSetSelectionOwnerNotifyMask); |
| 86 } | 68 } |
| 87 | 69 |
| 88 void XServerClipboard::SetClipboard(const std::string& mime_type, | 70 void XServerClipboard::SetClipboard(const std::string& mime_type, |
| 89 const std::string& data) { | 71 const std::string& data) { |
| 90 DCHECK(display_); | 72 DCHECK(display_); |
| 91 | 73 |
| 92 if (clipboard_window_ == BadValue) | 74 if (clipboard_window_ == BadValue) |
| 93 return; | 75 return; |
| 94 | 76 |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 366 } else { | 348 } else { |
| 367 LOG(ERROR) << "XSetSelectionOwner failed for selection " << selection; | 349 LOG(ERROR) << "XSetSelectionOwner failed for selection " << selection; |
| 368 } | 350 } |
| 369 } | 351 } |
| 370 | 352 |
| 371 bool XServerClipboard::IsSelectionOwner(Atom selection) { | 353 bool XServerClipboard::IsSelectionOwner(Atom selection) { |
| 372 return selections_owned_.find(selection) != selections_owned_.end(); | 354 return selections_owned_.find(selection) != selections_owned_.end(); |
| 373 } | 355 } |
| 374 | 356 |
| 375 } // namespace remoting | 357 } // namespace remoting |
| OLD | NEW |