Debian Codegraph @

xcb/libqt5xcbqpa-dev/5.9.2/qxcbconnection.h

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