0

[XProto] Remove old x11::* constants

BUG=1066670
R=sky

Change-Id: I3df7737031e8aecc9463b8f42fb5bcf8b5722693
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2410841
Commit-Queue: Thomas Anderson <thomasanderson@chromium.org>
Auto-Submit: Thomas Anderson <thomasanderson@chromium.org>
Reviewed-by: Scott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#807165}
This commit is contained in:
Tom Anderson
2020-09-15 20:35:25 +00:00
committed by Commit Bot
parent faa1a22bb4
commit 2a460ccaa4
16 changed files with 222 additions and 209 deletions

@@ -111,7 +111,7 @@ bool GlobalShortcutListenerX11::RegisterAcceleratorImpl(
// Caps lock, Scroll lock. See comment about |kModifiersMasks|. // Caps lock, Scroll lock. See comment about |kModifiersMasks|.
for (unsigned int kModifiersMask : kModifiersMasks) { for (unsigned int kModifiersMask : kModifiersMasks) {
XGrabKey(x_display_, keycode, modifiers | kModifiersMask, XGrabKey(x_display_, keycode, modifiers | kModifiersMask,
static_cast<uint32_t>(x_root_window_), x11::False, GrabModeAsync, static_cast<uint32_t>(x_root_window_), false, GrabModeAsync,
GrabModeAsync); GrabModeAsync);
} }

@@ -191,8 +191,8 @@ class Simulator {
display_, kVisualIdMask, &visual_info_template, &visual_info_count); display_, kVisualIdMask, &visual_info_template, &visual_info_count);
for (int i = 0; i < visual_info_count && !gl_context_; ++i) { for (int i = 0; i < visual_info_count && !gl_context_; ++i) {
gl_context_ = glXCreateContext(display_, visual_info_list + i, 0, gl_context_ = glXCreateContext(display_, visual_info_list + i, nullptr,
x11::True /* Direct rendering */); true /* Direct rendering */);
} }
XFree(visual_info_list); XFree(visual_info_list);

