Qt 4.8
qxcbconnection.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the plugins of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #ifndef QXCBCONNECTION_H
43 #define QXCBCONNECTION_H
44 
45 #include <xcb/xcb.h>
46 
47 #include <QList>
48 #include <QObject>
49 #include <QVector>
50 
51 #define Q_XCB_DEBUG
52 
53 class QXcbScreen;
54 
55 namespace QXcbAtom {
56  enum Atom {
57  // window-manager <-> client protocols
65 
66  // ICCCM window state
69 
70  // Session management
74 
75  // Clipboard
87 
89 
91 
94 
96 
101 
102  // EWMH (aka NETWM)
106 
109 
113 
115 
117 
127 
131 
148 
150 
153 
155 
157 
159 
161 
162  // Property formats
166 
167  // Xdnd
176 
178 
181 
186 
187  // Motif DND
193 
196 
197  // Xkb
199 
200  // XEMBED
203 
207 
210 
212 
215  };
216 }
217 
218 class QXcbKeyboard;
219 
220 class QXcbConnection : public QObject
221 {
222  Q_OBJECT
223 public:
224  QXcbConnection(const char *displayName = 0);
225  ~QXcbConnection();
226 
227  QXcbConnection *connection() const { return const_cast<QXcbConnection *>(this); }
228 
229  QList<QXcbScreen *> screens() const { return m_screens; }
230  int primaryScreen() const { return m_primaryScreen; }
231 
232  xcb_atom_t atom(QXcbAtom::Atom atom);
233 
234  const char *displayName() const { return m_displayName.constData(); }
235 
236  xcb_connection_t *xcb_connection() const { return m_connection; }
237 
238  QXcbKeyboard *keyboard() const { return m_keyboard; }
239 
240 #ifdef XCB_USE_XLIB
241  void *xlib_display() const { return m_xlib_display; }
242 #endif
243 
244 #ifdef XCB_USE_DRI2
245  bool hasSupportForDri2() const;
246  QByteArray dri2DeviceName() const { return m_dri2_device_name; }
247 #endif
248 #ifdef XCB_USE_EGL
249  bool hasEgl() const;
250 #endif
251 #if defined(XCB_USE_EGL) || defined(XCB_USE_DRI2)
252  void *egl_display() const { return m_egl_display; }
253 #endif
254 
255  void sync();
256  void handleXcbError(xcb_generic_error_t *error);
257 
258 private slots:
259  void processXcbEvents();
260 
261 private:
262  void initializeAllAtoms();
263  void sendConnectionEvent(QXcbAtom::Atom atom, uint id = 0);
264 #ifdef XCB_USE_DRI2
265  void initializeDri2();
266 #endif
267 
268  xcb_connection_t *m_connection;
269  const xcb_setup_t *m_setup;
270 
273 
274  xcb_atom_t m_allAtoms[QXcbAtom::NAtoms];
275 
277 
279 
280 #if defined(XCB_USE_XLIB)
281  void *m_xlib_display;
282 #endif
283 
284 #ifdef XCB_USE_DRI2
285  uint32_t m_dri2_major;
286  uint32_t m_dri2_minor;
287  bool m_dri2_support_probed;
288  bool m_has_support_for_dri2;
289  QByteArray m_dri2_device_name;
290 #endif
291 #if defined(XCB_USE_EGL) || defined(XCB_USE_DRI2)
292  void *m_egl_display;
293  bool m_has_egl;
294 #endif
295 #ifdef Q_XCB_DEBUG
296  struct CallInfo {
297  int sequence;
299  int line;
300  };
302  void log(const char *file, int line, int sequence);
303  template <typename cookie_t>
304  friend cookie_t q_xcb_call_template(const cookie_t &cookie, QXcbConnection *connection, const char *file, int line);
305 #endif
306 };
307 
308 #define DISPLAY_FROM_XCB(object) ((Display *)(object->connection()->xlib_display()))
309 
310 #ifdef Q_XCB_DEBUG
311 template <typename cookie_t>
312 cookie_t q_xcb_call_template(const cookie_t &cookie, QXcbConnection *connection, const char *file, int line)
313 {
314  connection->log(file, line, cookie.sequence);
315  return cookie;
316 }
317 #define Q_XCB_CALL(x) q_xcb_call_template(x, connection(), __FILE__, __LINE__)
318 #define Q_XCB_CALL2(x, connection) q_xcb_call_template(x, connection, __FILE__, __LINE__)
319 #define Q_XCB_NOOP(c) q_xcb_call_template(xcb_no_operation(c->xcb_connection()), c, __FILE__, __LINE__);
320 #else
321 #define Q_XCB_CALL(x) x
322 #define Q_XCB_CALL2(x, connection) x
323 #define Q_XCB_NOOP(c)
324 #endif
325 
326 
327 #if defined(XCB_USE_DRI2) || defined(XCB_USE_EGL)
328 #define EGL_DISPLAY_FROM_XCB(object) ((EGLDisplay)(object->connection()->egl_display()))
329 #endif //endifXCB_USE_DRI2
330 
331 #endif
QVector< CallInfo > m_callLog
#define error(msg)
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
xcb_connection_t * xcb_connection() const
void log(const char *file, int line, int sequence)
The QVector class is a template class that provides a dynamic array.
Definition: qdatastream.h:64
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
const char * displayName() const
QList< QXcbScreen * > screens() const
int primaryScreen() const
QXcbKeyboard * keyboard() const
QByteArray m_displayName
QXcbKeyboard * m_keyboard
unsigned int uint
Definition: qglobal.h:996
#define Q_OBJECT
Definition: qobjectdefs.h:157
QXcbConnection * connection() const
xcb_connection_t * m_connection
const xcb_setup_t * m_setup
cookie_t q_xcb_call_template(const cookie_t &cookie, QXcbConnection *connection, const char *file, int line)
QList< QXcbScreen * > m_screens
#define slots
Definition: qobjectdefs.h:68
The QList class is a template class that provides lists.
Definition: qdatastream.h:62