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>
55 #ifdef XCB_USE_XINPUT2_MAEMO
69 class QXcbNativeInterface;
71 typedef QHash<xcb_window_t, QXcbWindow *> WindowMapper;
75 // window-manager <-> client protocols
82 _NET_WM_SYNC_REQUEST_COUNTER,
102 _QT_CLIPBOARD_SENTINEL,
103 _QT_SELECTION_SENTINEL,
114 _QT_CLOSE_CONNECTION,
119 ENLIGHTENMENT_DESKTOP,
128 _NET_MOVERESIZE_WINDOW,
137 _NET_WM_WINDOW_OPACITY,
142 _NET_WM_STATE_FULLSCREEN,
143 _NET_WM_STATE_MAXIMIZED_HORZ,
144 _NET_WM_STATE_MAXIMIZED_VERT,
146 _NET_WM_STATE_STAYS_ON_TOP,
147 _NET_WM_STATE_DEMANDS_ATTENTION,
150 _NET_WM_USER_TIME_WINDOW,
151 _NET_WM_FULL_PLACEMENT,
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,
170 _KDE_NET_WM_FRAME_STRUT,
173 _NET_STARTUP_INFO_BEGIN,
175 _NET_SUPPORTING_WM_CHECK,
179 _NET_SYSTEM_TRAY_VISUAL,
208 _MOTIF_DRAG_AND_DROP_MESSAGE,
209 _MOTIF_DRAG_INITIATOR_INFO,
210 _MOTIF_DRAG_RECEIVER_INFO,
237 ButtonHorizWheelLeft,
238 ButtonHorizWheelRight,
247 #if XCB_USE_MAEMO_WINDOW_PROPERTIES
248 MeegoTouchOrientationAngle,
253 _QT_SETTINGS_TIMESTAMP = NPredefinedAtoms,
258 typedef QVarLengthArray<xcb_generic_event_t *, 64> QXcbEventArray;
260 class QXcbConnection;
261 class QXcbEventReader : public QThread
265 QXcbEventReader(QXcbConnection *connection)
266 : m_connection(connection)
270 #ifdef XCB_POLL_FOR_QUEUED_EVENT
274 QXcbEventArray *lock();
281 void addEvent(xcb_generic_event_t *event);
284 QXcbEventArray m_events;
285 QXcbConnection *m_connection;
288 class QAbstractEventDispatcher;
289 class QXcbConnection : public QObject
293 QXcbConnection(QXcbNativeInterface *nativeInterface, const char *displayName = 0);
296 QXcbConnection *connection() const { return const_cast<QXcbConnection *>(this); }
298 const QList<QXcbScreen *> &screens() const { return m_screens; }
299 int primaryScreen() const { return m_primaryScreen; }
301 xcb_atom_t atom(QXcbAtom::Atom atom);
302 xcb_atom_t internAtom(const char *name);
303 QByteArray atomName(xcb_atom_t atom);
305 const char *displayName() const { return m_displayName.constData(); }
307 xcb_connection_t *xcb_connection() const { return m_connection; }
308 const xcb_setup_t *setup() const { return m_setup; }
309 const xcb_format_t *formatForDepth(uint8_t depth) const;
311 QXcbKeyboard *keyboard() const { return m_keyboard; }
313 QXcbClipboard *clipboard() const { return m_clipboard; }
314 QXcbDrag *drag() const { return m_drag; }
316 QXcbWMSupport *wmSupport() const { return m_wmSupport.data(); }
319 void *xlib_display() const { return m_xlib_display; }
323 bool hasSupportForDri2() const;
324 QByteArray dri2DeviceName() const { return m_dri2_device_name; }
329 #if defined(XCB_USE_EGL) || defined(XCB_USE_DRI2)
330 void *egl_display() const { return m_egl_display; }
332 #ifdef XCB_USE_XINPUT2_MAEMO
333 bool isUsingXInput2();
337 void flush() { xcb_flush(m_connection); }
339 void handleXcbError(xcb_generic_error_t *error);
340 void handleXcbEvent(xcb_generic_event_t *event);
342 void addWindow(xcb_window_t id, QXcbWindow *window);
343 void removeWindow(xcb_window_t id);
344 QXcbWindow *platformWindowFromId(xcb_window_t id);
346 xcb_generic_event_t *checkEvent(int type);
348 inline xcb_generic_event_t *checkEvent(T &checker);
350 typedef bool (*PeekFunc)(xcb_generic_event_t *);
351 void addPeekFunc(PeekFunc f);
353 inline xcb_timestamp_t time() const { return m_time; }
354 inline void setTime(xcb_timestamp_t t) { if (t > m_time) m_time = t; }
356 bool hasXFixes() const { return xfixes_first_event > 0; }
357 bool hasXShape() const { return has_shape_extension; }
358 bool hasXRandr() const { return has_randr_extension; }
359 bool hasInputShape() const { return has_input_shape; }
362 void processXcbEvents();
365 void initializeAllAtoms();
366 void sendConnectionEvent(QXcbAtom::Atom atom, uint id = 0);
367 void initializeXFixes();
368 void initializeXRender();
369 void initializeXRandr();
370 void initializeXShape();
372 void initializeDri2();
374 #ifdef XCB_USE_XINPUT2_MAEMO
375 void initializeXInput2();
376 void finalizeXInput2();
377 void handleGenericEvent(xcb_ge_event_t *event);
379 void handleClientMessageEvent(const xcb_client_message_event_t *event);
381 xcb_connection_t *m_connection;
382 const xcb_setup_t *m_setup;
384 QList<QXcbScreen *> m_screens;
387 xcb_atom_t m_allAtoms[QXcbAtom::NAtoms];
389 xcb_timestamp_t m_time;
391 QByteArray m_displayName;
393 xcb_window_t m_connectionEventListener;
395 QXcbKeyboard *m_keyboard;
396 QXcbClipboard *m_clipboard;
398 QScopedPointer<QXcbWMSupport> m_wmSupport;
399 QXcbNativeInterface *m_nativeInterface;
401 #if defined(XCB_USE_XLIB)
402 void *m_xlib_display;
404 QXcbEventReader *m_reader;
405 #ifdef XCB_USE_XINPUT2_MAEMO
406 XInput2Data *m_xinputData;
409 uint32_t m_dri2_major;
410 uint32_t m_dri2_minor;
411 bool m_dri2_support_probed;
412 bool m_has_support_for_dri2;
413 QByteArray m_dri2_device_name;
415 #if defined(XCB_USE_EGL) || defined(XCB_USE_DRI2)
425 QVector<CallInfo> m_callLog;
426 QMutex m_callLogMutex;
427 void log(const char *file, int line, int sequence);
428 template <typename cookie_t>
429 friend cookie_t q_xcb_call_template(const cookie_t &cookie, QXcbConnection *connection, const char *file, int line);
432 WindowMapper m_mapper;
434 QVector<PeekFunc> m_peekFuncs;
436 uint32_t xfixes_first_event;
437 uint32_t xrandr_first_event;
439 bool has_shape_extension;
440 bool has_randr_extension;
441 bool has_input_shape;
444 #define DISPLAY_FROM_XCB(object) ((Display *)(object->connection()->xlib_display()))
447 xcb_generic_event_t *QXcbConnection::checkEvent(T &checker)
449 QXcbEventArray *eventqueue = m_reader->lock();
451 for (int i = 0; i < eventqueue->size(); ++i) {
452 xcb_generic_event_t *event = eventqueue->at(i);
453 if (checker.checkEvent(event)) {
454 (*eventqueue)[i] = 0;
465 template <typename cookie_t>
466 cookie_t q_xcb_call_template(const cookie_t &cookie, QXcbConnection *connection, const char *file, int line)
468 connection->log(file, line, cookie.sequence);
471 #define Q_XCB_CALL(x) q_xcb_call_template(x, connection(), __FILE__, __LINE__)
472 #define Q_XCB_CALL2(x, connection) q_xcb_call_template(x, connection, __FILE__, __LINE__)
473 #define Q_XCB_NOOP(c) q_xcb_call_template(xcb_no_operation(c->xcb_connection()), c, __FILE__, __LINE__);
475 #define Q_XCB_CALL(x) x
476 #define Q_XCB_CALL2(x, connection) x
477 #define Q_XCB_NOOP(c)
481 #if defined(XCB_USE_DRI2) || defined(XCB_USE_EGL)
482 #define EGL_DISPLAY_FROM_XCB(object) ((EGLDisplay)(object->connection()->egl_display()))
483 #endif //endifXCB_USE_DRI2