Debian Codegraph @

xcb/libqt5xcbqpa-dev/5.9.0/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 #ifndef QT_NO_TABLETEVENT
33 #include <QTabletEvent>
34 #endif
35
36 #if XCB_USE_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 // XCB_USE_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
357 const QList<QXcbVirtualDesktop *> &virtualDesktops() const { return m_virtualDesktops; }
358 const QList<QXcbScreen *> &screens() const { return m_screens; }
359 int primaryScreenNumber() const { return m_primaryScreenNumber; }
360 QXcbVirtualDesktop *primaryVirtualDesktop() const { return m_virtualDesktops.value(m_primaryScreenNumber); }
361 QXcbScreen *primaryScreen() const;
362
363 inline xcb_atom_t atom(QXcbAtom::Atom atom) const { return m_allAtoms[atom]; }
364 QXcbAtom::Atom qatom(xcb_atom_t atom) const;
365 xcb_atom_t internAtom(const char *name);
366 QByteArray atomName(xcb_atom_t atom);
367
368 const char *displayName() const { return m_displayName.constData(); }
369 xcb_connection_t *xcb_connection() const { return m_connection; }
370 const xcb_setup_t *setup() const { return m_setup; }
371 const xcb_format_t *formatForDepth(uint8_t depth) const;
372
373 QXcbKeyboard *keyboard() const { return m_keyboard; }
374
375 #ifndef QT_NO_CLIPBOARD
376 QXcbClipboard *clipboard() const { return m_clipboard; }
377 #endif
378 #ifndef QT_NO_DRAGANDDROP
379 QXcbDrag *drag() const { return m_drag; }
380 #endif
381
382 QXcbWMSupport *wmSupport() const { return m_wmSupport.data(); }
383 xcb_window_t rootWindow();
384 xcb_window_t clientLeader();
385
386 bool hasDefaultVisualId() const { return m_defaultVisualId != UINT_MAX; }
387 xcb_visualid_t defaultVisualId() const { return m_defaultVisualId; }
388
389 #ifdef XCB_USE_XLIB
390 void *xlib_display() const;
391 void *createVisualInfoForDefaultVisualId() const;
392 #endif
393
394 #if defined(XCB_USE_XINPUT2)
395 void xi2Select(xcb_window_t window);
396 #endif
397 #ifdef XCB_USE_XINPUT21
398 bool isAtLeastXI21() const { return m_xi2Enabled && m_xi2Minor >= 1; }
399 #else
400 bool isAtLeastXI21() const { return false; }
401 #endif
402 #ifdef XCB_USE_XINPUT22
403 bool isAtLeastXI22() const { return m_xi2Enabled && m_xi2Minor >= 2; }
404 #else
405 bool isAtLeastXI22() const { return false; }
406 #endif
407
408 void sync();
409
410 void handleXcbError(xcb_generic_error_t *error);
411 void handleXcbEvent(xcb_generic_event_t *event);
412
413 void addWindowEventListener(xcb_window_t id, QXcbWindowEventListener *eventListener);
414 void removeWindowEventListener(xcb_window_t id);
415 QXcbWindowEventListener *windowEventListenerFromId(xcb_window_t id);
416 QXcbWindow *platformWindowFromId(xcb_window_t id);
417
418 template<typename T>
419 inline xcb_generic_event_t *checkEvent(T &checker);
420
421 typedef bool (*PeekFunc)(QXcbConnection *, xcb_generic_event_t *);
422 void addPeekFunc(PeekFunc f);
423
424 inline xcb_timestamp_t time() const { return m_time; }
425 inline void setTime(xcb_timestamp_t t) { if (t > m_time) m_time = t; }
426
427 inline xcb_timestamp_t netWmUserTime() const { return m_netWmUserTime; }
428 inline void setNetWmUserTime(xcb_timestamp_t t) { if (t > m_netWmUserTime) m_netWmUserTime = t; }
429
430 bool hasXFixes() const { return xfixes_first_event > 0; }
431 bool hasXShape() const { return has_shape_extension; }
432 bool hasXRandr() const { return has_randr_extension; }
433 bool hasInputShape() const { return has_input_shape; }
434 bool hasXKB() const { return has_xkb; }
435
436 bool supportsThreadedRendering() const { return m_reader->isRunning(); }
437 bool threadedEventHandling() const { return m_reader->isRunning(); }
438
439 xcb_timestamp_t getTimestamp();
440 xcb_window_t getSelectionOwner(xcb_atom_t atom) const;
441 xcb_window_t getQtSelectionOwner();
442
443 void setButton(Qt::MouseButton button, bool down) { m_buttons.setFlag(button, down); }
444 Qt::MouseButtons buttons() const { return m_buttons; }
445 Qt::MouseButton translateMouseButton(xcb_button_t s);
446
447 QXcbWindow *focusWindow() const { return m_focusWindow; }
448 void setFocusWindow(QWindow *);
449 QXcbWindow *mouseGrabber() const { return m_mouseGrabber; }
450 void setMouseGrabber(QXcbWindow *);
451 QXcbWindow *mousePressWindow() const { return m_mousePressWindow; }
452 void setMousePressWindow(QXcbWindow *);
453
454 QByteArray startupId() const { return m_startupId; }
455 void setStartupId(const QByteArray &nextId) { m_startupId = nextId; }
456 void clearStartupId() { m_startupId.clear(); }
457
458 void grabServer();
459 void ungrabServer();
460
461 QXcbNativeInterface *nativeInterface() const { return m_nativeInterface; }
462
463 QXcbSystemTrayTracker *systemTrayTracker() const;
464 static bool xEmbedSystemTrayAvailable();
465 static bool xEmbedSystemTrayVisualHasAlphaChannel();
466
467 #ifdef XCB_USE_XINPUT21
468 void handleEnterEvent();
469 #endif
470
471 #ifdef XCB_USE_XINPUT22
472 bool startSystemResizeForTouchBegin(xcb_window_t window, const QPoint &point, Qt::Corner corner);
473 bool xi2SetMouseGrabEnabled(xcb_window_t w, bool grab);
474 #endif
475 Qt::MouseButton xiToQtMouseButton(uint32_t b);
476
477 QXcbEventReader *eventReader() const { return m_reader; }
478
479 bool canGrab() const { return m_canGrabServer; }
480
481 QXcbGlIntegration *glIntegration() const { return m_glIntegration; }
482
483 #ifdef XCB_USE_XINPUT22
484 bool xi2MouseEvents() const;
485 bool isTouchScreen(int id) const;
486 #endif
487
488 protected:
489 bool event(QEvent *e) override;
490
491 public slots:
492 void flush() { xcb_flush(m_connection); }
493
494 private slots:
495 void processXcbEvents();
496
497 private:
498 void initializeAllAtoms();
499 void sendConnectionEvent(QXcbAtom::Atom atom, uint id = 0);
500 void initializeXFixes();
501 void initializeXRender();
502 void initializeXRandr();
503 void initializeXinerama();
504 void initializeXShape();
505 void initializeXKB();
506 void handleClientMessageEvent(const xcb_client_message_event_t *event);
507 QXcbScreen* findScreenForCrtc(xcb_window_t rootWindow, xcb_randr_crtc_t crtc) const;
508 QXcbScreen* findScreenForOutput(xcb_window_t rootWindow, xcb_randr_output_t output) const;
509 QXcbVirtualDesktop* virtualDesktopForRootWindow(xcb_window_t rootWindow) const;
510 void updateScreens(const xcb_randr_notify_event_t *event);
511 bool checkOutputIsPrimary(xcb_window_t rootWindow, xcb_randr_output_t output);
512 void updateScreen(QXcbScreen *screen, const xcb_randr_output_change_t &outputChange);
513 QXcbScreen *createScreen(QXcbVirtualDesktop *virtualDesktop,
514 const xcb_randr_output_change_t &outputChange,
515 xcb_randr_get_output_info_reply_t *outputInfo);
516 void destroyScreen(QXcbScreen *screen);
517 void initializeScreens();
518 bool compressEvent(xcb_generic_event_t *event, int currentIndex, QXcbEventArray *eventqueue) const;
519 #ifdef XCB_USE_XINPUT2
520 bool m_xi2Enabled = false;
521 int m_xi2Minor = 2;
522 void initializeXInput2();
523 void finalizeXInput2();
524 void xi2SetupDevices();
525 XInput2TouchDeviceData *touchDeviceForId(int id);
526 void xi2HandleEvent(xcb_ge_event_t *event);
527 void xi2HandleHierachyEvent(void *event);
528 void xi2HandleDeviceChangedEvent(void *event);
529 int m_xiOpCode, m_xiEventBase, m_xiErrorBase;
530 #ifdef XCB_USE_XINPUT22
531 void xi2ProcessTouch(void *xiDevEvent, QXcbWindow *platformWindow);
532 #endif // XCB_USE_XINPUT22
533 #ifndef QT_NO_TABLETEVENT
534 struct TabletData {
535 int deviceId = 0;
536 QTabletEvent::PointerType pointerType = QTabletEvent::UnknownPointer;
537 QTabletEvent::TabletDevice tool = QTabletEvent::Stylus;
538 Qt::MouseButtons buttons = 0;
539 qint64 serialId = 0;
540 bool inProximity = false;
541 struct ValuatorClassInfo {
542 double minVal = 0;
543 double maxVal = 0;
544 double curVal = 0;
545 int number = -1;
546 };
547 QHash<int, ValuatorClassInfo> valuatorInfo;
548 };
549 friend class QTypeInfo<TabletData>;
550 friend class QTypeInfo<TabletData::ValuatorClassInfo>;
551 bool xi2HandleTabletEvent(const void *event, TabletData *tabletData);
552 void xi2ReportTabletEvent(const void *event, TabletData *tabletData);
553 QVector<TabletData> m_tabletData;
554 TabletData *tabletDataForDevice(int id);
555 #endif // !QT_NO_TABLETEVENT
556 struct ScrollingDevice {
557 int deviceId = 0;
558 int verticalIndex = 0;
559 int horizontalIndex = 0;
560 double verticalIncrement = 0;
561 double horizontalIncrement = 0;
562 Qt::Orientations orientations = 0;
563 Qt::Orientations legacyOrientations = 0;
564 QPointF lastScrollPosition;
565 };
566 void updateScrollingDevice(ScrollingDevice& scrollingDevice, int num_classes, void *classes);
567 void xi2HandleScrollEvent(void *event, ScrollingDevice &scrollingDevice);
568 QHash<int, ScrollingDevice> m_scrollingDevices;
569
570 static bool xi2GetValuatorValueIfSet(const void *event, int valuatorNum, double *value);
571 static void xi2PrepareXIGenericDeviceEvent(xcb_ge_event_t *event);
572 #endif
573
574 xcb_connection_t *m_connection = nullptr;
575 const xcb_setup_t *m_setup = nullptr;
576 const bool m_canGrabServer;
577 const xcb_visualid_t m_defaultVisualId;
578
579 QList<QXcbVirtualDesktop *> m_virtualDesktops;
580 QList<QXcbScreen *> m_screens;
581 int m_primaryScreenNumber = 0;
582
583 xcb_atom_t m_allAtoms[QXcbAtom::NAtoms];
584
585 xcb_timestamp_t m_time = XCB_CURRENT_TIME;
586 xcb_timestamp_t m_netWmUserTime = XCB_CURRENT_TIME;
587
588 QByteArray m_displayName;
589
590 QXcbKeyboard *m_keyboard = nullptr;
591 #ifndef QT_NO_CLIPBOARD
592 QXcbClipboard *m_clipboard = nullptr;
593 #endif
594 #ifndef QT_NO_DRAGANDDROP
595 QXcbDrag *m_drag = nullptr;
596 #endif
597 QScopedPointer<QXcbWMSupport> m_wmSupport;
598 QXcbNativeInterface *m_nativeInterface = nullptr;
599
600 #if defined(XCB_USE_XLIB)
601 void *m_xlib_display = nullptr;
602 #endif
603 QXcbEventReader *m_reader = nullptr;
604 #if defined(XCB_USE_XINPUT2)
605 QHash<int, XInput2TouchDeviceData*> m_touchDevices;
606 #ifdef XCB_USE_XINPUT22
607 struct StartSystemResizeInfo {
608 xcb_window_t window;
609 uint16_t deviceid;
610 uint32_t pointid;
611 Qt::Corner corner;
612 } m_startSystemResizeInfo;
613 #endif
614 #endif
615 #ifdef Q_XCB_DEBUG
616 struct CallInfo {
617 int sequence;
618 QByteArray file;
619 int line;
620 };
621 QVector<CallInfo> m_callLog;
622 QMutex m_callLogMutex;
623 void log(const char *file, int line, int sequence);
624 template <typename cookie_t>
625 friend cookie_t q_xcb_call_template(const cookie_t &cookie, QXcbConnection *connection,
626 const char *file, int line);
627 template <typename reply_t>
628 friend reply_t *q_xcb_call_template(reply_t *reply, QXcbConnection *connection,
629 const char *file, int line);
630 #endif
631
632 WindowMapper m_mapper;
633
634 QVector<PeekFunc> m_peekFuncs;
635
636 uint32_t xfixes_first_event = 0;
637 uint32_t xrandr_first_event = 0;
638 uint32_t xkb_first_event = 0;
639
640 bool has_xinerama_extension = false;
641 bool has_shape_extension = false;
642 bool has_randr_extension = false;
643 bool has_input_shape;
644 bool has_xkb = false;
645
646 Qt::MouseButtons m_buttons = 0;
647
648 QXcbWindow *m_focusWindow = nullptr;
649 QXcbWindow *m_mouseGrabber = nullptr;
650 QXcbWindow *m_mousePressWindow = nullptr;
651
652 xcb_window_t m_clientLeader = 0;
653 QByteArray m_startupId;
654 QXcbSystemTrayTracker *m_systemTrayTracker = nullptr;
655 QXcbGlIntegration *m_glIntegration = nullptr;
656 bool m_xiGrab = false;
657
658 xcb_window_t m_qtSelectionOwner = 0;
659
660 friend class QXcbEventReader;
661 };
662 #ifdef XCB_USE_XINPUT2
663 #ifndef QT_NO_TABLETEVENT
664 Q_DECLARE_TYPEINFO(QXcbConnection::TabletData::ValuatorClassInfo, Q_PRIMITIVE_TYPE);
665 Q_DECLARE_TYPEINFO(QXcbConnection::TabletData, Q_MOVABLE_TYPE);
666 #endif
667 #endif
668
669 #define DISPLAY_FROM_XCB(object) (reinterpret_cast<Display *>(object->connection()->xlib_display()))
670 #define CREATE_VISUALINFO_FROM_DEFAULT_VISUALID(object) ((XVisualInfo *)(object->connection()->createVisualInfoForDefaultVisualId()))
671
672 template<typename T>
673 xcb_generic_event_t *QXcbConnection::checkEvent(T &checker)
674 {
675 QXcbEventArray *eventqueue = m_reader->lock();
676
677 for (int i = 0; i < eventqueue->size(); ++i) {
678 xcb_generic_event_t *event = eventqueue->at(i);
679 if (checker.checkEvent(event)) {
680 (*eventqueue)[i] = 0;
681 m_reader->unlock();
682 return event;
683 }
684 }
685 m_reader->unlock();
686 return 0;
687 }
688
689 class QXcbConnectionGrabber
690 {
691 public:
692 QXcbConnectionGrabber(QXcbConnection *connection);
693 ~QXcbConnectionGrabber();
694 void release();
695 private:
696 QXcbConnection *m_connection;
697 };
698
699 template <typename T>
700 union q_padded_xcb_event {
701 T event;
702 char padding[32];
703 };
704
705 // The xcb_send_event() requires all events to have 32 bytes. It calls memcpy() on the
706 // passed in event. If the passed in event is less than 32 bytes, memcpy() reaches into
707 // unrelated memory.
708 #define Q_DECLARE_XCB_EVENT(event_var, event_type) \
709 q_padded_xcb_event<event_type> store = {}; \
710 auto &event_var = store.event;
711
712 #ifdef Q_XCB_DEBUG
713 template <typename cookie_t>
714 cookie_t q_xcb_call_template(const cookie_t &cookie, QXcbConnection *connection, const char *file,
715 int line)
716 {
717 connection->log(file, line, cookie.sequence);
718 return cookie;
719 }
720
721 template <typename reply_t>
722 reply_t *q_xcb_call_template(reply_t *reply, QXcbConnection *connection, const char *file, int line)
723 {
724 connection->log(file, line, reply->sequence);
725 return reply;
726 }
727 #define Q_XCB_CALL(x) q_xcb_call_template(x, connection(), __FILE__, __LINE__)
728 #define Q_XCB_CALL2(x, connection) q_xcb_call_template(x, connection, __FILE__, __LINE__)
729 #define Q_XCB_NOOP(c) q_xcb_call_template(xcb_no_operation(c->xcb_connection()), c, __FILE__, __LINE__);
730 #else
731 #define Q_XCB_CALL(x) x
732 #define Q_XCB_CALL2(x, connection) x
733 #define Q_XCB_NOOP(c) (void)c;
734 #endif
735
736 QT_END_NAMESPACE
737
738 #endif