| 1 |
// Copyright (C) 2016 The Qt Company Ltd. |
| 2 |
// |
| 3 |
// SPDX-License-Identifier: LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 4 |
|
| 5 |
#ifndef QXCBCONNECTION_H |
| 6 |
#define QXCBCONNECTION_H |
| 7 |
|
| 8 |
#include <xcb/xcb.h> |
| 9 |
#include <xcb/randr.h> |
| 10 |
|
| 11 |
#include "qxcbexport.h" |
| 12 |
#include <QHash> |
| 13 |
#include <QList> |
| 14 |
#include <QMutex> |
| 15 |
#include <QObject> |
| 16 |
#include <QThread> |
| 17 |
#include <QVector> |
| 18 |
#include <QVarLengthArray> |
| 19 |
#include <qpa/qwindowsysteminterface.h> |
| 20 |
#include <QtCore/QLoggingCategory> |
| 21 |
|
| 22 |
// This is needed to make Qt compile together with XKB. xkb.h is using a variable |
| 23 |
// which is called 'explicit', this is a reserved keyword in c++ |
| 24 |
#ifndef QT_NO_XKB |
| 25 |
#define explicit dont_use_cxx_explicit |
| 26 |
#include <xcb/xkb.h> |
| 27 |
#undef explicit |
| 28 |
#endif |
| 29 |
|
| 30 |
#ifndef QT_NO_TABLETEVENT |
| 31 |
#include <QTabletEvent> |
| 32 |
#endif |
| 33 |
|
| 34 |
#if XCB_USE_XINPUT2 |
| 35 |
#include <X11/extensions/XI2.h> |
| 36 |
#ifdef XIScrollClass |
| 37 |
#define XCB_USE_XINPUT21 // XI 2.1 adds smooth scrolling support |
| 38 |
#ifdef XI_TouchBeginMask |
| 39 |
#define XCB_USE_XINPUT22 // XI 2.2 adds multi-point touch support |
| 40 |
#endif |
| 41 |
#endif |
| 42 |
struct XInput2TouchDeviceData; |
| 43 |
#endif // XCB_USE_XINPUT2 |
| 44 |
|
| 45 |
struct xcb_randr_get_output_info_reply_t; |
| 46 |
|
| 47 |
//#define Q_XCB_DEBUG |
| 48 |
|
| 49 |
QT_BEGIN_NAMESPACE |
| 50 |
|
| 51 |
Q_DECLARE_LOGGING_CATEGORY(lcQpaXInput) |
| 52 |
Q_DECLARE_LOGGING_CATEGORY(lcQpaXInputDevices) |
| 53 |
Q_DECLARE_LOGGING_CATEGORY(lcQpaXInputEvents) |
| 54 |
Q_DECLARE_LOGGING_CATEGORY(lcQpaScreen) |
| 55 |
|
| 56 |
class QXcbVirtualDesktop; |
| 57 |
class QXcbScreen; |
| 58 |
class QXcbWindow; |
| 59 |
class QXcbDrag; |
| 60 |
class QXcbKeyboard; |
| 61 |
class QXcbClipboard; |
| 62 |
class QXcbWMSupport; |
| 63 |
class QXcbNativeInterface; |
| 64 |
class QXcbSystemTrayTracker; |
| 65 |
class QXcbGlIntegration; |
| 66 |
|
| 67 |
namespace QXcbAtom { |
| 68 |
enum Atom { |
| 69 |
// window-manager <-> client protocols |
| 70 |
WM_PROTOCOLS, |
| 71 |
WM_DELETE_WINDOW, |
| 72 |
WM_TAKE_FOCUS, |
| 73 |
_NET_WM_PING, |
| 74 |
_NET_WM_CONTEXT_HELP, |
| 75 |
_NET_WM_SYNC_REQUEST, |
| 76 |
_NET_WM_SYNC_REQUEST_COUNTER, |
| 77 |
MANAGER, // System tray notification |
| 78 |
_NET_SYSTEM_TRAY_OPCODE, // System tray operation |
| 79 |
|
| 80 |
// ICCCM window state |
| 81 |
WM_STATE, |
| 82 |
WM_CHANGE_STATE, |
| 83 |
WM_CLASS, |
| 84 |
WM_NAME, |
| 85 |
|
| 86 |
// Session management |
| 87 |
WM_CLIENT_LEADER, |
| 88 |
WM_WINDOW_ROLE, |
| 89 |
SM_CLIENT_ID, |
| 90 |
|
| 91 |
// Clipboard |
| 92 |
CLIPBOARD, |
| 93 |
INCR, |
| 94 |
TARGETS, |
| 95 |
MULTIPLE, |
| 96 |
TIMESTAMP, |
| 97 |
SAVE_TARGETS, |
| 98 |
CLIP_TEMPORARY, |
| 99 |
_QT_SELECTION, |
| 100 |
_QT_CLIPBOARD_SENTINEL, |
| 101 |
_QT_SELECTION_SENTINEL, |
| 102 |
CLIPBOARD_MANAGER, |
| 103 |
|
| 104 |
RESOURCE_MANAGER, |
| 105 |
|
| 106 |
_XSETROOT_ID, |
| 107 |
|
| 108 |
_QT_SCROLL_DONE, |
| 109 |
_QT_INPUT_ENCODING, |
| 110 |
|
| 111 |
// Qt/XCB specific |
| 112 |
_QT_CLOSE_CONNECTION, |
| 113 |
|
| 114 |
_MOTIF_WM_HINTS, |
| 115 |
|
| 116 |
DTWM_IS_RUNNING, |
| 117 |
ENLIGHTENMENT_DESKTOP, |
| 118 |
_DT_SAVE_MODE, |
| 119 |
_SGI_DESKS_MANAGER, |
| 120 |
|
| 121 |
// EWMH (aka NETWM) |
| 122 |
_NET_SUPPORTED, |
| 123 |
_NET_VIRTUAL_ROOTS, |
| 124 |
_NET_WORKAREA, |
| 125 |
|
| 126 |
_NET_MOVERESIZE_WINDOW, |
| 127 |
_NET_WM_MOVERESIZE, |
| 128 |
|
| 129 |
_NET_WM_NAME, |
| 130 |
_NET_WM_ICON_NAME, |
| 131 |
_NET_WM_ICON, |
| 132 |
|
| 133 |
_NET_WM_PID, |
| 134 |
|
| 135 |
_NET_WM_WINDOW_OPACITY, |
| 136 |
|
| 137 |
_NET_WM_STATE, |
| 138 |
_NET_WM_STATE_ABOVE, |
| 139 |
_NET_WM_STATE_BELOW, |
| 140 |
_NET_WM_STATE_FULLSCREEN, |
| 141 |
_NET_WM_STATE_MAXIMIZED_HORZ, |
| 142 |
_NET_WM_STATE_MAXIMIZED_VERT, |
| 143 |
_NET_WM_STATE_MODAL, |
| 144 |
_NET_WM_STATE_STAYS_ON_TOP, |
| 145 |
_NET_WM_STATE_DEMANDS_ATTENTION, |
| 146 |
|
| 147 |
_NET_WM_USER_TIME, |
| 148 |
_NET_WM_USER_TIME_WINDOW, |
| 149 |
_NET_WM_FULL_PLACEMENT, |
| 150 |
|
| 151 |
_NET_WM_WINDOW_TYPE, |
| 152 |
_NET_WM_WINDOW_TYPE_DESKTOP, |
| 153 |
_NET_WM_WINDOW_TYPE_DOCK, |
| 154 |
_NET_WM_WINDOW_TYPE_TOOLBAR, |
| 155 |
_NET_WM_WINDOW_TYPE_MENU, |
| 156 |
_NET_WM_WINDOW_TYPE_UTILITY, |
| 157 |
_NET_WM_WINDOW_TYPE_SPLASH, |
| 158 |
_NET_WM_WINDOW_TYPE_DIALOG, |
| 159 |
_NET_WM_WINDOW_TYPE_DROPDOWN_MENU, |
| 160 |
_NET_WM_WINDOW_TYPE_POPUP_MENU, |
| 161 |
_NET_WM_WINDOW_TYPE_TOOLTIP, |
| 162 |
_NET_WM_WINDOW_TYPE_NOTIFICATION, |
| 163 |
_NET_WM_WINDOW_TYPE_COMBO, |
| 164 |
_NET_WM_WINDOW_TYPE_DND, |
| 165 |
_NET_WM_WINDOW_TYPE_NORMAL, |
| 166 |
_KDE_NET_WM_WINDOW_TYPE_OVERRIDE, |
| 167 |
|
| 168 |
_KDE_NET_WM_FRAME_STRUT, |
| 169 |
_NET_FRAME_EXTENTS, |
| 170 |
|
| 171 |
_NET_STARTUP_INFO, |
| 172 |
_NET_STARTUP_INFO_BEGIN, |
| 173 |
|
| 174 |
_NET_SUPPORTING_WM_CHECK, |
| 175 |
|
| 176 |
_NET_WM_CM_S0, |
| 177 |
|
| 178 |
_NET_SYSTEM_TRAY_VISUAL, |
| 179 |
|
| 180 |
_NET_ACTIVE_WINDOW, |
| 181 |
|
| 182 |
// Property formats |
| 183 |
TEXT, |
| 184 |
UTF8_STRING, |
| 185 |
CARDINAL, |
| 186 |
|
| 187 |
// Xdnd |
| 188 |
XdndEnter, |
| 189 |
XdndPosition, |
| 190 |
XdndStatus, |
| 191 |
XdndLeave, |
| 192 |
XdndDrop, |
| 193 |
XdndFinished, |
| 194 |
XdndTypelist, |
| 195 |
XdndActionList, |
| 196 |
|
| 197 |
XdndSelection, |
| 198 |
|
| 199 |
XdndAware, |
| 200 |
XdndProxy, |
| 201 |
|
| 202 |
XdndActionCopy, |
| 203 |
XdndActionLink, |
| 204 |
XdndActionMove, |
| 205 |
XdndActionPrivate, |
| 206 |
|
| 207 |
// Motif DND |
| 208 |
_MOTIF_DRAG_AND_DROP_MESSAGE, |
| 209 |
_MOTIF_DRAG_INITIATOR_INFO, |
| 210 |
_MOTIF_DRAG_RECEIVER_INFO, |
| 211 |
_MOTIF_DRAG_WINDOW, |
| 212 |
_MOTIF_DRAG_TARGETS, |
| 213 |
|
| 214 |
XmTRANSFER_SUCCESS, |
| 215 |
XmTRANSFER_FAILURE, |
| 216 |
|
| 217 |
// Xkb |
| 218 |
_XKB_RULES_NAMES, |
| 219 |
|
| 220 |
// XEMBED |
| 221 |
_XEMBED, |
| 222 |
_XEMBED_INFO, |
| 223 |
|
| 224 |
// XInput2 |
| 225 |
ButtonLeft, |
| 226 |
ButtonMiddle, |
| 227 |
ButtonRight, |
| 228 |
ButtonWheelUp, |
| 229 |
ButtonWheelDown, |
| 230 |
ButtonHorizWheelLeft, |
| 231 |
ButtonHorizWheelRight, |
| 232 |
AbsMTPositionX, |
| 233 |
AbsMTPositionY, |
| 234 |
AbsMTTouchMajor, |
| 235 |
AbsMTTouchMinor, |
| 236 |
AbsMTOrientation, |
| 237 |
AbsMTPressure, |
| 238 |
AbsMTTrackingID, |
| 239 |
MaxContacts, |
| 240 |
RelX, |
| 241 |
RelY, |
| 242 |
// XInput2 tablet |
| 243 |
AbsX, |
| 244 |
AbsY, |
| 245 |
AbsPressure, |
| 246 |
AbsTiltX, |
| 247 |
AbsTiltY, |
| 248 |
AbsWheel, |
| 249 |
AbsDistance, |
| 250 |
WacomSerialIDs, |
| 251 |
INTEGER, |
| 252 |
RelHorizWheel, |
| 253 |
RelVertWheel, |
| 254 |
RelHorizScroll, |
| 255 |
RelVertScroll, |
| 256 |
|
| 257 |
_XSETTINGS_SETTINGS, |
| 258 |
|
| 259 |
_COMPIZ_DECOR_PENDING, |
| 260 |
_COMPIZ_DECOR_REQUEST, |
| 261 |
_COMPIZ_DECOR_DELETE_PIXMAP, |
| 262 |
_COMPIZ_TOOLKIT_ACTION, |
| 263 |
_GTK_LOAD_ICONTHEMES, |
| 264 |
|
| 265 |
NPredefinedAtoms, |
| 266 |
|
| 267 |
_QT_SETTINGS_TIMESTAMP = NPredefinedAtoms, |
| 268 |
NAtoms |
| 269 |
}; |
| 270 |
} |
| 271 |
|
| 272 |
typedef QVarLengthArray<xcb_generic_event_t *, 64> QXcbEventArray; |
| 273 |
|
| 274 |
class QXcbConnection; |
| 275 |
class QXcbEventReader : public QThread |
| 276 |
{ |
| 277 |
Q_OBJECT |
| 278 |
public: |
| 279 |
QXcbEventReader(QXcbConnection *connection); |
| 280 |
|
| 281 |
void run() Q_DECL_OVERRIDE; |
| 282 |
|
| 283 |
QXcbEventArray *lock(); |
| 284 |
void unlock(); |
| 285 |
|
| 286 |
void start(); |
| 287 |
|
| 288 |
void registerEventDispatcher(QAbstractEventDispatcher *dispatcher); |
| 289 |
|
| 290 |
signals: |
| 291 |
void eventPending(); |
| 292 |
|
| 293 |
private slots: |
| 294 |
void registerForEvents(); |
| 295 |
|
| 296 |
private: |
| 297 |
void addEvent(xcb_generic_event_t *event); |
| 298 |
|
| 299 |
QMutex m_mutex; |
| 300 |
QXcbEventArray m_events; |
| 301 |
QXcbConnection *m_connection; |
| 302 |
}; |
| 303 |
|
| 304 |
class QXcbWindowEventListener |
| 305 |
{ |
| 306 |
public: |
| 307 |
virtual ~QXcbWindowEventListener() {} |
| 308 |
virtual bool handleGenericEvent(xcb_generic_event_t *, long *) { return false; } |
| 309 |
|
| 310 |
virtual void handleExposeEvent(const xcb_expose_event_t *) {} |
| 311 |
virtual void handleClientMessageEvent(const xcb_client_message_event_t *) {} |
| 312 |
virtual void handleConfigureNotifyEvent(const xcb_configure_notify_event_t *) {} |
| 313 |
virtual void handleMapNotifyEvent(const xcb_map_notify_event_t *) {} |
| 314 |
virtual void handleUnmapNotifyEvent(const xcb_unmap_notify_event_t *) {} |
| 315 |
virtual void handleDestroyNotifyEvent(const xcb_destroy_notify_event_t *) {} |
| 316 |
virtual void handleButtonPressEvent(const xcb_button_press_event_t *) {} |
| 317 |
virtual void handleButtonReleaseEvent(const xcb_button_release_event_t *) {} |
| 318 |
virtual void handleMotionNotifyEvent(const xcb_motion_notify_event_t *) {} |
| 319 |
virtual void handleEnterNotifyEvent(const xcb_enter_notify_event_t *) {} |
| 320 |
virtual void handleLeaveNotifyEvent(const xcb_leave_notify_event_t *) {} |
| 321 |
virtual void handleFocusInEvent(const xcb_focus_in_event_t *) {} |
| 322 |
virtual void handleFocusOutEvent(const xcb_focus_out_event_t *) {} |
| 323 |
virtual void handlePropertyNotifyEvent(const xcb_property_notify_event_t *) {} |
| 324 |
#ifdef XCB_USE_XINPUT22 |
| 325 |
virtual void handleXIMouseEvent(xcb_ge_event_t *, Qt::MouseEventSource = Qt::MouseEventNotSynthesized) {} |
| 326 |
virtual void handleXIEnterLeave(xcb_ge_event_t *) {} |
| 327 |
#endif |
| 328 |
virtual QXcbWindow *toWindow() { return 0; } |
| 329 |
}; |
| 330 |
|
| 331 |
typedef QHash<xcb_window_t, QXcbWindowEventListener *> WindowMapper; |
| 332 |
|
| 333 |
class QXcbSyncWindowRequest : public QEvent |
| 334 |
{ |
| 335 |
public: |
| 336 |
QXcbSyncWindowRequest(QXcbWindow *w) : QEvent(QEvent::Type(QEvent::User + 1)), m_window(w) { } |
| 337 |
|
| 338 |
QXcbWindow *window() const { return m_window; } |
| 339 |
void invalidate(); |
| 340 |
|
| 341 |
private: |
| 342 |
QXcbWindow *m_window; |
| 343 |
}; |
| 344 |
|
| 345 |
class QAbstractEventDispatcher; |
| 346 |
class Q_XCB_EXPORT QXcbConnection : public QObject |
| 347 |
{ |
| 348 |
Q_OBJECT |
| 349 |
public: |
| 350 |
QXcbConnection(QXcbNativeInterface *nativeInterface, bool canGrabServer, xcb_visualid_t defaultVisualId, const char *displayName = 0); |
| 351 |
~QXcbConnection(); |
| 352 |
|
| 353 |
QXcbConnection *connection() const { return const_cast<QXcbConnection *>(this); } |
| 354 |
|
| 355 |
const QList<QXcbVirtualDesktop *> &virtualDesktops() const { return m_virtualDesktops; } |
| 356 |
const QList<QXcbScreen *> &screens() const { return m_screens; } |
| 357 |
int primaryScreenNumber() const { return m_primaryScreenNumber; } |
| 358 |
QXcbVirtualDesktop *primaryVirtualDesktop() const { return m_virtualDesktops.value(m_primaryScreenNumber); } |
| 359 |
QXcbScreen *primaryScreen() const; |
| 360 |
|
| 361 |
inline xcb_atom_t atom(QXcbAtom::Atom atom) const { return m_allAtoms[atom]; } |
| 362 |
QXcbAtom::Atom qatom(xcb_atom_t atom) const; |
| 363 |
xcb_atom_t internAtom(const char *name); |
| 364 |
QByteArray atomName(xcb_atom_t atom); |
| 365 |
|
| 366 |
const char *displayName() const { return m_displayName.constData(); } |
| 367 |
xcb_connection_t *xcb_connection() const { return m_connection; } |
| 368 |
const xcb_setup_t *setup() const { return m_setup; } |
| 369 |
const xcb_format_t *formatForDepth(uint8_t depth) const; |
| 370 |
|
| 371 |
QXcbKeyboard *keyboard() const { return m_keyboard; } |
| 372 |
|
| 373 |
#ifndef QT_NO_CLIPBOARD |
| 374 |
QXcbClipboard *clipboard() const { return m_clipboard; } |
| 375 |
#endif |
| 376 |
#ifndef QT_NO_DRAGANDDROP |
| 377 |
QXcbDrag *drag() const { return m_drag; } |
| 378 |
#endif |
| 379 |
|
| 380 |
QXcbWMSupport *wmSupport() const { return m_wmSupport.data(); } |
| 381 |
xcb_window_t rootWindow(); |
| 382 |
xcb_window_t clientLeader(); |
| 383 |
|
| 384 |
bool hasDefaultVisualId() const { return m_defaultVisualId != UINT_MAX; } |
| 385 |
xcb_visualid_t defaultVisualId() const { return m_defaultVisualId; } |
| 386 |
|
| 387 |
#ifdef XCB_USE_XLIB |
| 388 |
void *xlib_display() const; |
| 389 |
void *createVisualInfoForDefaultVisualId() const; |
| 390 |
#endif |
| 391 |
|
| 392 |
#if defined(XCB_USE_XINPUT2) |
| 393 |
void xi2Select(xcb_window_t window); |
| 394 |
#endif |
| 395 |
#ifdef XCB_USE_XINPUT21 |
| 396 |
bool isAtLeastXI21() const { return m_xi2Enabled && m_xi2Minor >= 1; } |
| 397 |
#else |
| 398 |
bool isAtLeastXI21() const { return false; } |
| 399 |
#endif |
| 400 |
#ifdef XCB_USE_XINPUT22 |
| 401 |
bool isAtLeastXI22() const { return m_xi2Enabled && m_xi2Minor >= 2; } |
| 402 |
#else |
| 403 |
bool isAtLeastXI22() const { return false; } |
| 404 |
#endif |
| 405 |
|
| 406 |
void sync(); |
| 407 |
|
| 408 |
void handleXcbError(xcb_generic_error_t *error); |
| 409 |
void handleXcbEvent(xcb_generic_event_t *event); |
| 410 |
|
| 411 |
void addWindowEventListener(xcb_window_t id, QXcbWindowEventListener *eventListener); |
| 412 |
void removeWindowEventListener(xcb_window_t id); |
| 413 |
QXcbWindowEventListener *windowEventListenerFromId(xcb_window_t id); |
| 414 |
QXcbWindow *platformWindowFromId(xcb_window_t id); |
| 415 |
|
| 416 |
xcb_generic_event_t *checkEvent(int type); |
| 417 |
template<typename T> |
| 418 |
inline xcb_generic_event_t *checkEvent(T &checker); |
| 419 |
|
| 420 |
typedef bool (*PeekFunc)(QXcbConnection *, xcb_generic_event_t *); |
| 421 |
void addPeekFunc(PeekFunc f); |
| 422 |
|
| 423 |
inline xcb_timestamp_t time() const { return m_time; } |
| 424 |
inline void setTime(xcb_timestamp_t t) { if (t > m_time) m_time = t; } |
| 425 |
|
| 426 |
inline xcb_timestamp_t netWmUserTime() const { return m_netWmUserTime; } |
| 427 |
inline void setNetWmUserTime(xcb_timestamp_t t) { if (t > m_netWmUserTime) m_netWmUserTime = t; } |
| 428 |
|
| 429 |
bool hasXFixes() const { return xfixes_first_event > 0; } |
| 430 |
bool hasXShape() const { return has_shape_extension; } |
| 431 |
bool hasXRandr() const { return has_randr_extension; } |
| 432 |
bool hasInputShape() const { return has_input_shape; } |
| 433 |
bool hasXKB() const { return has_xkb; } |
| 434 |
|
| 435 |
bool supportsThreadedRendering() const { return m_reader->isRunning(); } |
| 436 |
bool threadedEventHandling() const { return m_reader->isRunning(); } |
| 437 |
|
| 438 |
xcb_timestamp_t getTimestamp(); |
| 439 |
xcb_window_t getSelectionOwner(xcb_atom_t atom) const; |
| 440 |
xcb_window_t getQtSelectionOwner(); |
| 441 |
|
| 442 |
void setButton(Qt::MouseButton button, bool down) { m_buttons.setFlag(button, down); } |
| 443 |
Qt::MouseButtons buttons() const { return m_buttons; } |
| 444 |
Qt::MouseButton translateMouseButton(xcb_button_t s); |
| 445 |
|
| 446 |
QXcbWindow *focusWindow() const { return m_focusWindow; } |
| 447 |
void setFocusWindow(QXcbWindow *); |
| 448 |
QXcbWindow *mouseGrabber() const { return m_mouseGrabber; } |
| 449 |
void setMouseGrabber(QXcbWindow *); |
| 450 |
QXcbWindow *mousePressWindow() const { return m_mousePressWindow; } |
| 451 |
void setMousePressWindow(QXcbWindow *); |
| 452 |
|
| 453 |
QByteArray startupId() const { return m_startupId; } |
| 454 |
void setStartupId(const QByteArray &nextId) { m_startupId = nextId; } |
| 455 |
void clearStartupId() { m_startupId.clear(); } |
| 456 |
|
| 457 |
void grabServer(); |
| 458 |
void ungrabServer(); |
| 459 |
|
| 460 |
QXcbNativeInterface *nativeInterface() const { return m_nativeInterface; } |
| 461 |
|
| 462 |
QXcbSystemTrayTracker *systemTrayTracker() const; |
| 463 |
static bool xEmbedSystemTrayAvailable(); |
| 464 |
static bool xEmbedSystemTrayVisualHasAlphaChannel(); |
| 465 |
|
| 466 |
#ifdef XCB_USE_XINPUT21 |
| 467 |
void handleEnterEvent(); |
| 468 |
#endif |
| 469 |
|
| 470 |
#ifdef XCB_USE_XINPUT22 |
| 471 |
bool xi2SetMouseGrabEnabled(xcb_window_t w, bool grab); |
| 472 |
#endif |
| 473 |
Qt::MouseButton xiToQtMouseButton(uint32_t b); |
| 474 |
|
| 475 |
QXcbEventReader *eventReader() const { return m_reader; } |
| 476 |
|
| 477 |
bool canGrab() const { return m_canGrabServer; } |
| 478 |
|
| 479 |
QXcbGlIntegration *glIntegration() const { return m_glIntegration; } |
| 480 |
|
| 481 |
#ifdef XCB_USE_XINPUT22 |
| 482 |
bool xi2MouseEvents() const; |
| 483 |
#endif |
| 484 |
|
| 485 |
protected: |
| 486 |
bool event(QEvent *e) Q_DECL_OVERRIDE; |
| 487 |
|
| 488 |
public slots: |
| 489 |
void flush() { xcb_flush(m_connection); } |
| 490 |
|
| 491 |
private slots: |
| 492 |
void processXcbEvents(); |
| 493 |
|
| 494 |
private: |
| 495 |
void initializeAllAtoms(); |
| 496 |
void sendConnectionEvent(QXcbAtom::Atom atom, uint id = 0); |
| 497 |
void initializeXFixes(); |
| 498 |
void initializeXRender(); |
| 499 |
void initializeXRandr(); |
| 500 |
void initializeXinerama(); |
| 501 |
void initializeXShape(); |
| 502 |
void initializeXKB(); |
| 503 |
void handleClientMessageEvent(const xcb_client_message_event_t *event); |
| 504 |
QXcbScreen* findScreenForCrtc(xcb_window_t rootWindow, xcb_randr_crtc_t crtc) const; |
| 505 |
QXcbScreen* findScreenForOutput(xcb_window_t rootWindow, xcb_randr_output_t output) const; |
| 506 |
QXcbVirtualDesktop* virtualDesktopForRootWindow(xcb_window_t rootWindow) const; |
| 507 |
void updateScreens(const xcb_randr_notify_event_t *event); |
| 508 |
bool checkOutputIsPrimary(xcb_window_t rootWindow, xcb_randr_output_t output); |
| 509 |
void updateScreen(QXcbScreen *screen, const xcb_randr_output_change_t &outputChange); |
| 510 |
QXcbScreen *createScreen(QXcbVirtualDesktop *virtualDesktop, |
| 511 |
const xcb_randr_output_change_t &outputChange, |
| 512 |
xcb_randr_get_output_info_reply_t *outputInfo); |
| 513 |
void destroyScreen(QXcbScreen *screen); |
| 514 |
void initializeScreens(); |
| 515 |
bool compressEvent(xcb_generic_event_t *event, int currentIndex, QXcbEventArray *eventqueue) const; |
| 516 |
|
| 517 |
#ifdef XCB_USE_XINPUT2 |
| 518 |
bool m_xi2Enabled; |
| 519 |
int m_xi2Minor; |
| 520 |
void initializeXInput2(); |
| 521 |
void finalizeXInput2(); |
| 522 |
void xi2SetupDevices(); |
| 523 |
XInput2TouchDeviceData *touchDeviceForId(int id); |
| 524 |
void xi2HandleEvent(xcb_ge_event_t *event); |
| 525 |
void xi2HandleHierachyEvent(void *event); |
| 526 |
void xi2HandleDeviceChangedEvent(void *event); |
| 527 |
int m_xiOpCode, m_xiEventBase, m_xiErrorBase; |
| 528 |
#ifdef XCB_USE_XINPUT22 |
| 529 |
void xi2ProcessTouch(void *xiDevEvent, QXcbWindow *platformWindow); |
| 530 |
#endif // XCB_USE_XINPUT22 |
| 531 |
#ifndef QT_NO_TABLETEVENT |
| 532 |
struct TabletData { |
| 533 |
TabletData() : deviceId(0), pointerType(QTabletEvent::UnknownPointer), |
| 534 |
tool(QTabletEvent::Stylus), buttons(0), serialId(0), inProximity(false) { } |
| 535 |
int deviceId; |
| 536 |
QTabletEvent::PointerType pointerType; |
| 537 |
QTabletEvent::TabletDevice tool; |
| 538 |
Qt::MouseButtons buttons; |
| 539 |
qint64 serialId; |
| 540 |
bool inProximity; |
| 541 |
struct ValuatorClassInfo { |
| 542 |
ValuatorClassInfo() : minVal(0.), maxVal(0.), curVal(0.) { } |
| 543 |
double minVal; |
| 544 |
double maxVal; |
| 545 |
double curVal; |
| 546 |
int number; |
| 547 |
}; |
| 548 |
QHash<int, ValuatorClassInfo> valuatorInfo; |
| 549 |
}; |
| 550 |
bool xi2HandleTabletEvent(const void *event, TabletData *tabletData); |
| 551 |
void xi2ReportTabletEvent(const void *event, TabletData *tabletData); |
| 552 |
QVector<TabletData> m_tabletData; |
| 553 |
TabletData *tabletDataForDevice(int id); |
| 554 |
#endif // !QT_NO_TABLETEVENT |
| 555 |
struct ScrollingDevice { |
| 556 |
ScrollingDevice() : deviceId(0), verticalIndex(0), horizontalIndex(0), orientations(0), legacyOrientations(0) { } |
| 557 |
int deviceId; |
| 558 |
int verticalIndex, horizontalIndex; |
| 559 |
double verticalIncrement, horizontalIncrement; |
| 560 |
Qt::Orientations orientations; |
| 561 |
Qt::Orientations legacyOrientations; |
| 562 |
QPointF lastScrollPosition; |
| 563 |
}; |
| 564 |
void updateScrollingDevice(ScrollingDevice& scrollingDevice, int num_classes, void *classes); |
| 565 |
void xi2HandleScrollEvent(void *event, ScrollingDevice &scrollingDevice); |
| 566 |
QHash<int, ScrollingDevice> m_scrollingDevices; |
| 567 |
|
| 568 |
static bool xi2GetValuatorValueIfSet(const void *event, int valuatorNum, double *value); |
| 569 |
static void xi2PrepareXIGenericDeviceEvent(xcb_ge_event_t *event); |
| 570 |
#endif |
| 571 |
|
| 572 |
xcb_connection_t *m_connection; |
| 573 |
const xcb_setup_t *m_setup; |
| 574 |
bool m_canGrabServer; |
| 575 |
xcb_visualid_t m_defaultVisualId; |
| 576 |
|
| 577 |
QList<QXcbVirtualDesktop *> m_virtualDesktops; |
| 578 |
QList<QXcbScreen *> m_screens; |
| 579 |
int m_primaryScreenNumber; |
| 580 |
|
| 581 |
xcb_atom_t m_allAtoms[QXcbAtom::NAtoms]; |
| 582 |
|
| 583 |
xcb_timestamp_t m_time; |
| 584 |
xcb_timestamp_t m_netWmUserTime; |
| 585 |
|
| 586 |
QByteArray m_displayName; |
| 587 |
|
| 588 |
QXcbKeyboard *m_keyboard; |
| 589 |
#ifndef QT_NO_CLIPBOARD |
| 590 |
QXcbClipboard *m_clipboard; |
| 591 |
#endif |
| 592 |
#ifndef QT_NO_DRAGANDDROP |
| 593 |
QXcbDrag *m_drag; |
| 594 |
#endif |
| 595 |
QScopedPointer<QXcbWMSupport> m_wmSupport; |
| 596 |
QXcbNativeInterface *m_nativeInterface; |
| 597 |
|
| 598 |
#if defined(XCB_USE_XLIB) |
| 599 |
void *m_xlib_display; |
| 600 |
#endif |
| 601 |
QXcbEventReader *m_reader; |
| 602 |
#if defined(XCB_USE_XINPUT2) |
| 603 |
QHash<int, XInput2TouchDeviceData*> m_touchDevices; |
| 604 |
#endif |
| 605 |
#ifdef Q_XCB_DEBUG |
| 606 |
struct CallInfo { |
| 607 |
int sequence; |
| 608 |
QByteArray file; |
| 609 |
int line; |
| 610 |
}; |
| 611 |
QVector<CallInfo> m_callLog; |
| 612 |
QMutex m_callLogMutex; |
| 613 |
void log(const char *file, int line, int sequence); |
| 614 |
template <typename cookie_t> |
| 615 |
friend cookie_t q_xcb_call_template(const cookie_t &cookie, QXcbConnection *connection, |
| 616 |
const char *file, int line); |
| 617 |
template <typename reply_t> |
| 618 |
friend reply_t *q_xcb_call_template(reply_t *reply, QXcbConnection *connection, |
| 619 |
const char *file, int line); |
| 620 |
#endif |
| 621 |
|
| 622 |
WindowMapper m_mapper; |
| 623 |
|
| 624 |
QVector<PeekFunc> m_peekFuncs; |
| 625 |
|
| 626 |
uint32_t xfixes_first_event; |
| 627 |
uint32_t xrandr_first_event; |
| 628 |
uint32_t xkb_first_event; |
| 629 |
|
| 630 |
bool has_xinerama_extension; |
| 631 |
bool has_shape_extension; |
| 632 |
bool has_randr_extension; |
| 633 |
bool has_input_shape; |
| 634 |
bool has_xkb; |
| 635 |
|
| 636 |
Qt::MouseButtons m_buttons; |
| 637 |
|
| 638 |
QXcbWindow *m_focusWindow; |
| 639 |
QXcbWindow *m_mouseGrabber; |
| 640 |
QXcbWindow *m_mousePressWindow; |
| 641 |
|
| 642 |
xcb_window_t m_clientLeader; |
| 643 |
QByteArray m_startupId; |
| 644 |
QXcbSystemTrayTracker *m_systemTrayTracker; |
| 645 |
QXcbGlIntegration *m_glIntegration; |
| 646 |
bool m_xiGrab; |
| 647 |
|
| 648 |
xcb_window_t m_qtSelectionOwner; |
| 649 |
|
| 650 |
friend class QXcbEventReader; |
| 651 |
}; |
| 652 |
|
| 653 |
#define DISPLAY_FROM_XCB(object) ((Display *)(object->connection()->xlib_display())) |
| 654 |
#define CREATE_VISUALINFO_FROM_DEFAULT_VISUALID(object) ((XVisualInfo *)(object->connection()->createVisualInfoForDefaultVisualId())) |
| 655 |
|
| 656 |
template<typename T> |
| 657 |
xcb_generic_event_t *QXcbConnection::checkEvent(T &checker) |
| 658 |
{ |
| 659 |
QXcbEventArray *eventqueue = m_reader->lock(); |
| 660 |
|
| 661 |
for (int i = 0; i < eventqueue->size(); ++i) { |
| 662 |
xcb_generic_event_t *event = eventqueue->at(i); |
| 663 |
if (checker.checkEvent(event)) { |
| 664 |
(*eventqueue)[i] = 0; |
| 665 |
m_reader->unlock(); |
| 666 |
return event; |
| 667 |
} |
| 668 |
} |
| 669 |
m_reader->unlock(); |
| 670 |
return 0; |
| 671 |
} |
| 672 |
|
| 673 |
class QXcbConnectionGrabber |
| 674 |
{ |
| 675 |
public: |
| 676 |
QXcbConnectionGrabber(QXcbConnection *connection); |
| 677 |
~QXcbConnectionGrabber(); |
| 678 |
void release(); |
| 679 |
private: |
| 680 |
QXcbConnection *m_connection; |
| 681 |
}; |
| 682 |
|
| 683 |
#ifdef Q_XCB_DEBUG |
| 684 |
template <typename cookie_t> |
| 685 |
cookie_t q_xcb_call_template(const cookie_t &cookie, QXcbConnection *connection, const char *file, |
| 686 |
int line) |
| 687 |
{ |
| 688 |
connection->log(file, line, cookie.sequence); |
| 689 |
return cookie; |
| 690 |
} |
| 691 |
|
| 692 |
template <typename reply_t> |
| 693 |
reply_t *q_xcb_call_template(reply_t *reply, QXcbConnection *connection, const char *file, int line) |
| 694 |
{ |
| 695 |
connection->log(file, line, reply->sequence); |
| 696 |
return reply; |
| 697 |
} |
| 698 |
#define Q_XCB_CALL(x) q_xcb_call_template(x, connection(), __FILE__, __LINE__) |
| 699 |
#define Q_XCB_CALL2(x, connection) q_xcb_call_template(x, connection, __FILE__, __LINE__) |
| 700 |
#define Q_XCB_NOOP(c) q_xcb_call_template(xcb_no_operation(c->xcb_connection()), c, __FILE__, __LINE__); |
| 701 |
#else |
| 702 |
#define Q_XCB_CALL(x) x |
| 703 |
#define Q_XCB_CALL2(x, connection) x |
| 704 |
#define Q_XCB_NOOP(c) (void)c; |
| 705 |
#endif |
| 706 |
|
| 707 |
QT_END_NAMESPACE |
| 708 |
|
| 709 |
#endif |