@@ -168,7 +168,6 @@ class InputInjectorX11 : public InputInjector {
// X11 graphics context. // X11 graphics context.
x11::Connection connection_; x11::Connection connection_;
Display* display_ = connection_.display(); Display* display_ = connection_.display();
Window root_window_ = x11::None;
// Number of buttons we support. // Number of buttons we support.
// Left, Right, Middle, VScroll Up/Down, HScroll Left/Right, back, forward. // Left, Right, Middle, VScroll Up/Down, HScroll Left/Right, back, forward.
@@ -243,12 +242,6 @@ bool InputInjectorX11::Core::Init() {
task_runner_->PostTask(FROM_HERE, task_runner_->PostTask(FROM_HERE,
base::BindOnce(&Core::InitClipboard, this)); base::BindOnce(&Core::InitClipboard, this));
root_window_ = XDefaultRootWindow(display_);
if (!root_window_) {
LOG(ERROR) << "Unable to get the root window";
return false;
}
if (!IgnoreXServerGrabs(&connection_, true)) { if (!IgnoreXServerGrabs(&connection_, true)) {
LOG(ERROR) << "Server does not support XTest."; LOG(ERROR) << "Server does not support XTest.";
return false; return false;
@@ -393,7 +386,7 @@ bool InputInjectorX11::Core::IsLockKey(KeyCode keycode) {
auto mods = state->baseMods | state->latchedMods | state->lockedMods; auto mods = state->baseMods | state->latchedMods | state->lockedMods;
KeySym keysym; KeySym keysym;
if (state && XkbLookupKeySym(display_, keycode, static_cast<unsigned>(mods), if (state && XkbLookupKeySym(display_, keycode, static_cast<unsigned>(mods),
nullptr, &keysym) == x11::True) { nullptr, &keysym)) {
return keysym == XK_Caps_Lock || keysym == XK_Num_Lock; return keysym == XK_Caps_Lock || keysym == XK_Num_Lock;
} else { } else {
return false; return false;

@@ -4,7 +4,11 @@
#include "remoting/host/linux/x_server_clipboard.h" #include "remoting/host/linux/x_server_clipboard.h"
#include <limits>
#include "base/callback.h" #include "base/callback.h"
#include "base/memory/ref_counted_memory.h"
#include "base/memory/scoped_refptr.h"
#include "base/stl_util.h" #include "base/stl_util.h"
#include "remoting/base/constants.h" #include "remoting/base/constants.h"
#include "remoting/base/logging.h" #include "remoting/base/logging.h"
@@ -16,15 +20,7 @@
namespace remoting { namespace remoting {
XServerClipboard::XServerClipboard() XServerClipboard::XServerClipboard() = default;
: clipboard_window_(x11::None),
clipboard_atom_(x11::None),
large_selection_atom_(x11::None),
selection_string_atom_(x11::None),
targets_atom_(x11::None),
timestamp_atom_(x11::None),
utf8_string_atom_(x11::None),
large_selection_property_(x11::None) {}
XServerClipboard::~XServerClipboard() = default; XServerClipboard::~XServerClipboard() = default;
@@ -51,11 +47,14 @@ void XServerClipboard::Init(x11::Connection* connection,
connection_->xfixes().QueryVersion( connection_->xfixes().QueryVersion(
{x11::XFixes::major_version, x11::XFixes::minor_version}); {x11::XFixes::major_version, x11::XFixes::minor_version});
clipboard_window_ = clipboard_window_ = connection_->GenerateId<x11::Window>();
XCreateSimpleWindow(connection_->display(), connection_->CreateWindow({
XDefaultRootWindow(connection_->display()), 0, 0, 1, .wid = clipboard_window_,
1, // x, y, width, height .parent = connection_->default_root(),
0, 0, 0); .width = 1,
.height = 1,
.override_redirect = x11::Bool32(true),
});
// TODO(lambroslambrou): Use ui::X11AtomCache for this, either by adding a // TODO(lambroslambrou): Use ui::X11AtomCache for this, either by adding a
// dependency on ui/ or by moving X11AtomCache to base/. // dependency on ui/ or by moving X11AtomCache to base/.
@@ -64,19 +63,27 @@ void XServerClipboard::Init(x11::Connection* connection,
"TIMESTAMP", "UTF8_STRING"}; "TIMESTAMP", "UTF8_STRING"};
static const int kNumAtomNames = base::size(kAtomNames); static const int kNumAtomNames = base::size(kAtomNames);
Atom atoms[kNumAtomNames]; x11::Future<x11::InternAtomReply> futures[kNumAtomNames];
if (XInternAtoms(connection_->display(), const_cast<char**>(kAtomNames), for (size_t i = 0; i < kNumAtomNames; i++)
kNumAtomNames, x11::False, atoms)) { futures[i] = connection_->InternAtom({false, kAtomNames[i]});
clipboard_atom_ = atoms[0]; connection_->Flush();
large_selection_atom_ = atoms[1]; x11::Atom atoms[kNumAtomNames];
selection_string_atom_ = atoms[2]; memset(atoms, 0, sizeof(atoms));
targets_atom_ = atoms[3]; for (size_t i = 0; i < kNumAtomNames; i++) {
timestamp_atom_ = atoms[4]; if (auto reply = futures[i].Sync()) {
utf8_string_atom_ = atoms[5]; atoms[i] = reply->atom;
static_assert(kNumAtomNames >= 6, "kAtomNames is too small"); } else {
} else { LOG(ERROR) << "Failed to intern atom(s)";
LOG(ERROR) << "XInternAtoms failed"; break;
}
} }
clipboard_atom_ = atoms[0];
large_selection_atom_ = atoms[1];
selection_string_atom_ = atoms[2];
targets_atom_ = atoms[3];
timestamp_atom_ = atoms[4];
utf8_string_atom_ = atoms[5];
static_assert(kNumAtomNames >= 6, "kAtomNames is too small");
connection_->xfixes().SelectSelectionInput( connection_->xfixes().SelectSelectionInput(
{static_cast<x11::Window>(clipboard_window_), {static_cast<x11::Window>(clipboard_window_),
@@ -89,7 +96,7 @@ void XServerClipboard::SetClipboard(const std::string& mime_type,
const std::string& data) { const std::string& data) {
DCHECK(connection_->display()); DCHECK(connection_->display());
if (clipboard_window_ == x11::None) if (clipboard_window_ == x11::Window::None)
return; return;
// Currently only UTF-8 is supported. // Currently only UTF-8 is supported.
@@ -102,13 +109,13 @@ void XServerClipboard::SetClipboard(const std::string& mime_type,
data_ = data; data_ = data;
AssertSelectionOwnership(static_cast<uint32_t>(x11::Atom::PRIMARY)); AssertSelectionOwnership(x11::Atom::PRIMARY);
AssertSelectionOwnership(clipboard_atom_); AssertSelectionOwnership(clipboard_atom_);
} }
void XServerClipboard::ProcessXEvent(const x11::Event& event) { void XServerClipboard::ProcessXEvent(const x11::Event& event) {
if (clipboard_window_ == x11::None || if (clipboard_window_ == x11::Window::None ||
event.window() != static_cast<x11::Window>(clipboard_window_)) { event.window() != clipboard_window_) {
return; return;
} }
@@ -123,14 +130,13 @@ void XServerClipboard::ProcessXEvent(const x11::Event& event) {
if (auto* xfixes_selection_notify = if (auto* xfixes_selection_notify =
event.As<x11::XFixes::SelectionNotifyEvent>()) { event.As<x11::XFixes::SelectionNotifyEvent>()) {
OnSetSelectionOwnerNotify( OnSetSelectionOwnerNotify(xfixes_selection_notify->selection,
static_cast<uint32_t>(xfixes_selection_notify->selection), xfixes_selection_notify->selection_timestamp);
static_cast<uint32_t>(xfixes_selection_notify->selection_timestamp));
} }
} }
void XServerClipboard::OnSetSelectionOwnerNotify(Atom selection, void XServerClipboard::OnSetSelectionOwnerNotify(x11::Atom selection,
Time timestamp) { x11::Time timestamp) {
// Protect against receiving new XFixes selection notifications whilst we're // Protect against receiving new XFixes selection notifications whilst we're
// in the middle of waiting for information from the current selection owner. // in the middle of waiting for information from the current selection owner.
// A reasonable timeout allows for misbehaving apps that don't respond // A reasonable timeout allows for misbehaving apps that don't respond
@@ -160,25 +166,25 @@ void XServerClipboard::OnSetSelectionOwnerNotify(Atom selection,
} }
void XServerClipboard::OnPropertyNotify(const x11::PropertyNotifyEvent& event) { void XServerClipboard::OnPropertyNotify(const x11::PropertyNotifyEvent& event) {
if (large_selection_property_ != x11::None && if (large_selection_property_ != x11::Atom::None &&
event.atom == static_cast<x11::Atom>(large_selection_property_) && event.atom == large_selection_property_ &&
event.state == x11::Property::NewValue) { event.state == x11::Property::NewValue) {
Atom type; auto req = connection_->GetProperty({
int format; .c_delete = true,
unsigned long item_count, after; .window = clipboard_window_,
unsigned char* data; .property = large_selection_property_,
XGetWindowProperty(connection_->display(), clipboard_window_, .type = x11::Atom::Any,
large_selection_property_, 0, ~0L, x11::True, .long_length = std::numeric_limits<uint32_t>::max(),
AnyPropertyType, &type, &format, &item_count, &after, });
&data); if (auto reply = req.Sync()) {
if (type != x11::None) { if (reply->type != x11::Atom::None) {
// TODO(lambroslambrou): Properly support large transfers - // TODO(lambroslambrou): Properly support large transfers -
// http://crbug.com/151447. // http://crbug.com/151447.
XFree(data);
// If the property is zero-length then the large transfer is complete. // If the property is zero-length then the large transfer is complete.
if (item_count == 0) if (reply->value_len == 0)
large_selection_property_ = x11::None; large_selection_property_ = x11::Atom::None;
}
} }
} }
} }
@@ -186,28 +192,29 @@ void XServerClipboard::OnPropertyNotify(const x11::PropertyNotifyEvent& event) {
void XServerClipboard::OnSelectionNotify( void XServerClipboard::OnSelectionNotify(
const x11::SelectionNotifyEvent& event) { const x11::SelectionNotifyEvent& event) {
if (event.property != x11::Atom::None) { if (event.property != x11::Atom::None) {
Atom type; auto req = connection_->GetProperty({
int format; .c_delete = true,
unsigned long item_count, after; .window = clipboard_window_,
unsigned char* data; .property = event.property,
XGetWindowProperty(connection_->display(), clipboard_window_, .type = x11::Atom::Any,
static_cast<uint32_t>(event.property), 0, ~0L, x11::True, .long_length = std::numeric_limits<uint32_t>::max(),
AnyPropertyType, &type, &format, &item_count, &after, });
&data); if (auto reply = req.Sync()) {
if (type == large_selection_atom_) { if (reply->type == large_selection_atom_) {
// Large selection - just read and ignore these for now. // Large selection - just read and ignore these for now.
large_selection_property_ = static_cast<uint32_t>(event.property); large_selection_property_ = event.property;
} else { } else {
// Standard selection - call the selection notifier. // Standard selection - call the selection notifier.
large_selection_property_ = x11::None; large_selection_property_ = x11::Atom::None;
if (type != x11::None) { if (reply->type != x11::Atom::None) {
HandleSelectionNotify(event, type, format, item_count, data); HandleSelectionNotify(event, reply->type, reply->format,
XFree(data); reply->value_len, reply->value->data());
return; return;
}
} }
} }
} }
HandleSelectionNotify(event, 0, 0, 0, nullptr); HandleSelectionNotify(event, x11::Atom::None, 0, 0, nullptr);
} }
void XServerClipboard::OnSelectionRequest( void XServerClipboard::OnSelectionRequest(
@@ -219,23 +226,21 @@ void XServerClipboard::OnSelectionRequest(
selection_event.target = event.target; selection_event.target = event.target;
auto property = auto property =
event.property == x11::Atom::None ? event.target : event.property; event.property == x11::Atom::None ? event.target : event.property;
if (!IsSelectionOwner(static_cast<uint32_t>(selection_event.selection))) { if (!IsSelectionOwner(selection_event.selection)) {
selection_event.property = x11::Atom::None; selection_event.property = x11::Atom::None;
} else { } else {
selection_event.property = property; selection_event.property = property;
if (selection_event.target == static_cast<x11::Atom>(targets_atom_)) { if (selection_event.target == static_cast<x11::Atom>(targets_atom_)) {
SendTargetsResponse(static_cast<uint32_t>(selection_event.requestor), SendTargetsResponse(selection_event.requestor, selection_event.property);
static_cast<uint32_t>(selection_event.property));
} else if (selection_event.target == } else if (selection_event.target ==
static_cast<x11::Atom>(timestamp_atom_)) { static_cast<x11::Atom>(timestamp_atom_)) {
SendTimestampResponse(static_cast<uint32_t>(selection_event.requestor), SendTimestampResponse(selection_event.requestor,
static_cast<uint32_t>(selection_event.property)); selection_event.property);
} else if (selection_event.target == } else if (selection_event.target ==
static_cast<x11::Atom>(utf8_string_atom_) || static_cast<x11::Atom>(utf8_string_atom_) ||
selection_event.target == x11::Atom::STRING) { selection_event.target == x11::Atom::STRING) {
SendStringResponse(static_cast<uint32_t>(selection_event.requestor), SendStringResponse(selection_event.requestor, selection_event.property,
static_cast<uint32_t>(selection_event.property), selection_event.target);
static_cast<uint32_t>(selection_event.target));
} }
} }
x11::SendEvent(selection_event, selection_event.requestor, x11::SendEvent(selection_event, selection_event.requestor,
@@ -243,22 +248,33 @@ void XServerClipboard::OnSelectionRequest(
} }
void XServerClipboard::OnSelectionClear(const x11::SelectionClearEvent& event) { void XServerClipboard::OnSelectionClear(const x11::SelectionClearEvent& event) {
selections_owned_.erase(static_cast<uint32_t>(event.selection)); selections_owned_.erase(event.selection);
} }
void XServerClipboard::SendTargetsResponse(Window requestor, Atom property) { void XServerClipboard::SendTargetsResponse(x11::Window requestor,
x11::Atom property) {
// Respond advertising x11::Atom::STRING, UTF8_STRING and TIMESTAMP data for // Respond advertising x11::Atom::STRING, UTF8_STRING and TIMESTAMP data for
// the selection. // the selection.
Atom targets[3]; x11::Atom targets[3] = {
targets[0] = timestamp_atom_; timestamp_atom_,
targets[1] = utf8_string_atom_; utf8_string_atom_,
targets[2] = static_cast<uint32_t>(x11::Atom::STRING); x11::Atom::STRING,
XChangeProperty(connection_->display(), requestor, property, };
static_cast<uint32_t>(x11::Atom::ATOM), 32, PropModeReplace, connection_->ChangeProperty({
reinterpret_cast<unsigned char*>(targets), 3); .mode = x11::PropMode::Replace,
.window = requestor,
.property = property,
.type = x11::Atom::ATOM,
.format = CHAR_BIT * sizeof(x11::Atom),
.data_len = base::size(targets),
.data = base::MakeRefCounted<base::RefCountedStaticMemory>(
&targets[0], sizeof(targets)),
});
connection_->Flush();
} }
void XServerClipboard::SendTimestampResponse(Window requestor, Atom property) { void XServerClipboard::SendTimestampResponse(x11::Window requestor,
x11::Atom property) {
// Respond with the timestamp of our selection; we always return // Respond with the timestamp of our selection; we always return
// CurrentTime since our selections are set by remote clients, so there // CurrentTime since our selections are set by remote clients, so there
// is no associated local X event. // is no associated local X event.
@@ -266,40 +282,53 @@ void XServerClipboard::SendTimestampResponse(Window requestor, Atom property) {
// TODO(lambroslambrou): Should use a proper timestamp here instead of // TODO(lambroslambrou): Should use a proper timestamp here instead of
// CurrentTime. ICCCM recommends doing a zero-length property append, // CurrentTime. ICCCM recommends doing a zero-length property append,
// and getting a timestamp from the subsequent PropertyNotify event. // and getting a timestamp from the subsequent PropertyNotify event.
Time time = x11::CurrentTime; x11::Time time = x11::Time::CurrentTime;
XChangeProperty(connection_->display(), requestor, property, connection_->ChangeProperty({
static_cast<uint32_t>(x11::Atom::INTEGER), 32, .mode = x11::PropMode::Replace,
PropModeReplace, reinterpret_cast<unsigned char*>(&time), 1); .window = requestor,
.property = property,
.type = x11::Atom::INTEGER,
.format = CHAR_BIT * sizeof(x11::Time),
.data_len = 1,
.data = base::MakeRefCounted<base::RefCountedStaticMemory>(&time,
sizeof(time)),
});
connection_->Flush();
} }
void XServerClipboard::SendStringResponse(Window requestor, void XServerClipboard::SendStringResponse(x11::Window requestor,
Atom property, x11::Atom property,
Atom target) { x11::Atom target) {
if (!data_.empty()) { if (!data_.empty()) {
// Return the actual string data; we always return UTF8, regardless of // Return the actual string data; we always return UTF8, regardless of
// the configured locale. // the configured locale.
XChangeProperty( connection_->ChangeProperty({
connection_->display(), requestor, property, target, 8, PropModeReplace, .mode = x11::PropMode::Replace,
reinterpret_cast<unsigned char*>(const_cast<char*>(data_.data())), .window = requestor,
data_.size()); .property = property,
.type = target,
.format = 8,
.data_len = data_.size(),
.data = base::MakeRefCounted<base::RefCountedStaticMemory>(
data_.data(), data_.size()),
});
connection_->Flush();
} }
} }
void XServerClipboard::HandleSelectionNotify( void XServerClipboard::HandleSelectionNotify(
const x11::SelectionNotifyEvent& event, const x11::SelectionNotifyEvent& event,
Atom type, x11::Atom type,
int format, int format,
int item_count, int item_count,
void* data) { const void* data) {
bool finished = false; bool finished = false;
auto target = static_cast<uint32_t>(event.target); auto target = event.target;
if (target == targets_atom_) { if (target == targets_atom_)
finished = HandleSelectionTargetsEvent(event, format, item_count, data); finished = HandleSelectionTargetsEvent(event, format, item_count, data);
} else if (target == utf8_string_atom_ || else if (target == utf8_string_atom_ || target == x11::Atom::STRING)
target == static_cast<uint32_t>(x11::Atom::STRING)) {
finished = HandleSelectionStringEvent(event, format, item_count, data); finished = HandleSelectionStringEvent(event, format, item_count, data);
}
if (finished) if (finished)
get_selections_time_ = base::TimeTicks(); get_selections_time_ = base::TimeTicks();
@@ -309,9 +338,9 @@ bool XServerClipboard::HandleSelectionTargetsEvent(
const x11::SelectionNotifyEvent& event, const x11::SelectionNotifyEvent& event,
int format, int format,
int item_count, int item_count,
void* data) { const void* data) {
auto selection = static_cast<uint32_t>(event.selection); auto selection = event.selection;
if (event.property == static_cast<x11::Atom>(targets_atom_)) { if (event.property == targets_atom_) {
if (data && format == 32) { if (data && format == 32) {
// The XGetWindowProperty man-page specifies that the returned // The XGetWindowProperty man-page specifies that the returned
// property data will be an array of |long|s in the case where // property data will be an array of |long|s in the case where
@@ -328,7 +357,7 @@ bool XServerClipboard::HandleSelectionTargetsEvent(
} }
} }
} }
RequestSelectionString(selection, static_cast<uint32_t>(x11::Atom::STRING)); RequestSelectionString(selection, x11::Atom::STRING);
return false; return false;
} }
@@ -336,17 +365,16 @@ bool XServerClipboard::HandleSelectionStringEvent(
const x11::SelectionNotifyEvent& event, const x11::SelectionNotifyEvent& event,
int format, int format,
int item_count, int item_count,
void* data) { const void* data) {
auto property = static_cast<uint32_t>(event.property); auto property = event.property;
auto target = static_cast<uint32_t>(event.target); auto target = event.target;
if (property != selection_string_atom_ || !data || format != 8) if (property != selection_string_atom_ || !data || format != 8)
return true; return true;
std::string text(static_cast<char*>(data), item_count); std::string text(static_cast<const char*>(data), item_count);
if (target == static_cast<uint32_t>(x11::Atom::STRING) || if (target == x11::Atom::STRING || target == utf8_string_atom_)
target == utf8_string_atom_)
NotifyClipboardText(text); NotifyClipboardText(text);
return true; return true;
@@ -357,29 +385,33 @@ void XServerClipboard::NotifyClipboardText(const std::string& text) {
callback_.Run(kMimeTypeTextUtf8, data_); callback_.Run(kMimeTypeTextUtf8, data_);
} }
void XServerClipboard::RequestSelectionTargets(Atom selection) { void XServerClipboard::RequestSelectionTargets(x11::Atom selection) {
XConvertSelection(connection_->display(), selection, targets_atom_, connection_->ConvertSelection({clipboard_window_, selection, targets_atom_,
targets_atom_, clipboard_window_, x11::CurrentTime); selection_string_atom_,
x11::Time::CurrentTime});
} }
void XServerClipboard::RequestSelectionString(Atom selection, Atom target) { void XServerClipboard::RequestSelectionString(x11::Atom selection,
XConvertSelection(connection_->display(), selection, target, x11::Atom target) {
selection_string_atom_, clipboard_window_, connection_->ConvertSelection({clipboard_window_, selection, target,
x11::CurrentTime); selection_string_atom_,
x11::Time::CurrentTime});
} }
void XServerClipboard::AssertSelectionOwnership(Atom selection) { void XServerClipboard::AssertSelectionOwnership(x11::Atom selection) {
XSetSelectionOwner(connection_->display(), selection, clipboard_window_, connection_->SetSelectionOwner(
x11::CurrentTime); {clipboard_window_, selection, x11::Time::CurrentTime});
if (XGetSelectionOwner(connection_->display(), selection) == auto reply = connection_->GetSelectionOwner({selection}).Sync();
clipboard_window_) { auto owner = reply ? reply->owner : x11::Window::None;
if (owner == clipboard_window_) {
selections_owned_.insert(selection); selections_owned_.insert(selection);
} else { } else {
LOG(ERROR) << "XSetSelectionOwner failed for selection " << selection; LOG(ERROR) << "XSetSelectionOwner failed for selection "
<< static_cast<uint32_t>(selection);
} }
} }
bool XServerClipboard::IsSelectionOwner(Atom selection) { bool XServerClipboard::IsSelectionOwner(x11::Atom selection) {
return selections_owned_.find(selection) != selections_owned_.end(); return selections_owned_.find(selection) != selections_owned_.end();
} }

@@ -53,7 +53,7 @@ class XServerClipboard {
private: private:
// Handlers called by ProcessXEvent() for each event type. // Handlers called by ProcessXEvent() for each event type.
void OnSetSelectionOwnerNotify(Atom selection, Time timestamp); void OnSetSelectionOwnerNotify(x11::Atom selection, x11::Time timestamp);
void OnPropertyNotify(const x11::PropertyNotifyEvent& event); void OnPropertyNotify(const x11::PropertyNotifyEvent& event);
void OnSelectionNotify(const x11::SelectionNotifyEvent& event); void OnSelectionNotify(const x11::SelectionNotifyEvent& event);
void OnSelectionRequest(const x11::SelectionRequestEvent& event); void OnSelectionRequest(const x11::SelectionRequestEvent& event);
@@ -63,9 +63,11 @@ class XServerClipboard {
// clipboard content. This is done by changing the property |property| of the // clipboard content. This is done by changing the property |property| of the
// |requestor| window (these values come from the XSelectionRequestEvent). // |requestor| window (these values come from the XSelectionRequestEvent).
// |target| must be a string type (STRING or UTF8_STRING). // |target| must be a string type (STRING or UTF8_STRING).
void SendTargetsResponse(Window requestor, Atom property); void SendTargetsResponse(x11::Window requestor, x11::Atom property);
void SendTimestampResponse(Window requestor, Atom property); void SendTimestampResponse(x11::Window requestor, x11::Atom property);
void SendStringResponse(Window requestor, Atom property, Atom target); void SendStringResponse(x11::Window requestor,
x11::Atom property,
x11::Atom target);
// Called by OnSelectionNotify() when the selection owner has replied to a // Called by OnSelectionNotify() when the selection owner has replied to a
// request for information about a selection. // request for information about a selection.
@@ -73,10 +75,10 @@ class XServerClipboard {
// |type|, |format| etc are the results from XGetWindowProperty(), or 0 if // |type|, |format| etc are the results from XGetWindowProperty(), or 0 if
// there is no associated data. // there is no associated data.
void HandleSelectionNotify(const x11::SelectionNotifyEvent& event, void HandleSelectionNotify(const x11::SelectionNotifyEvent& event,
Atom type, x11::Atom type,
int format, int format,
int item_count, int item_count,
void* data); const void* data);
// These methods return true if selection processing is complete, false // These methods return true if selection processing is complete, false
// otherwise. They are called from HandleSelectionNotify(), and take the same // otherwise. They are called from HandleSelectionNotify(), and take the same
@@ -84,42 +86,42 @@ class XServerClipboard {
bool HandleSelectionTargetsEvent(const x11::SelectionNotifyEvent& event, bool HandleSelectionTargetsEvent(const x11::SelectionNotifyEvent& event,
int format, int format,
int item_count, int item_count,
void* data); const void* data);
bool HandleSelectionStringEvent(const x11::SelectionNotifyEvent& event, bool HandleSelectionStringEvent(const x11::SelectionNotifyEvent& event,
int format, int format,
int item_count, int item_count,
void* data); const void* data);
// Notify the registered callback of new clipboard text. // Notify the registered callback of new clipboard text.
void NotifyClipboardText(const std::string& text); void NotifyClipboardText(const std::string& text);
// These methods trigger the X server or selection owner to send back an // These methods trigger the X server or selection owner to send back an
// event containing the requested information. // event containing the requested information.
void RequestSelectionTargets(Atom selection); void RequestSelectionTargets(x11::Atom selection);
void RequestSelectionString(Atom selection, Atom target); void RequestSelectionString(x11::Atom selection, x11::Atom target);
// Assert ownership of the specified |selection|. // Assert ownership of the specified |selection|.
void AssertSelectionOwnership(Atom selection); void AssertSelectionOwnership(x11::Atom selection);
bool IsSelectionOwner(Atom selection); bool IsSelectionOwner(x11::Atom selection);
// Stores the connection supplied to Init(). // Stores the connection supplied to Init().
x11::Connection* connection_ = nullptr; x11::Connection* connection_ = nullptr;
// Window through which clipboard events are received, or BadValue if the // Window through which clipboard events are received, or BadValue if the
// window could not be created. // window could not be created.
Window clipboard_window_; x11::Window clipboard_window_ = x11::Window::None;
// Cached atoms for various strings, initialized during Init(). // Cached atoms for various strings, initialized during Init().
Atom clipboard_atom_; x11::Atom clipboard_atom_ = x11::Atom::None;
Atom large_selection_atom_; x11::Atom large_selection_atom_ = x11::Atom::None;
Atom selection_string_atom_; x11::Atom selection_string_atom_ = x11::Atom::None;
Atom targets_atom_; x11::Atom targets_atom_ = x11::Atom::None;
Atom timestamp_atom_; x11::Atom timestamp_atom_ = x11::Atom::None;
Atom utf8_string_atom_; x11::Atom utf8_string_atom_ = x11::Atom::None;
// The set of X selections owned by |clipboard_window_| (can be Primary or // The set of X selections owned by |clipboard_window_| (can be Primary or
// Clipboard or both). // Clipboard or both).
std::set<Atom> selections_owned_; std::set<x11::Atom> selections_owned_;
// Clipboard content to return to other applications when |clipboard_window_| // Clipboard content to return to other applications when |clipboard_window_|
// owns a selection. // owns a selection.
@@ -127,7 +129,7 @@ class XServerClipboard {
// Stores the property to use for large transfers, or None if a large // Stores the property to use for large transfers, or None if a large
// transfer is not currently in-progress. // transfer is not currently in-progress.
Atom large_selection_property_; x11::Atom large_selection_property_ = x11::Atom::None;
// Remembers the start time of selection processing, and is set to null when // Remembers the start time of selection processing, and is set to null when
// processing is complete. This is used to decide whether to begin processing // processing is complete. This is used to decide whether to begin processing

@@ -672,7 +672,7 @@ void XDragDropClient::SendXdndLeave(x11::Window dest_window) {
void XDragDropClient::SendXdndDrop(x11::Window dest_window) { void XDragDropClient::SendXdndDrop(x11::Window dest_window) {
auto xev = PrepareXdndClientMessage(kXdndDrop, dest_window); auto xev = PrepareXdndClientMessage(kXdndDrop, dest_window);
xev.data.data32[2] = x11::CurrentTime; xev.data.data32[2] = static_cast<uint32_t>(x11::Time::CurrentTime);
SendXClientEvent(dest_window, xev); SendXClientEvent(dest_window, xev);
} }

@@ -28,7 +28,7 @@ TestCompositorHostX11::~TestCompositorHostX11() = default;
void TestCompositorHostX11::Show() { void TestCompositorHostX11::Show() {
XDisplay* display = gfx::GetXDisplay(); XDisplay* display = gfx::GetXDisplay();
XSetWindowAttributes swa; XSetWindowAttributes swa;
swa.override_redirect = x11::True; swa.override_redirect = true;
window_ = static_cast<x11::Window>(XCreateWindow( window_ = static_cast<x11::Window>(XCreateWindow(
display, XDefaultRootWindow(display), // parent display, XDefaultRootWindow(display), // parent
bounds_.x(), bounds_.y(), bounds_.width(), bounds_.height(), bounds_.x(), bounds_.y(), bounds_.width(), bounds_.height(),
@@ -42,7 +42,7 @@ void TestCompositorHostX11::Show() {
XMapWindow(display, static_cast<uint32_t>(window_)); XMapWindow(display, static_cast<uint32_t>(window_));
// Since this window is override-redirect, syncing is sufficient // Since this window is override-redirect, syncing is sufficient
// to ensure the map is complete. // to ensure the map is complete.
XSync(display, x11::False); XSync(display, false);
allocator_.GenerateId(); allocator_.GenerateId();
compositor_.SetAcceleratedWidget( compositor_.SetAcceleratedWidget(
static_cast<gfx::AcceleratedWidget>(window_)); static_cast<gfx::AcceleratedWidget>(window_));

@@ -114,7 +114,7 @@ void KeyboardHookX11::CaptureKeyForDomCode(DomCode dom_code) {
// error handler for debugging purposes but are not used to judge success. // error handler for debugging purposes but are not used to judge success.
XGrabKey(x_display_, native_key_code, modifier, XGrabKey(x_display_, native_key_code, modifier,
static_cast<uint32_t>(x_window_), static_cast<uint32_t>(x_window_),
/*owner_events=*/x11::False, /*owner_events=*/false,
/*pointer_mode=*/GrabModeAsync, /*pointer_mode=*/GrabModeAsync,
/*keyboard_mode=*/GrabModeAsync); /*keyboard_mode=*/GrabModeAsync);
} }

@@ -376,13 +376,4 @@ inline int XkbBuildCoreState(int m, int g) {
return ((g & 0x3) << 13) | (m & 0xff); return ((g & 0x3) << 13) | (m & 0xff);
} }
// Deprecated.
namespace x11 {
static constexpr unsigned long None = 0L;
static constexpr long CurrentTime = 0L;
static constexpr int False = 0;
static constexpr int True = 1;
static constexpr int Success = 0;
} // namespace x11
#endif // UI_GFX_X_X11_H_ #endif // UI_GFX_X_X11_H_

@@ -22,7 +22,7 @@ int X11ErrorHandler(Display* display, XErrorEvent* error) {
namespace gfx { namespace gfx {
X11ErrorTracker::X11ErrorTracker() { X11ErrorTracker::X11ErrorTracker() {
XSync(GetXDisplay(), x11::False); XSync(GetXDisplay(), false);
old_handler_ = reinterpret_cast<void*>(XSetErrorHandler(X11ErrorHandler)); old_handler_ = reinterpret_cast<void*>(XSetErrorHandler(X11ErrorHandler));
g_x11_error_code = 0; g_x11_error_code = 0;
} }
@@ -32,7 +32,7 @@ X11ErrorTracker::~X11ErrorTracker() {
} }
bool X11ErrorTracker::FoundNewError() { bool X11ErrorTracker::FoundNewError() {
XSync(GetXDisplay(), x11::False); XSync(GetXDisplay(), false);
unsigned char error = g_x11_error_code; unsigned char error = g_x11_error_code;
g_x11_error_code = 0; g_x11_error_code = 0;
return error != 0; return error != 0;

@@ -57,10 +57,10 @@ GLXContext CreateContextAttribs(Display* display,
// errors can be generated. To prevent these errors from crashing our process, // errors can be generated. To prevent these errors from crashing our process,
// we simply ignore them and only look if the GLXContext was created. // we simply ignore them and only look if the GLXContext was created.
// Sync to ensure any errors generated are processed. // Sync to ensure any errors generated are processed.
XSync(display, x11::False); XSync(display, false);
auto old_error_handler = XSetErrorHandler(IgnoreX11Errors); auto old_error_handler = XSetErrorHandler(IgnoreX11Errors);
GLXContext context = glXCreateContextAttribsARB(display, config, share, GLXContext context =
x11::True, attribs.data()); glXCreateContextAttribsARB(display, config, share, true, attribs.data());
XSetErrorHandler(old_error_handler); XSetErrorHandler(old_error_handler);
return context; return context;
@@ -182,7 +182,7 @@ bool GLContextGLX::Initialize(GLSurface* compatible_surface,
DVLOG(1) << "GLX_ARB_create_context not supported."; DVLOG(1) << "GLX_ARB_create_context not supported.";
context_ = glXCreateNewContext( context_ = glXCreateNewContext(
display_, static_cast<GLXFBConfig>(compatible_surface->GetConfig()), display_, static_cast<GLXFBConfig>(compatible_surface->GetConfig()),
GLX_RGBA_TYPE, share_handle, x11::True); GLX_RGBA_TYPE, share_handle, true);
if (!context_) { if (!context_) {
LOG(ERROR) << "Failed to create GL context with glXCreateNewContext."; LOG(ERROR) << "Failed to create GL context with glXCreateNewContext.";
return false; return false;

@@ -34,7 +34,7 @@ TEST(GLContextGLXTest, MAYBE_DoNotDestroyOnFailedMakeCurrent) {
XSetWindowAttributes swa; XSetWindowAttributes swa;
memset(&swa, 0, sizeof(swa)); memset(&swa, 0, sizeof(swa));
swa.background_pixmap = 0; swa.background_pixmap = 0;
swa.override_redirect = x11::True; swa.override_redirect = true;
auto xwindow = static_cast<x11::Window>(XCreateWindow( auto xwindow = static_cast<x11::Window>(XCreateWindow(
xdisplay, XDefaultRootWindow(xdisplay), 0, 0, 10, xdisplay, XDefaultRootWindow(xdisplay), 0, 0, 10,
10, // x, y, width, height 10, // x, y, width, height
@@ -47,7 +47,7 @@ TEST(GLContextGLXTest, MAYBE_DoNotDestroyOnFailedMakeCurrent) {
XMapWindow(xdisplay, static_cast<uint32_t>(xwindow)); XMapWindow(xdisplay, static_cast<uint32_t>(xwindow));
// Since this window is override-redirect, syncing is sufficient // Since this window is override-redirect, syncing is sufficient
// to ensure the map is complete. // to ensure the map is complete.
XSync(xdisplay, x11::False); XSync(xdisplay, false);
GLImageTestSupport::InitializeGL(base::nullopt); GLImageTestSupport::InitializeGL(base::nullopt);
auto surface = gl::InitializeGLSurface(base::MakeRefCounted<GLSurfaceGLXX11>( auto surface = gl::InitializeGLSurface(base::MakeRefCounted<GLSurfaceGLXX11>(
@@ -64,7 +64,7 @@ TEST(GLContextGLXTest, MAYBE_DoNotDestroyOnFailedMakeCurrent) {
XDestroyWindow(xdisplay, static_cast<uint32_t>(xwindow)); XDestroyWindow(xdisplay, static_cast<uint32_t>(xwindow));
// Since this window is override-redirect, syncing is sufficient // Since this window is override-redirect, syncing is sufficient
// to ensure the window is destroyed and unmapped. // to ensure the window is destroyed and unmapped.
XSync(xdisplay, x11::False); XSync(xdisplay, false);
ASSERT_FALSE(error_tracker.FoundNewError()); ASSERT_FALSE(error_tracker.FoundNewError());
if (context->MakeCurrent(surface.get())) { if (context->MakeCurrent(surface.get())) {
@@ -83,7 +83,7 @@ TEST(GLContextGLXTest, MAYBE_DoNotDestroyOnFailedMakeCurrent) {
// not destroyed. // not destroyed.
ASSERT_TRUE(context->GetHandle()); ASSERT_TRUE(context->GetHandle());
surface = nullptr; surface = nullptr;
XSync(xdisplay, x11::True); XSync(xdisplay, true);
} }
} // namespace gl } // namespace gl

@@ -281,7 +281,7 @@ class SGIVideoSyncThread : public base::Thread,
DCHECK(task_runner()->BelongsToCurrentThread()); DCHECK(task_runner()->BelongsToCurrentThread());
if (!context_) { if (!context_) {
context_ = glXCreateNewContext(GetDisplay(), config, GLX_RGBA_TYPE, context_ = glXCreateNewContext(GetDisplay(), config, GLX_RGBA_TYPE,
nullptr, x11::True); nullptr, true);
} }
LOG_IF(ERROR, !context_) << "video_sync: glXCreateNewContext failed"; LOG_IF(ERROR, !context_) << "video_sync: glXCreateNewContext failed";
} }
@@ -337,7 +337,7 @@ class SGIVideoSyncProviderThreadShim {
vsync_lock_() { vsync_lock_() {
// This ensures that creation of |parent_window_| has occured when this shim // This ensures that creation of |parent_window_| has occured when this shim
// is executing in the same thread as the call to create |parent_window_|. // is executing in the same thread as the call to create |parent_window_|.
XSync(gfx::GetXDisplay(), x11::False); XSync(gfx::GetXDisplay(), false);
} }
~SGIVideoSyncProviderThreadShim() { ~SGIVideoSyncProviderThreadShim() {

@@ -202,11 +202,11 @@ class X11WindowTest : public testing::Test {
// Make X11 synchronous for our display connection. This does not force the // Make X11 synchronous for our display connection. This does not force the
// window manager to behave synchronously. // window manager to behave synchronously.
XSynchronize(gfx::GetXDisplay(), x11::True); XSynchronize(gfx::GetXDisplay(), true);
} }
protected: protected:
void TearDown() override { XSynchronize(gfx::GetXDisplay(), x11::False); } void TearDown() override { XSynchronize(gfx::GetXDisplay(), false); }
std::unique_ptr<X11Window> CreateX11Window( std::unique_ptr<X11Window> CreateX11Window(
PlatformWindowDelegate* delegate, PlatformWindowDelegate* delegate,

@@ -69,23 +69,18 @@ void DispatchMouseMotionEvent(DesktopWindowTreeHostLinux* desktop_host,
gfx::Rect bounds_in_screen = desktop_host->window()->GetBoundsInScreen(); gfx::Rect bounds_in_screen = desktop_host->window()->GetBoundsInScreen();
auto* connection = x11::Connection::Get(); auto* connection = x11::Connection::Get();
xcb_generic_event_t ge; x11::MotionNotifyEvent xev{
memset(&ge, 0, sizeof(ge)); .detail = x11::Motion::Normal,
auto* xev = reinterpret_cast<xcb_motion_notify_event_t*>(&ge); .root = connection->default_root(),
xev->response_type = x11::MotionNotifyEvent::opcode; .event = static_cast<x11::Window>(desktop_host->GetAcceleratedWidget()),
xev->event = static_cast<uint32_t>(desktop_host->GetAcceleratedWidget()); .root_x = point_in_screen.x(),
xev->root = static_cast<uint32_t>(connection->default_screen().root); .root_y = point_in_screen.y(),
xev->child = 0; .event_x = point_in_screen.x() - bounds_in_screen.x(),
xev->time = x11::CurrentTime; .event_y = point_in_screen.y() - bounds_in_screen.y(),
xev->event_x = point_in_screen.x() - bounds_in_screen.x(); .same_screen = true,
xev->event_y = point_in_screen.y() - bounds_in_screen.y(); };
xev->root_x = point_in_screen.x();
xev->root_y = point_in_screen.y();
xev->state = 0;
xev->detail = NotifyNormal;
xev->same_screen = x11::True;
x11::Event x11_event(&ge, connection); x11::Event x11_event(xev);
ui::X11EventSource::GetInstance()->ProcessXEvent(&x11_event); ui::X11EventSource::GetInstance()->ProcessXEvent(&x11_event);
} }

@@ -117,13 +117,13 @@ class X11TopmostWindowFinderTest : public test::DesktopWidgetTestInteractive {
#endif #endif
// Make X11 synchronous for our display connection. This does not force the // Make X11 synchronous for our display connection. This does not force the
// window manager to behave synchronously. // window manager to behave synchronously.
XSynchronize(xdisplay(), x11::True); XSynchronize(xdisplay(), true);
DesktopWidgetTestInteractive::SetUp(); DesktopWidgetTestInteractive::SetUp();
} }
void TearDown() override { void TearDown() override {
if (!IsSkipped()) if (!IsSkipped())
XSynchronize(xdisplay(), x11::False); XSynchronize(xdisplay(), false);
DesktopWidgetTestInteractive::TearDown(); DesktopWidgetTestInteractive::TearDown();
} }
@@ -400,7 +400,7 @@ TEST_F(X11TopmostWindowFinderTest, DISABLED_Menu) {
x11::Window root = ui::GetX11RootWindow(); x11::Window root = ui::GetX11RootWindow();
XSetWindowAttributes swa; XSetWindowAttributes swa;
swa.override_redirect = x11::True; swa.override_redirect = true;
x11::Window menu_window = static_cast<x11::Window>(XCreateWindow( x11::Window menu_window = static_cast<x11::Window>(XCreateWindow(
xdisplay(), static_cast<uint32_t>(root), 0, 0, 1, 1, xdisplay(), static_cast<uint32_t>(root), 0, 0, 1, 1,
0, // border width 0, // border width