1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the plugins of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
42 #ifndef QXCBCONNECTION_H
43 #define QXCBCONNECTION_H
53 #include <QVarLengthArray>
54 #include <QtGui/qwindowsysteminterface.h>
56 #ifndef QT_NO_TABLETEVENT
57 #include <QTabletEvent>
60 #ifdef XCB_USE_XINPUT2_MAEMO
61 struct XInput2MaemoData;
63 #ifdef XI_TouchBeginMask
64 #define XCB_USE_XINPUT22 // XI 2.2 adds multi-point touch support
66 struct XInput2DeviceData;
79 class QXcbNativeInterface;
81 typedef QHash<xcb_window_t, QXcbWindow *> WindowMapper;
85 // window-manager <-> client protocols
92 _NET_WM_SYNC_REQUEST_COUNTER,
112 _QT_CLIPBOARD_SENTINEL,
113 _QT_SELECTION_SENTINEL,
124 _QT_CLOSE_CONNECTION,
129 ENLIGHTENMENT_DESKTOP,
138 _NET_MOVERESIZE_WINDOW,
147 _NET_WM_WINDOW_OPACITY,
152 _NET_WM_STATE_FULLSCREEN,
153 _NET_WM_STATE_MAXIMIZED_HORZ,
154 _NET_WM_STATE_MAXIMIZED_VERT,
156 _NET_WM_STATE_STAYS_ON_TOP,
157 _NET_WM_STATE_DEMANDS_ATTENTION,
160 _NET_WM_USER_TIME_WINDOW,
161 _NET_WM_FULL_PLACEMENT,
164 _NET_WM_WINDOW_TYPE_DESKTOP,
165 _NET_WM_WINDOW_TYPE_DOCK,
166 _NET_WM_WINDOW_TYPE_TOOLBAR,
167 _NET_WM_WINDOW_TYPE_MENU,
168 _NET_WM_WINDOW_TYPE_UTILITY,
169 _NET_WM_WINDOW_TYPE_SPLASH,
170 _NET_WM_WINDOW_TYPE_DIALOG,
171 _NET_WM_WINDOW_TYPE_DROPDOWN_MENU,
172 _NET_WM_WINDOW_TYPE_POPUP_MENU,
173 _NET_WM_WINDOW_TYPE_TOOLTIP,
174 _NET_WM_WINDOW_TYPE_NOTIFICATION,
175 _NET_WM_WINDOW_TYPE_COMBO,
176 _NET_WM_WINDOW_TYPE_DND,
177 _NET_WM_WINDOW_TYPE_NORMAL,
178 _KDE_NET_WM_WINDOW_TYPE_OVERRIDE,
180 _KDE_NET_WM_FRAME_STRUT,
183 _NET_STARTUP_INFO_BEGIN,
185 _NET_SUPPORTING_WM_CHECK,
189 _NET_SYSTEM_TRAY_VISUAL,
219 _MOTIF_DRAG_AND_DROP_MESSAGE,
220 _MOTIF_DRAG_INITIATOR_INFO,
221 _MOTIF_DRAG_RECEIVER_INFO,
241 ButtonHorizWheelLeft,
242 ButtonHorizWheelRight,
261 #if XCB_USE_MAEMO_WINDOW_PROPERTIES
262 MeegoTouchOrientationAngle,
267 _QT_SETTINGS_TIMESTAMP = NPredefinedAtoms,
272 typedef QVarLengthArray<xcb_generic_event_t *, 64> QXcbEventArray;
274 class QXcbConnection;
275 class QXcbEventReader : public QThread
279 QXcbEventReader(QXcbConnection *connection)
280 : m_connection(connection)
284 #ifdef XCB_POLL_FOR_QUEUED_EVENT
288 QXcbEventArray *lock();
295 void addEvent(xcb_generic_event_t *event);
298 QXcbEventArray m_events;
299 QXcbConnection *m_connection;
302 class QAbstractEventDispatcher;
303 class QXcbConnection : public QObject
307 QXcbConnection(QXcbNativeInterface *nativeInterface, const char *displayName = 0);
310 QXcbConnection *connection() const { return const_cast<QXcbConnection *>(this); }
312 const QList<QXcbScreen *> &screens() const { return m_screens; }
313 int primaryScreen() const { return m_primaryScreen; }
315 xcb_atom_t atom(QXcbAtom::Atom atom);
316 xcb_atom_t internAtom(const char *name);
317 QByteArray atomName(xcb_atom_t atom);
319 const char *displayName() const { return m_displayName.constData(); }
321 xcb_connection_t *xcb_connection() const { return m_connection; }
322 const xcb_setup_t *setup() const { return m_setup; }
323 const xcb_format_t *formatForDepth(uint8_t depth) const;
325 QXcbKeyboard *keyboard() const { return m_keyboard; }
327 #ifndef QT_NO_CLIPBOARD
328 QXcbClipboard *clipboard() const { return m_clipboard; }
330 #ifndef QT_NO_DRAGANDDROP
331 QXcbDrag *drag() const { return m_drag; }
334 QXcbWMSupport *wmSupport() const { return m_wmSupport.data(); }
337 void *xlib_display() const { return m_xlib_display; }
341 bool hasSupportForDri2() const;
342 QByteArray dri2DeviceName() const { return m_dri2_device_name; }
347 #if defined(XCB_USE_EGL) || defined(XCB_USE_DRI2)
348 void *egl_display() const { return m_egl_display; }
350 #ifdef XCB_USE_XINPUT2_MAEMO
351 bool isUsingXInput2Maemo();
352 #elif defined(XCB_USE_XINPUT2)
353 void xi2Select(xcb_window_t window);
357 void flush() { xcb_flush(m_connection); }
359 void handleXcbError(xcb_generic_error_t *error);
360 void handleXcbEvent(xcb_generic_event_t *event);
362 void addWindow(xcb_window_t id, QXcbWindow *window);
363 void removeWindow(xcb_window_t id);
364 QXcbWindow *platformWindowFromId(xcb_window_t id);
366 xcb_generic_event_t *checkEvent(int type);
368 inline xcb_generic_event_t *checkEvent(T &checker);
370 typedef bool (*PeekFunc)(xcb_generic_event_t *);
371 void addPeekFunc(PeekFunc f);
373 inline xcb_timestamp_t time() const { return m_time; }
374 inline void setTime(xcb_timestamp_t t) { if (t > m_time) m_time = t; }
376 bool hasXFixes() const { return xfixes_first_event > 0; }
377 bool hasXShape() const { return has_shape_extension; }
378 bool hasXRandr() const { return has_randr_extension; }
379 bool hasInputShape() const { return has_input_shape; }
382 void processXcbEvents();
385 void initializeAllAtoms();
386 void sendConnectionEvent(QXcbAtom::Atom atom, uint id = 0);
387 void initializeXFixes();
388 void initializeXRender();
389 void initializeXRandr();
390 void initializeXShape();
392 void initializeDri2();
394 #ifdef XCB_USE_XINPUT2_MAEMO
395 void initializeXInput2Maemo();
396 void finalizeXInput2Maemo();
397 void handleGenericEventMaemo(xcb_ge_event_t *event);
399 void handleClientMessageEvent(const xcb_client_message_event_t *event);
403 #ifdef XCB_USE_XINPUT2
404 void initializeXInput2();
405 void finalizeXInput2();
406 XInput2DeviceData *deviceForId(int id);
407 void xi2HandleEvent(xcb_ge_event_t *event);
408 int m_xiOpCode, m_xiEventBase, m_xiErrorBase;
409 #ifndef QT_NO_TABLETEVENT
411 TabletData() : deviceId(0), down(false), serialId(0), inProximity(false) { }
413 QTabletEvent::PointerType pointerType;
417 struct ValuatorClassInfo {
418 ValuatorClassInfo() : minVal(0), maxVal(0) { }
423 QHash<int, ValuatorClassInfo> valuatorInfo;
425 void xi2QueryTabletData(void *dev, TabletData *tabletData); // use no XI stuff in headers
426 void xi2SetupTabletDevices();
427 bool xi2HandleTabletEvent(void *event, TabletData *tabletData);
428 void xi2ReportTabletEvent(const TabletData &tabletData, void *event);
429 QVector<TabletData> m_tabletData;
431 #endif // XCB_USE_XINPUT2
433 #if defined(XCB_USE_XINPUT2) || defined(XCB_USE_XINPUT2_MAEMO)
434 static int xi2CountBits(unsigned char *ptr, int len);
435 static bool xi2GetValuatorValueIfSet(void *event, int valuatorNum, double *value);
436 static bool xi2PrepareXIGenericDeviceEvent(xcb_ge_event_t *event, int opCode);
439 xcb_connection_t *m_connection;
440 const xcb_setup_t *m_setup;
442 QList<QXcbScreen *> m_screens;
445 xcb_atom_t m_allAtoms[QXcbAtom::NAtoms];
447 xcb_timestamp_t m_time;
449 QByteArray m_displayName;
451 xcb_window_t m_connectionEventListener;
453 QXcbKeyboard *m_keyboard;
454 #ifndef QT_NO_CLIPBOARD
455 QXcbClipboard *m_clipboard;
457 #ifndef QT_NO_DRAGANDDROP
460 QScopedPointer<QXcbWMSupport> m_wmSupport;
461 QXcbNativeInterface *m_nativeInterface;
463 #if defined(XCB_USE_XLIB)
464 void *m_xlib_display;
466 QXcbEventReader *m_reader;
467 #ifdef XCB_USE_XINPUT2_MAEMO
468 XInput2MaemoData *m_xinputData;
469 #elif defined(XCB_USE_XINPUT2)
470 QHash<int, QWindowSystemInterface::TouchPoint> m_touchPoints;
471 QHash<int, XInput2DeviceData*> m_touchDevices;
474 uint32_t m_dri2_major;
475 uint32_t m_dri2_minor;
476 bool m_dri2_support_probed;
477 bool m_has_support_for_dri2;
478 QByteArray m_dri2_device_name;
480 #if defined(XCB_USE_EGL) || defined(XCB_USE_DRI2)
490 QVector<CallInfo> m_callLog;
491 QMutex m_callLogMutex;
492 void log(const char *file, int line, int sequence);
493 template <typename cookie_t>
494 friend cookie_t q_xcb_call_template(const cookie_t &cookie, QXcbConnection *connection, const char *file, int line);
497 WindowMapper m_mapper;
499 QVector<PeekFunc> m_peekFuncs;
501 uint32_t xfixes_first_event;
502 uint32_t xrandr_first_event;
504 bool has_shape_extension;
505 bool has_randr_extension;
506 bool has_input_shape;
509 #define DISPLAY_FROM_XCB(object) ((Display *)(object->connection()->xlib_display()))
512 xcb_generic_event_t *QXcbConnection::checkEvent(T &checker)
514 QXcbEventArray *eventqueue = m_reader->lock();
516 for (int i = 0; i < eventqueue->size(); ++i) {
517 xcb_generic_event_t *event = eventqueue->at(i);
518 if (checker.checkEvent(event)) {
519 (*eventqueue)[i] = 0;
530 template <typename cookie_t>
531 cookie_t q_xcb_call_template(const cookie_t &cookie, QXcbConnection *connection, const char *file, int line)
533 connection->log(file, line, cookie.sequence);
536 #define Q_XCB_CALL(x) q_xcb_call_template(x, connection(), __FILE__, __LINE__)
537 #define Q_XCB_CALL2(x, connection) q_xcb_call_template(x, connection, __FILE__, __LINE__)
538 #define Q_XCB_NOOP(c) q_xcb_call_template(xcb_no_operation(c->xcb_connection()), c, __FILE__, __LINE__);
540 #define Q_XCB_CALL(x) x
541 #define Q_XCB_CALL2(x, connection) x
542 #define Q_XCB_NOOP(c)
546 #if defined(XCB_USE_DRI2) || defined(XCB_USE_EGL)
547 #define EGL_DISPLAY_FROM_XCB(object) ((EGLDisplay)(object->connection()->egl_display()))
548 #endif //endifXCB_USE_DRI2