Debian Codegraph @

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