Commit 91d9d1ac authored by Tom Anderson's avatar Tom Anderson Committed by Commit Bot

[XProto] Consolidate all <X11/*> includes to //ui/gfx/x/x11.h

This makes it easier to track the remaining usages of Xlib.  I plan on
removing headers from x11.h a couple at a time.  Once we're down to
just Xlib.h, I'll remove the Xlib.h include and replace it with manual
declarations for all the types and functions we need (XOpenDisplay(),
etc).  Then I'll continue incrementally removing types and functions
from there.

BUG=1066670
R=msisov,sky,penghuang

Change-Id: Ia80e911eb540f99c2a4aa3edf396f1e1cc982e5d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2373227Reviewed-by: default avatarMaksim Sisov (GMT+3) <msisov@igalia.com>
Reviewed-by: default avatarPeng Huang <penghuang@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Commit-Queue: Thomas Anderson <thomasanderson@chromium.org>
Cr-Commit-Position: refs/heads/master@{#801306}
parent 89bd0574
...@@ -24,7 +24,7 @@ component("menu") { ...@@ -24,7 +24,7 @@ component("menu") {
"//ui/gfx", "//ui/gfx",
] ]
if (use_x11) { if (use_x11) {
configs += [ "//build/config/linux:x11" ] deps += [ "//ui/gfx/x" ]
} }
} }
......
...@@ -3,4 +3,5 @@ include_rules = [ ...@@ -3,4 +3,5 @@ include_rules = [
"+ui/base", "+ui/base",
"+ui/events/keycodes", "+ui/events/keycodes",
"+ui/gfx/image", "+ui/gfx/image",
"+ui/gfx/x",
] ]
...@@ -14,10 +14,9 @@ ...@@ -14,10 +14,9 @@
#include "ui/gfx/image/image.h" #include "ui/gfx/image/image.h"
#if defined(USE_X11) #if defined(USE_X11)
#include <X11/Xlib.h>
#include "ui/base/ui_base_features.h" #include "ui/base/ui_base_features.h"
#include "ui/events/keycodes/keyboard_code_conversion_x.h" // nogncheck #include "ui/events/keycodes/keyboard_code_conversion_x.h" // nogncheck
#include "ui/gfx/x/x11.h" // nogncheck
#endif #endif
MenuItemProperties ComputeMenuPropertiesForMenuItem(ui::MenuModel* menu, MenuItemProperties ComputeMenuPropertiesForMenuItem(ui::MenuModel* menu,
......
...@@ -382,7 +382,9 @@ def GenerateHeaderFile(out_file): ...@@ -382,7 +382,9 @@ def GenerateHeaderFile(out_file):
#endif #endif
#if defined(USE_VULKAN_XLIB) #if defined(USE_VULKAN_XLIB)
#include <X11/Xlib.h> typedef struct _XDisplay Display;
typedef unsigned long Window;
typedef unsigned long VisualID;
#include <vulkan/vulkan_xlib.h> #include <vulkan/vulkan_xlib.h>
#endif #endif
......
...@@ -32,7 +32,9 @@ ...@@ -32,7 +32,9 @@
#endif #endif
#if defined(USE_VULKAN_XLIB) #if defined(USE_VULKAN_XLIB)
#include <X11/Xlib.h> typedef struct _XDisplay Display;
typedef unsigned long Window;
typedef unsigned long VisualID;
#include <vulkan/vulkan_xlib.h> #include <vulkan/vulkan_xlib.h>
#endif #endif
......
...@@ -5,8 +5,6 @@ ...@@ -5,8 +5,6 @@
#include "ui/base/x/selection_requestor.h" #include "ui/base/x/selection_requestor.h"
#include <stddef.h> #include <stddef.h>
#include <xcb/xcb.h>
#include <memory> #include <memory>
#include "base/bind.h" #include "base/bind.h"
...@@ -44,19 +42,12 @@ class SelectionRequestorTest : public testing::Test { ...@@ -44,19 +42,12 @@ class SelectionRequestorTest : public testing::Test {
ui::SetStringProperty(x_window_, requestor_->x_property_, ui::SetStringProperty(x_window_, requestor_->x_property_,
gfx::GetAtom("STRING"), value); gfx::GetAtom("STRING"), value);
xcb_generic_event_t ge; requestor_->OnSelectionNotify({
memset(&ge, 0, sizeof(ge)); .requestor = x_window_,
auto* event = reinterpret_cast<xcb_selection_notify_event_t*>(&ge); .selection = selection,
event->response_type = x11::SelectionNotifyEvent::opcode; .target = target,
event->sequence = 0; .property = requestor_->x_property_,
event->requestor = static_cast<uint32_t>(x_window_); });
event->selection = static_cast<uint32_t>(selection);
event->target = static_cast<uint32_t>(target);
event->property = static_cast<uint32_t>(requestor_->x_property_);
event->time = x11::CurrentTime;
x11::Event xev(&ge, x11::Connection::Get());
requestor_->OnSelectionNotify(*xev.As<x11::SelectionNotifyEvent>());
} }
protected: protected:
......
...@@ -31,7 +31,9 @@ const int kWaitForUIThreadSeconds = 10; ...@@ -31,7 +31,9 @@ const int kWaitForUIThreadSeconds = 10;
int BrowserX11ErrorHandler(Display* d, XErrorEvent* error) { int BrowserX11ErrorHandler(Display* d, XErrorEvent* error) {
if (!g_in_x11_io_error_handler) { if (!g_in_x11_io_error_handler) {
base::SequencedTaskRunnerHandle::Get()->PostTask( base::SequencedTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::BindOnce(&x11::LogErrorEventDescription, *error)); FROM_HERE, base::BindOnce(&x11::LogErrorEventDescription, error->serial,
error->error_code, error->request_code,
error->minor_code));
} }
return 0; return 0;
} }
......
...@@ -101,7 +101,9 @@ int DefaultX11ErrorHandler(XDisplay* d, XErrorEvent* e) { ...@@ -101,7 +101,9 @@ int DefaultX11ErrorHandler(XDisplay* d, XErrorEvent* e) {
if (base::CurrentThread::Get()) { if (base::CurrentThread::Get()) {
base::ThreadTaskRunnerHandle::Get()->PostTask( base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::BindOnce(&x11::LogErrorEventDescription, *e)); FROM_HERE,
base::BindOnce(&x11::LogErrorEventDescription, e->serial, e->error_code,
e->request_code, e->minor_code));
} else { } else {
LOG(ERROR) << "X error received: " LOG(ERROR) << "X error received: "
<< "serial " << e->serial << ", " << "serial " << e->serial << ", "
......
...@@ -4,11 +4,6 @@ ...@@ -4,11 +4,6 @@
#include "ui/events/platform/x11/x11_event_source.h" #include "ui/events/platform/x11/x11_event_source.h"
#include <X11/Xlib-xcb.h>
#include <xcb/xcb.h>
#include <xcb/xcbext.h>
#include <xcb/xproto.h>
#include <algorithm> #include <algorithm>
#include <memory> #include <memory>
#include <type_traits> #include <type_traits>
......
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
#include "ui/events/test/events_test_utils_x11.h" #include "ui/events/test/events_test_utils_x11.h"
#include <stddef.h> #include <stddef.h>
#include <xcb/xproto.h>
#include "base/check_op.h" #include "base/check_op.h"
#include "base/notreached.h" #include "base/notreached.h"
...@@ -19,6 +18,7 @@ ...@@ -19,6 +18,7 @@
#include "ui/gfx/x/connection.h" #include "ui/gfx/x/connection.h"
#include "ui/gfx/x/x11.h" #include "ui/gfx/x/x11.h"
#include "ui/gfx/x/xinput.h" #include "ui/gfx/x/xinput.h"
#include "ui/gfx/x/xproto.h"
namespace { namespace {
...@@ -38,14 +38,15 @@ unsigned int XEventState(int flags) { ...@@ -38,14 +38,15 @@ unsigned int XEventState(int flags) {
} }
// Converts EventType to XKeyEvent type. // Converts EventType to XKeyEvent type.
int XKeyEventType(ui::EventType type) { x11::KeyEvent::Opcode XKeyEventType(ui::EventType type) {
switch (type) { switch (type) {
case ui::ET_KEY_PRESSED: case ui::ET_KEY_PRESSED:
return x11::KeyEvent::Press; return x11::KeyEvent::Press;
case ui::ET_KEY_RELEASED: case ui::ET_KEY_RELEASED:
return x11::KeyEvent::Release; return x11::KeyEvent::Release;
default: default:
return 0; NOTREACHED();
return {};
} }
} }
...@@ -130,76 +131,49 @@ ScopedXI2Event::~ScopedXI2Event() = default; ...@@ -130,76 +131,49 @@ ScopedXI2Event::~ScopedXI2Event() = default;
void ScopedXI2Event::InitKeyEvent(EventType type, void ScopedXI2Event::InitKeyEvent(EventType type,
KeyboardCode key_code, KeyboardCode key_code,
int flags) { int flags) {
auto* connection = x11::Connection::Get(); x11::KeyEvent key_event{
xcb_generic_event_t ge; .opcode = XKeyEventType(type),
memset(&ge, 0, sizeof(ge)); .detail = static_cast<x11::KeyCode>(
auto* key = reinterpret_cast<xcb_key_press_event_t*>(&ge); XKeyCodeForWindowsKeyCode(key_code, flags, x11::Connection::Get())),
key->response_type = XKeyEventType(type); .state = static_cast<x11::KeyButMask>(XEventState(flags)),
CHECK_NE(0, key->response_type); .same_screen = true,
key->sequence = 0; };
key->time = 0;
key->event = 0; x11::Event x11_event(key_event);
key->root = 0;
key->child = 0;
key->event_x = 0;
key->event_y = 0;
key->root_x = 0;
key->root_y = 0;
key->state = XEventState(flags);
key->detail = XKeyCodeForWindowsKeyCode(key_code, flags, connection);
key->same_screen = 1;
x11::Event x11_event(&ge, connection);
event_ = std::move(x11_event); event_ = std::move(x11_event);
} }
void ScopedXI2Event::InitMotionEvent(const gfx::Point& location, void ScopedXI2Event::InitMotionEvent(const gfx::Point& location,
const gfx::Point& root_location, const gfx::Point& root_location,
int flags) { int flags) {
auto* connection = x11::Connection::Get(); x11::MotionNotifyEvent motion_event{
xcb_generic_event_t ge; .root_x = root_location.x(),
memset(&ge, 0, sizeof(ge)); .root_y = root_location.y(),
auto* motion = reinterpret_cast<xcb_motion_notify_event_t*>(&ge); .event_x = location.x(),
motion->response_type = MotionNotify; .event_y = location.y(),
motion->sequence = 0; .state = static_cast<x11::KeyButMask>(XEventState(flags)),
motion->time = 0; .same_screen = true,
motion->event = 0; };
motion->root = 0;
motion->child = 0; x11::Event x11_event(motion_event);
motion->event_x = location.x();
motion->event_y = location.y();
motion->root_x = root_location.x();
motion->root_y = root_location.y();
motion->state = XEventState(flags);
motion->same_screen = 1;
x11::Event x11_event(&ge, connection);
event_ = std::move(x11_event); event_ = std::move(x11_event);
} }
void ScopedXI2Event::InitButtonEvent(EventType type, void ScopedXI2Event::InitButtonEvent(EventType type,
const gfx::Point& location, const gfx::Point& location,
int flags) { int flags) {
auto* connection = x11::Connection::Get(); x11::ButtonEvent button_event{
xcb_generic_event_t ge; .opcode = type == ui::ET_MOUSE_PRESSED ? x11::ButtonEvent::Press
memset(&ge, 0, sizeof(ge)); : x11::ButtonEvent::Release,
auto* button = reinterpret_cast<xcb_button_press_event_t*>(&ge); .detail = static_cast<x11::Button>(XButtonEventButton(type, flags)),
button->response_type = (type == ui::ET_MOUSE_PRESSED) .root_x = location.x(),
? x11::ButtonEvent::Press .root_y = location.y(),
: x11::ButtonEvent::Release; .event_x = location.x(),
button->sequence = 0; .event_y = location.y(),
button->time = 0; .same_screen = true,
button->event = 0; };
button->root = 0;
button->event_x = location.x(); x11::Event x11_event(button_event);
button->event_y = location.y();
button->root_x = location.x();
button->root_y = location.y();
button->state = 0;
button->detail = XButtonEventButton(type, flags);
button->same_screen = 1;
x11::Event x11_event(&ge, connection);
event_ = std::move(x11_event); event_ = std::move(x11_event);
} }
......
...@@ -98,6 +98,7 @@ component("xprotos") { ...@@ -98,6 +98,7 @@ component("xprotos") {
"event.cc", "event.cc",
"x11_switches.cc", "x11_switches.cc",
"x11_switches.h", "x11_switches.h",
"x11.h",
] ]
configs += [ configs += [
":x11_private_config", ":x11_private_config",
...@@ -110,7 +111,6 @@ component("x") { ...@@ -110,7 +111,6 @@ component("x") {
sources = [ sources = [
"../gfx_export.h", "../gfx_export.h",
"x11.h",
"x11_atom_cache.cc", "x11_atom_cache.cc",
"x11_atom_cache.h", "x11_atom_cache.h",
"x11_error_tracker.cc", "x11_error_tracker.cc",
......
...@@ -4,10 +4,8 @@ ...@@ -4,10 +4,8 @@
#include "ui/gfx/x/connection.h" #include "ui/gfx/x/connection.h"
#include <X11/Xlib-xcb.h>
#include <X11/Xlib.h>
#include <X11/keysym.h>
#include <xcb/xcb.h> #include <xcb/xcb.h>
#include <xcb/xcbext.h>
#include <algorithm> #include <algorithm>
...@@ -21,6 +19,7 @@ ...@@ -21,6 +19,7 @@
#include "ui/gfx/x/bigreq.h" #include "ui/gfx/x/bigreq.h"
#include "ui/gfx/x/event.h" #include "ui/gfx/x/event.h"
#include "ui/gfx/x/randr.h" #include "ui/gfx/x/randr.h"
#include "ui/gfx/x/x11.h"
#include "ui/gfx/x/x11_switches.h" #include "ui/gfx/x/x11_switches.h"
#include "ui/gfx/x/xproto.h" #include "ui/gfx/x/xproto.h"
#include "ui/gfx/x/xproto_internal.h" #include "ui/gfx/x/xproto_internal.h"
...@@ -194,12 +193,12 @@ void ConvertCase(KeySym sym, KeySym* lower, KeySym* upper) { ...@@ -194,12 +193,12 @@ void ConvertCase(KeySym sym, KeySym* lower, KeySym* upper) {
*upper = static_cast<KeySym>(upper32); *upper = static_cast<KeySym>(upper32);
} }
bool IsKeypadKey(KeySym keysym) { bool IsXKeypadKey(KeySym keysym) {
auto key = static_cast<uint32_t>(keysym); auto key = static_cast<uint32_t>(keysym);
return key >= XK_KP_Space && key <= XK_KP_Equal; return key >= XK_KP_Space && key <= XK_KP_Equal;
} }
bool IsPrivateKeypadKey(KeySym keysym) { bool IsPrivateXKeypadKey(KeySym keysym) {
auto key = static_cast<uint32_t>(keysym); auto key = static_cast<uint32_t>(keysym);
return key >= 0x11000000 && key <= 0x1100FFFF; return key >= 0x11000000 && key <= 0x1100FFFF;
} }
...@@ -621,7 +620,7 @@ KeySym Connection::TranslateKey(uint32_t key, unsigned int modifiers) const { ...@@ -621,7 +620,7 @@ KeySym Connection::TranslateKey(uint32_t key, unsigned int modifiers) const {
if ((modifiers & num_lock_) && if ((modifiers & num_lock_) &&
(n_keysyms > 1 && (n_keysyms > 1 &&
(IsKeypadKey(syms[1]) || IsPrivateKeypadKey(syms[1])))) { (IsXKeypadKey(syms[1]) || IsPrivateXKeypadKey(syms[1])))) {
if ((modifiers & ShiftMask) || if ((modifiers & ShiftMask) ||
((modifiers & LockMask) && (lock_meaning_ == XK_Shift_Lock))) { ((modifiers & LockMask) && (lock_meaning_ == XK_Shift_Lock))) {
return syms[0]; return syms[0];
......
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
#include "ui/gfx/x/event.h" #include "ui/gfx/x/event.h"
#include <xcb/xcb.h>
#include <cstring> #include <cstring>
#include "base/check_op.h" #include "base/check_op.h"
......
...@@ -5,9 +5,6 @@ ...@@ -5,9 +5,6 @@
#ifndef UI_GFX_X_EVENT_H_ #ifndef UI_GFX_X_EVENT_H_
#define UI_GFX_X_EVENT_H_ #define UI_GFX_X_EVENT_H_
#include <X11/Xlib.h>
#include <xcb/xcb.h>
#include <cstdint> #include <cstdint>
#include <utility> #include <utility>
...@@ -29,11 +26,12 @@ class COMPONENT_EXPORT(X11) Event { ...@@ -29,11 +26,12 @@ class COMPONENT_EXPORT(X11) Event {
public: public:
template <typename T> template <typename T>
explicit Event(T&& xproto_event) { explicit Event(T&& xproto_event) {
using DecayT = std::decay_t<T>;
sequence_valid_ = true; sequence_valid_ = true;
sequence_ = xproto_event.sequence; sequence_ = xproto_event.sequence;
type_id_ = T::type_id; type_id_ = DecayT::type_id;
deleter_ = [](void* event) { delete reinterpret_cast<T*>(event); }; deleter_ = [](void* event) { delete reinterpret_cast<DecayT*>(event); };
T* event = new T(std::forward<T>(xproto_event)); auto* event = new DecayT(std::forward<T>(xproto_event));
event_ = event; event_ = event;
window_ = event->GetWindow(); window_ = event->GetWindow();
} }
......
...@@ -64,6 +64,8 @@ extern "C" { ...@@ -64,6 +64,8 @@ extern "C" {
#include <X11/keysym.h> #include <X11/keysym.h>
} }
#include "ui/gfx/x/xproto_undef.h"
#include "ui/gfx/x/connection.h" #include "ui/gfx/x/connection.h"
// These commonly used names are undefined and if necessary recreated // These commonly used names are undefined and if necessary recreated
...@@ -75,18 +77,18 @@ extern "C" { ...@@ -75,18 +77,18 @@ extern "C" {
// headers than initially expected, including system headers like // headers than initially expected, including system headers like
// those from X11. // those from X11.
#undef Status // Defined by X11/Xlib.h to int #undef Status // Defined by X11/Xlib.h to int
#undef Bool // Defined by X11/Xlib.h to int #undef Bool // Defined by X11/Xlib.h to int
#undef RootWindow // Defined by X11/Xlib.h #undef RootWindow // Defined by X11/Xlib.h
#undef DestroyAll // Defined by X11/X.h to 0 #undef DestroyAll // Defined by X11/X.h to 0
#undef Always // Defined by X11/X.h to 2 #undef Always // Defined by X11/X.h to 2
#undef FocusIn // Defined by X.h to 9 #undef FocusIn // Defined by X.h to 9
#undef FocusOut // Defined by X.h to 10 #undef FocusOut // Defined by X.h to 10
#undef None // Defined by X11/X.h to 0L #undef None // Defined by X11/X.h to 0L
#undef True // Defined by X11/Xlib.h to 1 #undef True // Defined by X11/Xlib.h to 1
#undef False // Defined by X11/Xlib.h to 0 #undef False // Defined by X11/Xlib.h to 0
#undef CurrentTime // Defined by X11/X.h to 0L #undef CurrentTime // Defined by X11/X.h to 0L
#undef Success // Defined by X11/X.h to 0 #undef Success // Defined by X11/X.h to 0
// The x11 namespace allows to scope X11 constants and types that // The x11 namespace allows to scope X11 constants and types that
// would be problematic at the default preprocessor level. // would be problematic at the default preprocessor level.
......
...@@ -4,9 +4,6 @@ ...@@ -4,9 +4,6 @@
#include "ui/gfx/x/x11_atom_cache.h" #include "ui/gfx/x/x11_atom_cache.h"
#include <X11/Xatom.h>
#include <X11/Xlib.h>
#include <utility> #include <utility>
#include <vector> #include <vector>
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "ui/gfx/x/x11_error_tracker.h" #include "ui/gfx/x/x11_error_tracker.h"
#include "base/check.h" #include "base/check.h"
#include "ui/gfx/x/x11.h"
#include "ui/gfx/x/x11_types.h" #include "ui/gfx/x/x11_types.h"
namespace { namespace {
...@@ -26,18 +27,18 @@ X11ErrorTracker::X11ErrorTracker() { ...@@ -26,18 +27,18 @@ X11ErrorTracker::X11ErrorTracker() {
// X11ErrorTracker instances on the same thread. // X11ErrorTracker instances on the same thread.
DCHECK(g_handler == nullptr); DCHECK(g_handler == nullptr);
g_handler = this; g_handler = this;
XSync(GetXDisplay(), False); XSync(GetXDisplay(), x11::False);
old_handler_ = XSetErrorHandler(X11ErrorHandler); old_handler_ = reinterpret_cast<void*>(XSetErrorHandler(X11ErrorHandler));
g_x11_error_code = 0; g_x11_error_code = 0;
} }
X11ErrorTracker::~X11ErrorTracker() { X11ErrorTracker::~X11ErrorTracker() {
g_handler = nullptr; g_handler = nullptr;
XSetErrorHandler(old_handler_); XSetErrorHandler(reinterpret_cast<XErrorHandler>(old_handler_));
} }
bool X11ErrorTracker::FoundNewError() { bool X11ErrorTracker::FoundNewError() {
XSync(GetXDisplay(), False); XSync(GetXDisplay(), x11::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;
......
...@@ -5,8 +5,6 @@ ...@@ -5,8 +5,6 @@
#ifndef UI_GFX_X_X11_ERROR_TRACKER_H_ #ifndef UI_GFX_X_X11_ERROR_TRACKER_H_
#define UI_GFX_X_X11_ERROR_TRACKER_H_ #define UI_GFX_X_X11_ERROR_TRACKER_H_
#include <X11/Xlib.h>
#include "base/macros.h" #include "base/macros.h"
#include "ui/gfx/gfx_export.h" #include "ui/gfx/gfx_export.h"
...@@ -26,7 +24,10 @@ class GFX_EXPORT X11ErrorTracker { ...@@ -26,7 +24,10 @@ class GFX_EXPORT X11ErrorTracker {
bool FoundNewError(); bool FoundNewError();
private: private:
XErrorHandler old_handler_; // The real type of |old_handler_| is XErrorHandler, or "int
// (*handler)(Display *, XErrorEvent *)". However, XErrorEvent cannot be
// forward declared, so void* is necessary here.
void* old_handler_ = nullptr;
DISALLOW_COPY_AND_ASSIGN(X11ErrorTracker); DISALLOW_COPY_AND_ASSIGN(X11ErrorTracker);
}; };
......
...@@ -4,13 +4,13 @@ ...@@ -4,13 +4,13 @@
#include "ui/gfx/x/x11_types.h" #include "ui/gfx/x/x11_types.h"
#include <X11/Xlib.h>
#include <string.h> #include <string.h>
#include "base/command_line.h" #include "base/command_line.h"
#include "base/logging.h" #include "base/logging.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "ui/gfx/x/connection.h" #include "ui/gfx/x/connection.h"
#include "ui/gfx/x/x11.h"
#include "ui/gfx/x/x11_switches.h" #include "ui/gfx/x/x11_switches.h"
namespace gfx { namespace gfx {
...@@ -24,4 +24,3 @@ XDisplay* CloneXDisplay(XDisplay* display) { ...@@ -24,4 +24,3 @@ XDisplay* CloneXDisplay(XDisplay* display) {
} }
} // namespace gfx } // namespace gfx
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "ui/gfx/gfx_export.h" #include "ui/gfx/gfx_export.h"
#include "ui/gfx/x/connection.h" #include "ui/gfx/x/connection.h"
typedef unsigned long XID;
typedef unsigned long VisualID; typedef unsigned long VisualID;
typedef union _XEvent XEvent; typedef union _XEvent XEvent;
typedef struct _XImage XImage; typedef struct _XImage XImage;
......
...@@ -4,6 +4,12 @@ ...@@ -4,6 +4,12 @@
#include "ui/gfx/x/xproto_internal.h" #include "ui/gfx/x/xproto_internal.h"
#include <stdint.h>
#include <xcb/xcb.h>
#include <xcb/xcbext.h>
#include "ui/gfx/x/x11.h"
// XCB used to send requests with FDs by sending each FD individually with // XCB used to send requests with FDs by sending each FD individually with
// xcb_send_fd(), then the request with xcb_send_request(). However, there's a // xcb_send_fd(), then the request with xcb_send_request(). However, there's a
// race condition -- FDs can get mixed up if multiple threads are sending them // race condition -- FDs can get mixed up if multiple threads are sending them
......
...@@ -9,14 +9,7 @@ ...@@ -9,14 +9,7 @@
#error "This file should only be included by //ui/gfx/x:xprotos" #error "This file should only be included by //ui/gfx/x:xprotos"
#endif #endif
#include <X11/Xlib-xcb.h>
#include <stdint.h>
#include <string.h>
#include <xcb/xcb.h>
#include <xcb/xcbext.h>
#include <bitset> #include <bitset>
#include <limits>
#include <type_traits> #include <type_traits>
#include "base/component_export.h" #include "base/component_export.h"
......
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
#include "ui/gfx/x/xproto_types.h" #include "ui/gfx/x/xproto_types.h"
#include <xcb/xcbext.h>
#include "base/memory/scoped_refptr.h" #include "base/memory/scoped_refptr.h"
#include "ui/gfx/x/connection.h" #include "ui/gfx/x/connection.h"
#include "ui/gfx/x/xproto_internal.h" #include "ui/gfx/x/xproto_internal.h"
...@@ -92,15 +94,8 @@ FutureBase::~FutureBase() { ...@@ -92,15 +94,8 @@ FutureBase::~FutureBase() {
if (!error) if (!error)
return; return;
x11::LogErrorEventDescription(XErrorEvent({ x11::LogErrorEventDescription(error->full_sequence, error->error_code,
.type = error->response_type, error->major_code, error->minor_code);
.display = connection->display(),
.resourceid = error->resource_id,
.serial = error->full_sequence,
.error_code = error->error_code,
.request_code = error->major_code,
.minor_code = error->minor_code,
}));
}, },
connection_)); connection_));
} }
......
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
#define UI_GFX_X_XPROTO_TYPES_H_ #define UI_GFX_X_XPROTO_TYPES_H_
#include <xcb/xcb.h> #include <xcb/xcb.h>
#include <xcb/xcbext.h>
#include <cstdint> #include <cstdint>
#include <memory> #include <memory>
......
...@@ -8,11 +8,15 @@ ...@@ -8,11 +8,15 @@
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "ui/gfx/x/connection.h" #include "ui/gfx/x/connection.h"
#include "ui/gfx/x/x11.h"
#include "ui/gfx/x/xproto.h" #include "ui/gfx/x/xproto.h"
namespace x11 { namespace x11 {
void LogErrorEventDescription(const XErrorEvent& error_event) { void LogErrorEventDescription(unsigned long serial,
uint8_t error_code,
uint8_t request_code,
uint8_t minor_code) {
// This function may make some expensive round trips (XListExtensions, // This function may make some expensive round trips (XListExtensions,
// XQueryExtension), but the only effect this function has is LOG(WARNING), // XQueryExtension), but the only effect this function has is LOG(WARNING),
// so early-return if the log would never be sent anyway. // so early-return if the log would never be sent anyway.
...@@ -22,13 +26,13 @@ void LogErrorEventDescription(const XErrorEvent& error_event) { ...@@ -22,13 +26,13 @@ void LogErrorEventDescription(const XErrorEvent& error_event) {
char error_str[256]; char error_str[256];
char request_str[256]; char request_str[256];
XDisplay* dpy = error_event.display;
x11::Connection* conn = x11::Connection::Get(); x11::Connection* conn = x11::Connection::Get();
XGetErrorText(dpy, error_event.error_code, error_str, sizeof(error_str)); auto* dpy = conn->display();
XGetErrorText(dpy, error_code, error_str, sizeof(error_str));
strncpy(request_str, "Unknown", sizeof(request_str)); strncpy(request_str, "Unknown", sizeof(request_str));
if (error_event.request_code < 128) { if (request_code < 128) {
std::string num = base::NumberToString(error_event.request_code); std::string num = base::NumberToString(request_code);
XGetErrorDatabaseText(dpy, "XRequest", num.c_str(), "Unknown", request_str, XGetErrorDatabaseText(dpy, "XRequest", num.c_str(), "Unknown", request_str,
sizeof(request_str)); sizeof(request_str));
} else { } else {
...@@ -37,9 +41,8 @@ void LogErrorEventDescription(const XErrorEvent& error_event) { ...@@ -37,9 +41,8 @@ void LogErrorEventDescription(const XErrorEvent& error_event) {
int ext_code, first_event, first_error; int ext_code, first_event, first_error;
const char* name = str.name.c_str(); const char* name = str.name.c_str();
XQueryExtension(dpy, name, &ext_code, &first_event, &first_error); XQueryExtension(dpy, name, &ext_code, &first_event, &first_error);
if (error_event.request_code == ext_code) { if (request_code == ext_code) {
std::string msg = std::string msg = base::StringPrintf("%s.%d", name, minor_code);
base::StringPrintf("%s.%d", name, error_event.minor_code);
XGetErrorDatabaseText(dpy, "XRequest", msg.c_str(), "Unknown", XGetErrorDatabaseText(dpy, "XRequest", msg.c_str(), "Unknown",
request_str, sizeof(request_str)); request_str, sizeof(request_str));
break; break;
...@@ -49,13 +52,12 @@ void LogErrorEventDescription(const XErrorEvent& error_event) { ...@@ -49,13 +52,12 @@ void LogErrorEventDescription(const XErrorEvent& error_event) {
} }
LOG(WARNING) << "X error received: " LOG(WARNING) << "X error received: "
<< "serial " << error_event.serial << ", " << "serial " << serial << ", "
<< "error_code " << static_cast<int>(error_event.error_code) << "error_code " << static_cast<int>(error_code) << " ("
<< " (" << error_str << "), " << error_str << "), "
<< "request_code " << static_cast<int>(error_event.request_code) << "request_code " << static_cast<int>(request_code) << ", "
<< ", " << "minor_code " << static_cast<int>(minor_code) << " ("
<< "minor_code " << static_cast<int>(error_event.minor_code) << request_str << ")";
<< " (" << request_str << ")";
} }
} // namespace x11 } // namespace x11
...@@ -5,14 +5,17 @@ ...@@ -5,14 +5,17 @@
#ifndef UI_GFX_X_XPROTO_UTIL_H_ #ifndef UI_GFX_X_XPROTO_UTIL_H_
#define UI_GFX_X_XPROTO_UTIL_H_ #define UI_GFX_X_XPROTO_UTIL_H_
#include <X11/Xlib.h> #include <cstdint>
#include "base/component_export.h" #include "base/component_export.h"
namespace x11 { namespace x11 {
COMPONENT_EXPORT(X11) COMPONENT_EXPORT(X11)
void LogErrorEventDescription(const XErrorEvent& error_event); void LogErrorEventDescription(unsigned long serial,
uint8_t error_code,
uint8_t request_code,
uint8_t minor_code);
} // namespace x11 } // namespace x11
......
...@@ -7,6 +7,10 @@ ...@@ -7,6 +7,10 @@
#include <gdk/gdkx.h> #include <gdk/gdkx.h>
#include <gtk/gtk.h> #include <gtk/gtk.h>
// gdkx.h includes Xlib.h directly, so we need to manually undef any macros
// that conflict with the below includes.
#undef None
#include "base/check.h" #include "base/check.h"
#include "ui/base/x/x11_util.h" #include "ui/base/x/x11_util.h"
#include "ui/events/platform/x11/x11_event_source.h" #include "ui/events/platform/x11/x11_event_source.h"
......
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