Commit b40fc335 authored by Daniel Bratell's avatar Daniel Bratell Committed by Commit Bot

Clear //remoting from direct X11 includes

X11 headers pollute the global namespace. Instead we use a
wrapper header (ui/gfx/x/x11.h) that puts important symbols
in the x11 namespace and removes them from the global namespace.

Bug: 782184
Change-Id: I3173f2dde17e6991cc31bd89ceaee8e651ccaf3f
Reviewed-on: https://chromium-review.googlesource.com/801390Reviewed-by: default avatarJamie Walch <jamiewalch@chromium.org>
Reviewed-by: default avatarDan Erat <derat@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Commit-Queue: Daniel Bratell <bratell@opera.com>
Cr-Commit-Position: refs/heads/master@{#521303}
parent 48a0f056
......@@ -4,10 +4,7 @@
#include "remoting/host/clipboard.h"
#include <X11/Xlib.h>
#include "base/memory/ptr_util.h"
#undef Status // Xlib.h #defines this, which breaks protobuf headers.
#include "base/bind.h"
#include "base/files/file_descriptor_watcher_posix.h"
......@@ -16,6 +13,7 @@
#include "remoting/host/linux/x_server_clipboard.h"
#include "remoting/proto/event.pb.h"
#include "remoting/protocol/clipboard_stub.h"
#include "ui/gfx/x/x11.h"
namespace remoting {
......
......@@ -4,14 +4,13 @@
#include "remoting/host/curtain_mode.h"
#include <X11/extensions/XInput.h>
#include "base/callback.h"
#include "base/macros.h"
#include "base/memory/ptr_util.h"
#include "base/single_thread_task_runner.h"
#include "remoting/base/logging.h"
#include "remoting/host/client_session_control.h"
#include "ui/gfx/x/x11.h"
namespace remoting {
......
......@@ -4,8 +4,6 @@
#include "remoting/host/desktop_resizer.h"
#include <X11/Xlib.h>
#include <X11/extensions/Xrandr.h>
#include <string.h>
#include "base/command_line.h"
......@@ -13,6 +11,7 @@
#include "base/memory/ptr_util.h"
#include "remoting/base/logging.h"
#include "remoting/host/linux/x11_util.h"
#include "ui/gfx/x/x11.h"
// On Linux, we use the xrandr extension to change the desktop resolution. In
// curtain mode, we do exact resize where supported (currently only using a
......@@ -168,9 +167,9 @@ class DesktopResizerX11 : public DesktopResizer {
DesktopResizerX11::DesktopResizerX11()
: display_(XOpenDisplay(nullptr)),
screen_(DefaultScreen(display_)),
root_(RootWindow(display_, screen_)),
exact_resize_(base::CommandLine::ForCurrentProcess()->
HasSwitch("server-supports-exact-resize")) {
root_(XRootWindow(display_, screen_)),
exact_resize_(base::CommandLine::ForCurrentProcess()->HasSwitch(
"server-supports-exact-resize")) {
int rr_event_base;
int rr_error_base;
......@@ -320,7 +319,7 @@ void DesktopResizerX11::SetResolutionExistingMode(
if (sizes[i].width == resolution.dimensions().width()
&& sizes[i].height == resolution.dimensions().height()) {
XRRSetScreenConfig(display_, config, root_, i, current_rotation,
CurrentTime);
x11::CurrentTime);
break;
}
}
......@@ -358,7 +357,7 @@ void DesktopResizerX11::DeleteMode(const char* name) {
}
void DesktopResizerX11::SwitchToMode(const char* name) {
RRMode mode_id = None;
RRMode mode_id = x11::None;
RROutput* outputs = nullptr;
int number_of_outputs = 0;
if (name) {
......@@ -368,7 +367,8 @@ void DesktopResizerX11::SwitchToMode(const char* name) {
number_of_outputs = resources_.get()->noutput;
}
XRRSetCrtcConfig(display_, resources_.get(), resources_.GetCrtc(),
CurrentTime, 0, 0, mode_id, 1, outputs, number_of_outputs);
x11::CurrentTime, 0, 0, mode_id, 1, outputs,
number_of_outputs);
}
std::unique_ptr<DesktopResizer> DesktopResizer::Create() {
......
......@@ -6,13 +6,6 @@
#include <stddef.h>
#include <stdint.h>
#include <X11/extensions/XInput.h>
#include <X11/extensions/XTest.h>
#include <X11/Xlib.h>
#include <X11/XKBlib.h>
#include <X11/keysym.h>
#undef Status // Xlib.h #defines this, which breaks protobuf headers.
#include <set>
#include <utility>
......@@ -35,6 +28,7 @@
#include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h"
#include "ui/events/keycodes/dom/dom_code.h"
#include "ui/events/keycodes/dom/keycode_converter.h"
#include "ui/gfx/x/x11.h"
#if defined(OS_CHROMEOS)
#include "remoting/host/chromeos/point_transformer.h"
......@@ -50,7 +44,7 @@ using protocol::TextEvent;
using protocol::MouseEvent;
using protocol::TouchEvent;
bool IsModifierKey(ui::DomCode dom_code) {
bool IsDomModifierKey(ui::DomCode dom_code) {
return dom_code == ui::DomCode::CONTROL_LEFT ||
dom_code == ui::DomCode::SHIFT_LEFT ||
dom_code == ui::DomCode::ALT_LEFT ||
......@@ -228,7 +222,7 @@ bool InputInjectorX11::Core::Init() {
if (!task_runner_->BelongsToCurrentThread())
task_runner_->PostTask(FROM_HERE, base::Bind(&Core::InitClipboard, this));
root_window_ = RootWindow(display_, DefaultScreen(display_));
root_window_ = XRootWindow(display_, DefaultScreen(display_));
if (root_window_ == BadValue) {
LOG(ERROR) << "Unable to get the root window";
return false;
......@@ -278,11 +272,11 @@ void InputInjectorX11::Core::InjectKeyEvent(const KeyEvent& event) {
if (event.pressed()) {
if (pressed_keys_.find(keycode) != pressed_keys_.end()) {
// Ignore repeats for modifier keys.
if (IsModifierKey(static_cast<ui::DomCode>(event.usb_keycode())))
if (IsDomModifierKey(static_cast<ui::DomCode>(event.usb_keycode())))
return;
// Key is already held down, so lift the key up to ensure this repeated
// press takes effect.
XTestFakeKeyEvent(display_, keycode, False, CurrentTime);
XTestFakeKeyEvent(display_, keycode, x11::False, x11::CurrentTime);
}
if (!IsLockKey(keycode)) {
......@@ -325,7 +319,7 @@ void InputInjectorX11::Core::InjectKeyEvent(const KeyEvent& event) {
}
}
XTestFakeKeyEvent(display_, keycode, event.pressed(), CurrentTime);
XTestFakeKeyEvent(display_, keycode, event.pressed(), x11::CurrentTime);
XFlush(display_);
}
......@@ -340,7 +334,7 @@ void InputInjectorX11::Core::InjectTextEvent(const TextEvent& event) {
// any interference with the currently pressed keys. E.g. if Shift is pressed
// when TextEvent is received.
for (int key : pressed_keys_) {
XTestFakeKeyEvent(display_, key, False, CurrentTime);
XTestFakeKeyEvent(display_, key, x11::False, x11::CurrentTime);
}
pressed_keys_.clear();
......@@ -382,9 +376,9 @@ void InputInjectorX11::Core::SetAutoRepeatEnabled(bool mode) {
bool InputInjectorX11::Core::IsLockKey(KeyCode keycode) {
XkbStateRec state;
KeySym keysym;
if (XkbGetState(display_, XkbUseCoreKbd, &state) == Success &&
if (XkbGetState(display_, XkbUseCoreKbd, &state) == x11::Success &&
XkbLookupKeySym(display_, keycode, XkbStateMods(&state), nullptr,
&keysym) == True) {
&keysym) == x11::True) {
return keysym == XK_Caps_Lock || keysym == XK_Num_Lock;
} else {
return false;
......@@ -426,8 +420,8 @@ void InputInjectorX11::Core::InjectScrollWheelClicks(int button, int count) {
}
for (int i = 0; i < count; i++) {
// Generate a button-down and a button-up to simulate a wheel click.
XTestFakeButtonEvent(display_, button, true, CurrentTime);
XTestFakeButtonEvent(display_, button, false, CurrentTime);
XTestFakeButtonEvent(display_, button, true, x11::CurrentTime);
XTestFakeButtonEvent(display_, button, false, x11::CurrentTime);
}
}
......@@ -443,9 +437,8 @@ void InputInjectorX11::Core::InjectMouseEvent(const MouseEvent& event) {
(event.delta_x() != 0 || event.delta_y() != 0)) {
latest_mouse_position_.set(-1, -1);
VLOG(3) << "Moving mouse by " << event.delta_x() << "," << event.delta_y();
XTestFakeRelativeMotionEvent(display_,
event.delta_x(), event.delta_y(),
CurrentTime);
XTestFakeRelativeMotionEvent(display_, event.delta_x(), event.delta_y(),
x11::CurrentTime);
} else if (event.has_x() && event.has_y()) {
// Injecting a motion event immediately before a button release results in
......@@ -474,8 +467,7 @@ void InputInjectorX11::Core::InjectMouseEvent(const MouseEvent& event) {
<< "," << latest_mouse_position_.y();
XTestFakeMotionEvent(display_, DefaultScreen(display_),
latest_mouse_position_.x(),
latest_mouse_position_.y(),
CurrentTime);
latest_mouse_position_.y(), x11::CurrentTime);
}
}
......@@ -492,7 +484,7 @@ void InputInjectorX11::Core::InjectMouseEvent(const MouseEvent& event) {
<< (event.button_down() ? "down " : "up ")
<< button_number;
XTestFakeButtonEvent(display_, button_number, event.button_down(),
CurrentTime);
x11::CurrentTime);
}
// Older client plugins always send scroll events in pixels, which
......@@ -602,7 +594,7 @@ void InputInjectorX11::Core::InitMouseButtonMap() {
}
error = XSetDeviceButtonMapping(display_, device, button_mapping.get(),
num_device_buttons);
if (error != Success)
if (error != x11::Success)
LOG(ERROR) << "Failed to set XTest device button mapping: " << error;
XCloseDevice(display_, device);
......
......@@ -27,9 +27,9 @@
#if defined(OS_LINUX)
#include <gtk/gtk.h>
#include <X11/Xlib.h>
#include "base/linux_util.h"
#include "ui/gfx/x/x11.h"
#endif // defined(OS_LINUX)
#if defined(OS_MACOSX)
......
......@@ -5,28 +5,9 @@
#include "remoting/host/linux/unicode_to_keysym.h"
#include <algorithm>
#define XK_MISCELLANY
#define XK_XKB_KEYS
#define XK_LATIN1
#define XK_LATIN2
#define XK_LATIN3
#define XK_LATIN4
#define XK_LATIN9
#define XK_GREEK
#define XK_KATAKANA
#define XK_ARABIC
#define XK_CYRILLIC
#define XK_HEBREW
#define XK_THAI
#define XK_KOREAN
#define XK_CURRENCY
#define XK_TECHNICAL
#define XK_PUBLISHING
#define XK_APL
#define XK_SPECIAL
#include <X11/keysymdef.h>
#include "base/macros.h"
#include "ui/gfx/x/x11.h"
namespace remoting {
......
......@@ -4,12 +4,9 @@
#include "remoting/host/linux/x11_keyboard_impl.h"
#include <X11/extensions/XInput.h>
#include <X11/extensions/XTest.h>
#include <X11/XKBlib.h>
#include "base/strings/stringprintf.h"
#include "remoting/host/linux/unicode_to_keysym.h"
#include "ui/gfx/x/x11.h"
#include "ui/gfx/x/x11_types.h"
namespace {
......@@ -82,8 +79,8 @@ std::vector<uint32_t> X11KeyboardImpl::GetUnusedKeycodes() {
void X11KeyboardImpl::PressKey(uint32_t keycode, uint32_t modifiers) {
XkbLockModifiers(display_, XkbUseCoreKbd, modifiers, modifiers);
XTestFakeKeyEvent(display_, keycode, True, CurrentTime);
XTestFakeKeyEvent(display_, keycode, False, CurrentTime);
XTestFakeKeyEvent(display_, keycode, x11::True, x11::CurrentTime);
XTestFakeKeyEvent(display_, keycode, x11::False, x11::CurrentTime);
XkbLockModifiers(display_, XkbUseCoreKbd, modifiers, 0);
}
......
......@@ -7,9 +7,8 @@
#include "remoting/host/linux/x11_keyboard.h"
#include <X11/Xlib.h>
#include "base/macros.h"
#include "ui/gfx/x/x11.h"
namespace remoting {
......
......@@ -4,9 +4,8 @@
#include "remoting/host/linux/x11_util.h"
#include <X11/extensions/XTest.h>
#include "base/bind.h"
#include "ui/gfx/x/x11.h"
namespace remoting {
......
......@@ -5,14 +5,15 @@
#ifndef REMOTING_HOST_LINUX_X11_UTIL_H_
#define REMOTING_HOST_LINUX_X11_UTIL_H_
// Xlib.h defines XErrorEvent as an anonymous struct, so we can't forward-
// declare it in this header. Since Xlib.h is not generally something you
// should #include into arbitrary code, please refrain from #including this
// header in another header.
#include <X11/Xlib.h>
// Xlib.h (via ui/gfx/x/x11.h) defines XErrorEvent as an anonymous
// struct, so we can't forward- declare it in this header. Since
// Xlib.h is not generally something you should #include into
// arbitrary code, please refrain from #including this header in
// another header.
#include "base/callback.h"
#include "base/macros.h"
#include "ui/gfx/x/x11.h"
namespace remoting {
......
......@@ -4,13 +4,12 @@
#include "remoting/host/linux/x_server_clipboard.h"
#include <X11/extensions/Xfixes.h>
#include "base/callback.h"
#include "base/macros.h"
#include "remoting/base/constants.h"
#include "remoting/base/logging.h"
#include "remoting/base/util.h"
#include "ui/gfx/x/x11.h"
namespace remoting {
......@@ -18,14 +17,13 @@ XServerClipboard::XServerClipboard()
: display_(nullptr),
clipboard_window_(BadValue),
xfixes_event_base_(-1),
clipboard_atom_(None),
large_selection_atom_(None),
selection_string_atom_(None),
targets_atom_(None),
timestamp_atom_(None),
utf8_string_atom_(None),
large_selection_property_(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;
......@@ -68,7 +66,7 @@ void XServerClipboard::Init(Display* display,
Atom atoms[kNumAtomNames];
if (XInternAtoms(display_, const_cast<char**>(kAtomNames), kNumAtomNames,
False, atoms)) {
x11::False, atoms)) {
clipboard_atom_ = atoms[0];
large_selection_atom_ = atoms[1];
selection_string_atom_ = atoms[2];
......@@ -167,7 +165,7 @@ void XServerClipboard::OnSetSelectionOwnerNotify(Atom selection,
}
void XServerClipboard::OnPropertyNotify(XEvent* event) {
if (large_selection_property_ != None &&
if (large_selection_property_ != x11::None &&
event->xproperty.atom == large_selection_property_ &&
event->xproperty.state == PropertyNewValue) {
Atom type;
......@@ -175,37 +173,36 @@ void XServerClipboard::OnPropertyNotify(XEvent* event) {
unsigned long item_count, after;
unsigned char *data;
XGetWindowProperty(display_, clipboard_window_, large_selection_property_,
0, ~0L, True, AnyPropertyType, &type, &format,
0, ~0L, x11::True, AnyPropertyType, &type, &format,
&item_count, &after, &data);
if (type != None) {
if (type != x11::None) {
// TODO(lambroslambrou): Properly support large transfers -
// http://crbug.com/151447.
XFree(data);
// If the property is zero-length then the large transfer is complete.
if (item_count == 0)
large_selection_property_ = None;
large_selection_property_ = x11::None;
}
}
}
void XServerClipboard::OnSelectionNotify(XEvent* event) {
if (event->xselection.property != None) {
if (event->xselection.property != x11::None) {
Atom type;
int format;
unsigned long item_count, after;
unsigned char *data;
XGetWindowProperty(display_, clipboard_window_,
event->xselection.property, 0, ~0L, True,
AnyPropertyType, &type, &format,
XGetWindowProperty(display_, clipboard_window_, event->xselection.property,
0, ~0L, x11::True, AnyPropertyType, &type, &format,
&item_count, &after, &data);
if (type == large_selection_atom_) {
// Large selection - just read and ignore these for now.
large_selection_property_ = event->xselection.property;
} else {
// Standard selection - call the selection notifier.
large_selection_property_ = None;
if (type != None) {
large_selection_property_ = x11::None;
if (type != x11::None) {
HandleSelectionNotify(&event->xselection, type, format, item_count,
data);
XFree(data);
......@@ -224,10 +221,10 @@ void XServerClipboard::OnSelectionRequest(XEvent* event) {
selection_event.selection = event->xselectionrequest.selection;
selection_event.time = event->xselectionrequest.time;
selection_event.target = event->xselectionrequest.target;
if (event->xselectionrequest.property == None)
if (event->xselectionrequest.property == x11::None)
event->xselectionrequest.property = event->xselectionrequest.target;
if (!IsSelectionOwner(selection_event.selection)) {
selection_event.property = None;
selection_event.property = x11::None;
} else {
selection_event.property = event->xselectionrequest.property;
if (selection_event.target == targets_atom_) {
......@@ -241,7 +238,7 @@ void XServerClipboard::OnSelectionRequest(XEvent* event) {
selection_event.target);
}
}
XSendEvent(display_, selection_event.requestor, False, 0,
XSendEvent(display_, selection_event.requestor, x11::False, 0,
reinterpret_cast<XEvent*>(&selection_event));
}
......@@ -268,7 +265,7 @@ void XServerClipboard::SendTimestampResponse(Window requestor, Atom property) {
// TODO(lambroslambrou): Should use a proper timestamp here instead of
// CurrentTime. ICCCM recommends doing a zero-length property append,
// and getting a timestamp from the subsequent PropertyNotify event.
Time time = CurrentTime;
Time time = x11::CurrentTime;
XChangeProperty(display_, requestor, property, XA_INTEGER, 32,
PropModeReplace, reinterpret_cast<unsigned char*>(&time), 1);
}
......@@ -350,16 +347,16 @@ void XServerClipboard::NotifyClipboardText(const std::string& text) {
void XServerClipboard::RequestSelectionTargets(Atom selection) {
XConvertSelection(display_, selection, targets_atom_, targets_atom_,
clipboard_window_, CurrentTime);
clipboard_window_, x11::CurrentTime);
}
void XServerClipboard::RequestSelectionString(Atom selection, Atom target) {
XConvertSelection(display_, selection, target, selection_string_atom_,
clipboard_window_, CurrentTime);
clipboard_window_, x11::CurrentTime);
}
void XServerClipboard::AssertSelectionOwnership(Atom selection) {
XSetSelectionOwner(display_, selection, clipboard_window_, CurrentTime);
XSetSelectionOwner(display_, selection, clipboard_window_, x11::CurrentTime);
if (XGetSelectionOwner(display_, selection) == clipboard_window_) {
selections_owned_.insert(selection);
} else {
......
......@@ -7,15 +7,13 @@
#ifndef REMOTING_HOST_LINUX_X_SERVER_CLIPBOARD_H_
#define REMOTING_HOST_LINUX_X_SERVER_CLIPBOARD_H_
#include <X11/Xatom.h>
#include <X11/Xlib.h>
#include <set>
#include <string>
#include "base/callback.h"
#include "base/macros.h"
#include "base/time/time.h"
#include "ui/gfx/x/x11.h"
namespace remoting {
......
......@@ -7,12 +7,9 @@
#include "base/bind.h"
#include "base/macros.h"
#include "remoting/base/constants.h"
#include "testing/gtest/include/gtest/gtest.h"
// X11 headers must be #included after gtest.h, since the X11 headers define
// some macros that cause errors in gtest-type-util.h.
#include <X11/Xlib.h>
#include "remoting/host/linux/x_server_clipboard.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/x/x11.h"
namespace remoting {
......@@ -72,10 +69,10 @@ class XServerClipboardTest : public testing::Test {
// XSynchronize() ensures that PumpXEvents() fully processes all X server
// requests and responses before returning to the caller.
Display* display1 = XOpenDisplay(nullptr);
XSynchronize(display1, True);
XSynchronize(display1, x11::True);
client1_.Init(display1);
Display* display2 = XOpenDisplay(nullptr);
XSynchronize(display2, True);
XSynchronize(display2, x11::True);
client2_.Init(display2);
}
......
......@@ -7,11 +7,6 @@
#include <sys/select.h>
#include <unistd.h>
#include "base/memory/ptr_util.h"
#include "base/sequence_checker.h"
#define XK_MISCELLANY
#include <X11/keysymdef.h>
#include "base/bind.h"
#include "base/callback.h"
#include "base/compiler_specific.h"
......@@ -19,15 +14,12 @@
#include "base/location.h"
#include "base/logging.h"
#include "base/macros.h"
#include "base/memory/ptr_util.h"
#include "base/sequence_checker.h"
#include "base/single_thread_task_runner.h"
#include "remoting/host/client_session_control.h"
#include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h"
// These includes need to be later than dictated by the style guide due to
// Xlib header pollution, specifically the min, max, and Status macros.
#include <X11/XKBlib.h>
#include <X11/Xlibint.h>
#include <X11/extensions/record.h>
#include "ui/gfx/x/x11.h"
namespace remoting {
......
......@@ -118,11 +118,10 @@
#if defined(OS_LINUX)
#include <gtk/gtk.h>
#include <X11/Xlib.h>
#undef Status // Xlib.h #defines this, which breaks protobuf headers.
#include <base/linux_util.h>
#include "base/linux_util.h"
#include "remoting/host/audio_capturer_linux.h"
#include "remoting/host/linux/certificate_watcher.h"
#include "ui/gfx/x/x11.h"
#endif // defined(OS_LINUX)
#if defined(OS_WIN)
......
......@@ -11,9 +11,9 @@
#if defined(OS_LINUX)
#include <gtk/gtk.h>
#include <X11/Xlib.h>
#include "base/linux_util.h"
#include "ui/gfx/x/x11.h"
#endif // defined(OS_LINUX)
int main(int argc, const char** argv) {
......
......@@ -33,6 +33,7 @@ extern "C" {
#include <X11/extensions/Xfixes.h>
#include <X11/extensions/Xrandr.h>
#include <X11/extensions/Xrender.h>
#include <X11/extensions/record.h>
#include <X11/extensions/scrnsaver.h>
#include <X11/extensions/shape.h>
......@@ -65,6 +66,7 @@ extern "C" {
#define XK_MATHEMATICAL
#define XK_BRAILLE
#define XK_SINHALA
#define XK_XKB_KEYS
#ifndef XK_dead_greek
#define XK_dead_greek 0xfe8c
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment