Qt 4.8
Classes | Public Functions | Private Slots | Private Functions | Properties | Friends | List of all members
QXcbConnection Class Reference

#include <qxcbconnection.h>

Inheritance diagram for QXcbConnection:
QObject

Classes

struct  CallInfo
 

Public Functions

xcb_atom_t atom (QXcbAtom::Atom atom)
 
QXcbConnectionconnection () const
 
const char * displayName () const
 
void handleXcbError (xcb_generic_error_t *error)
 
QXcbKeyboardkeyboard () const
 
int primaryScreen () const
 
 QXcbConnection (const char *displayName=0)
 
QList< QXcbScreen * > screens () const
 
void sync ()
 
xcb_connection_t * xcb_connection () const
 
 ~QXcbConnection ()
 
- Public Functions inherited from QObject
bool blockSignals (bool b)
 If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it). More...
 
const QObjectListchildren () const
 Returns a list of child objects. More...
 
bool connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const
 
bool disconnect (const char *signal=0, const QObject *receiver=0, const char *member=0)
 
bool disconnect (const QObject *receiver, const char *member=0)
 
void dumpObjectInfo ()
 Dumps information about signal connections, etc. More...
 
void dumpObjectTree ()
 Dumps a tree of children to the debug output. More...
 
QList< QByteArraydynamicPropertyNames () const
 Returns the names of all properties that were dynamically added to the object using setProperty(). More...
 
virtual bool event (QEvent *)
 This virtual function receives events to an object and should return true if the event e was recognized and processed. More...
 
virtual bool eventFilter (QObject *, QEvent *)
 Filters events if this object has been installed as an event filter for the watched object. More...
 
template<typename T >
findChild (const QString &aName=QString()) const
 Returns the child of this object that can be cast into type T and that is called name, or 0 if there is no such object. More...
 
template<typename T >
QList< T > findChildren (const QString &aName=QString()) const
 Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects. More...
 
template<typename T >
QList< T > findChildren (const QRegExp &re) const
 
bool inherits (const char *classname) const
 Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false. More...
 
void installEventFilter (QObject *)
 Installs an event filter filterObj on this object. More...
 
bool isWidgetType () const
 Returns true if the object is a widget; otherwise returns false. More...
 
void killTimer (int id)
 Kills the timer with timer identifier, id. More...
 
virtual const QMetaObjectmetaObject () const
 Returns a pointer to the meta-object of this object. More...
 
void moveToThread (QThread *thread)
 Changes the thread affinity for this object and its children. More...
 
QString objectName () const
 
QObjectparent () const
 Returns a pointer to the parent object. More...
 
QVariant property (const char *name) const
 Returns the value of the object's name property. More...
 
Q_INVOKABLE QObject (QObject *parent=0)
 Constructs an object with parent object parent. More...
 
void removeEventFilter (QObject *)
 Removes an event filter object obj from this object. More...
 
void setObjectName (const QString &name)
 
void setParent (QObject *)
 Makes the object a child of parent. More...
 
bool setProperty (const char *name, const QVariant &value)
 Sets the value of the object's name property to value. More...
 
void setUserData (uint id, QObjectUserData *data)
 
bool signalsBlocked () const
 Returns true if signals are blocked; otherwise returns false. More...
 
int startTimer (int interval)
 Starts a timer and returns a timer identifier, or returns zero if it could not start a timer. More...
 
QThreadthread () const
 Returns the thread in which the object lives. More...
 
QObjectUserDatauserData (uint id) const
 
virtual ~QObject ()
 Destroys the object, deleting all its child objects. More...
 

Private Slots

void processXcbEvents ()
 

Private Functions

void initializeAllAtoms ()
 
void log (const char *file, int line, int sequence)
 
void sendConnectionEvent (QXcbAtom::Atom atom, uint id=0)
 

Properties

xcb_atom_t m_allAtoms [QXcbAtom::NAtoms]
 
QVector< CallInfom_callLog
 
xcb_connection_t * m_connection
 
QByteArray m_displayName
 
QXcbKeyboardm_keyboard
 
int m_primaryScreen
 
QList< QXcbScreen * > m_screens
 
const xcb_setup_t * m_setup
 

Friends

template<typename cookie_t >
cookie_t q_xcb_call_template (const cookie_t &cookie, QXcbConnection *connection, const char *file, int line)
 

Additional Inherited Members

- Public Slots inherited from QObject
void deleteLater ()
 Schedules this object for deletion. More...
 
- Signals inherited from QObject
void destroyed (QObject *=0)
 This signal is emitted immediately before the object obj is destroyed, and can not be blocked. More...
 
- Static Public Functions inherited from QObject
static bool connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
 Creates a connection of the given type from the signal in the sender object to the method in the receiver object. More...
 
static bool connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member)
 Disconnects signal in object sender from method in object receiver. More...
 
static bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member)
 
static uint registerUserData ()
 
static QString tr (const char *sourceText, const char *comment=0, int n=-1)
 
static QString trUtf8 (const char *sourceText, const char *comment=0, int n=-1)
 
- Static Public Variables inherited from QObject
static const QMetaObject staticMetaObject
 This variable stores the meta-object for the class. More...
 
- Protected Functions inherited from QObject
virtual void childEvent (QChildEvent *)
 This event handler can be reimplemented in a subclass to receive child events. More...
 
virtual void connectNotify (const char *signal)
 This virtual function is called when something has been connected to signal in this object. More...
 
virtual void customEvent (QEvent *)
 This event handler can be reimplemented in a subclass to receive custom events. More...
 
virtual void disconnectNotify (const char *signal)
 This virtual function is called when something has been disconnected from signal in this object. More...
 
 QObject (QObjectPrivate &dd, QObject *parent=0)
 
int receivers (const char *signal) const
 Returns the number of receivers connected to the signal. More...
 
QObjectsender () const
 Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns 0. More...
 
int senderSignalIndex () const
 
virtual void timerEvent (QTimerEvent *)
 This event handler can be reimplemented in a subclass to receive timer events for the object. More...
 
- Protected Variables inherited from QObject
QScopedPointer< QObjectDatad_ptr
 
- Static Protected Variables inherited from QObject
static const QMetaObject staticQtMetaObject
 

Detailed Description

Definition at line 220 of file qxcbconnection.h.

Constructors and Destructors

◆ QXcbConnection()

QXcbConnection::QXcbConnection ( const char *  displayName = 0)

Definition at line 78 of file qxcbconnection.cpp.

80 #ifdef XCB_USE_DRI2
81  , m_dri2_major(0)
82  , m_dri2_minor(0)
83  , m_dri2_support_probed(false)
84  , m_has_support_for_dri2(false)
85 #endif
86 {
87  int primaryScreen = 0;
88 
89 #ifdef XCB_USE_XLIB
90  Display *dpy = XOpenDisplay(m_displayName.constData());
91  primaryScreen = DefaultScreen(dpy);
92  m_connection = XGetXCBConnection(dpy);
93  XSetEventQueueOwner(dpy, XCBOwnsEventQueue);
94  m_xlib_display = dpy;
95 #ifdef XCB_USE_EGL
96  EGLDisplay eglDisplay = eglGetDisplay(dpy);
97  m_egl_display = eglDisplay;
98  EGLint major, minor;
99  eglBindAPI(EGL_OPENGL_ES_API);
100  m_has_egl = eglInitialize(eglDisplay,&major,&minor);
101 #endif //XCB_USE_EGL
102 #else
104 
105 #endif //XCB_USE_XLIB
106  m_setup = xcb_get_setup(xcb_connection());
107 
109 
110  xcb_screen_iterator_t it = xcb_setup_roots_iterator(m_setup);
111 
112  int screenNumber = 0;
113  while (it.rem) {
114  m_screens << new QXcbScreen(this, it.data, screenNumber++);
115  xcb_screen_next(&it);
116  }
117 
118  m_keyboard = new QXcbKeyboard(this);
119 
120 #ifdef XCB_USE_DRI2
121  initializeDri2();
122 #endif
123 
124  QSocketNotifier *notifier = new QSocketNotifier(xcb_get_file_descriptor(xcb_connection()), QSocketNotifier::Read, this);
125  connect(notifier, SIGNAL(activated(int)), this, SLOT(processXcbEvents()));
126 
128  connect(dispatcher, SIGNAL(aboutToBlock()), this, SLOT(processXcbEvents()));
129 
130  sync();
131 }
Q_CORE_EXPORT QByteArray qgetenv(const char *varName)
#define it(className, varName)
static QAbstractEventDispatcher * instance(QThread *thread=0)
Returns a pointer to the event dispatcher object for the specified thread.
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
#define SLOT(a)
Definition: qobjectdefs.h:226
xcb_connection_t * xcb_connection() const
const char * displayName() const
The QSocketNotifier class provides support for monitoring activity on a file descriptor.
#define SIGNAL(a)
Definition: qobjectdefs.h:227
int primaryScreen() const
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
Definition: qobject.cpp:2580
#define qApp
QByteArray m_displayName
QXcbKeyboard * m_keyboard
xcb_connection_t * m_connection
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
struct _XDisplay Display
Definition: qwindowdefs.h:115
const xcb_setup_t * m_setup
QList< QXcbScreen * > m_screens
The QAbstractEventDispatcher class provides an interface to manage Qt&#39;s event queue.

◆ ~QXcbConnection()

QXcbConnection::~QXcbConnection ( )

Definition at line 133 of file qxcbconnection.cpp.

134 {
136 
137 #ifdef XCB_USE_XLIB
138  XCloseDisplay((Display *)m_xlib_display);
139 #else
140  xcb_disconnect(xcb_connection());
141 #endif
142 
143  delete m_keyboard;
144 }
xcb_connection_t * xcb_connection() const
QXcbKeyboard * m_keyboard
struct _XDisplay Display
Definition: qwindowdefs.h:115
QList< QXcbScreen * > m_screens
Q_OUTOFLINE_TEMPLATE void qDeleteAll(ForwardIterator begin, ForwardIterator end)
Definition: qalgorithms.h:319

Functions

◆ atom()

xcb_atom_t QXcbConnection::atom ( QXcbAtom::Atom  atom)

Definition at line 633 of file qxcbconnection.cpp.

Referenced by QXcbObject::atom().

634 {
635  return m_allAtoms[atom];
636 }
xcb_atom_t m_allAtoms[QXcbAtom::NAtoms]
xcb_atom_t atom(QXcbAtom::Atom atom)

◆ connection()

QXcbConnection* QXcbConnection::connection ( ) const
inline

Definition at line 227 of file qxcbconnection.h.

227 { return const_cast<QXcbConnection *>(this); }

◆ displayName()

const char* QXcbConnection::displayName ( ) const
inline

Definition at line 234 of file qxcbconnection.h.

234 { return m_displayName.constData(); }
QByteArray m_displayName
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433

◆ handleXcbError()

void QXcbConnection::handleXcbError ( xcb_generic_error_t *  error)

Definition at line 384 of file qxcbconnection.cpp.

Referenced by processXcbEvents(), and QXcbScreen::QXcbScreen().

385 {
386  uint clamped_error_code = qMin<uint>(error->error_code, (sizeof(xcb_errors) / sizeof(xcb_errors[0])) - 1);
387  uint clamped_major_code = qMin<uint>(error->major_code, (sizeof(xcb_protocol_request_codes) / sizeof(xcb_protocol_request_codes[0])) - 1);
388 
389  printf("XCB error: %d (%s), sequence: %d, resource id: %d, major code: %d (%s), minor code: %d\n",
390  int(error->error_code), xcb_errors[clamped_error_code],
391  int(error->sequence), int(error->resource_id),
392  int(error->major_code), xcb_protocol_request_codes[clamped_major_code],
393  int(error->minor_code));
394 #ifdef Q_XCB_DEBUG
395  int i = 0;
396  for (; i < m_callLog.size(); ++i) {
397  if (m_callLog.at(i).sequence == error->sequence) {
398  printf("Caused by: %s:%d\n", qPrintable(m_callLog.at(i).file), m_callLog.at(i).line);
399  break;
400  } else if (m_callLog.at(i).sequence > error->sequence) {
401  printf("Caused some time before: %s:%d\n", qPrintable(m_callLog.at(i).file), m_callLog.at(i).line);
402  if (i > 0)
403  printf("and after: %s:%d\n", qPrintable(m_callLog.at(i-1).file), m_callLog.at(i-1).line);
404  break;
405  }
406  }
407  if (i == m_callLog.size() && !m_callLog.isEmpty())
408  printf("Caused some time after: %s:%d\n", qPrintable(m_callLog.first().file), m_callLog.first().line);
409 #endif
410 }
QVector< CallInfo > m_callLog
#define error(msg)
unsigned int uint
Definition: qglobal.h:996
const char * xcb_errors[]
const char * xcb_protocol_request_codes[]
#define qPrintable(string)
Definition: qglobal.h:1750

◆ initializeAllAtoms()

void QXcbConnection::initializeAllAtoms ( )
private

Definition at line 638 of file qxcbconnection.cpp.

Referenced by QXcbConnection().

638  {
639  const char *names[QXcbAtom::NAtoms];
640  const char *ptr = xcb_atomnames;
641 
642  int i = 0;
643  while (*ptr) {
644  names[i++] = ptr;
645  while (*ptr)
646  ++ptr;
647  ++ptr;
648  }
649 
651 
652  QByteArray settings_atom_name("_QT_SETTINGS_TIMESTAMP_");
653  settings_atom_name += m_displayName;
654  names[i++] = settings_atom_name;
655 
656  xcb_intern_atom_cookie_t cookies[QXcbAtom::NAtoms];
657 
659  for (i = 0; i < QXcbAtom::NAtoms; ++i)
660  cookies[i] = xcb_intern_atom(xcb_connection(), false, strlen(names[i]), names[i]);
661 
662  for (i = 0; i < QXcbAtom::NAtoms; ++i)
663  m_allAtoms[i] = xcb_intern_atom_reply(xcb_connection(), cookies[i], 0)->atom;
664 }
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
xcb_atom_t m_allAtoms[QXcbAtom::NAtoms]
xcb_connection_t * xcb_connection() const
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
static const char * xcb_atomnames
QByteArray m_displayName
const T * ptr(const T &t)

◆ keyboard()

QXcbKeyboard* QXcbConnection::keyboard ( ) const
inline

Definition at line 238 of file qxcbconnection.h.

238 { return m_keyboard; }
QXcbKeyboard * m_keyboard

◆ log()

void QXcbConnection::log ( const char *  file,
int  line,
int  sequence 
)
private

Definition at line 374 of file qxcbconnection.cpp.

Referenced by q_xcb_call_template().

375 {
376  CallInfo info;
377  info.sequence = sequence;
378  info.file = file;
379  info.line = line;
380  m_callLog << info;
381 }
QVector< CallInfo > m_callLog
static mach_timebase_info_data_t info

◆ primaryScreen()

int QXcbConnection::primaryScreen ( ) const
inline

Definition at line 230 of file qxcbconnection.h.

Referenced by QXcbConnection().

230 { return m_primaryScreen; }

◆ processXcbEvents

void QXcbConnection::processXcbEvents ( )
privateslot

Definition at line 412 of file qxcbconnection.cpp.

Referenced by QXcbConnection().

413 {
414  while (xcb_generic_event_t *event = xcb_poll_for_event(xcb_connection())) {
415  bool handled = true;
416 
417  uint response_type = event->response_type & ~0x80;
418 
419  if (!response_type) {
420  handleXcbError((xcb_generic_error_t *)event);
421  continue;
422  }
423 
424 #ifdef Q_XCB_DEBUG
425  {
426  int i = 0;
427  for (; i < m_callLog.size(); ++i)
428  if (m_callLog.at(i).sequence >= event->sequence)
429  break;
430  m_callLog.remove(0, i);
431  }
432 #endif
433 
434  switch (response_type) {
435  case XCB_EXPOSE:
436  HANDLE_PLATFORM_WINDOW_EVENT(xcb_expose_event_t, window, handleExposeEvent);
437  case XCB_BUTTON_PRESS:
438  HANDLE_PLATFORM_WINDOW_EVENT(xcb_button_press_event_t, event, handleButtonPressEvent);
439  case XCB_BUTTON_RELEASE:
440  HANDLE_PLATFORM_WINDOW_EVENT(xcb_button_release_event_t, event, handleButtonReleaseEvent);
441  case XCB_MOTION_NOTIFY:
442  HANDLE_PLATFORM_WINDOW_EVENT(xcb_motion_notify_event_t, event, handleMotionNotifyEvent);
443  case XCB_CONFIGURE_NOTIFY:
444  HANDLE_PLATFORM_WINDOW_EVENT(xcb_configure_notify_event_t, event, handleConfigureNotifyEvent);
445  case XCB_CLIENT_MESSAGE:
446  HANDLE_PLATFORM_WINDOW_EVENT(xcb_client_message_event_t, window, handleClientMessageEvent);
447  case XCB_ENTER_NOTIFY:
448  HANDLE_PLATFORM_WINDOW_EVENT(xcb_enter_notify_event_t, event, handleEnterNotifyEvent);
449  case XCB_LEAVE_NOTIFY:
450  HANDLE_PLATFORM_WINDOW_EVENT(xcb_leave_notify_event_t, event, handleLeaveNotifyEvent);
451  case XCB_FOCUS_IN:
452  HANDLE_PLATFORM_WINDOW_EVENT(xcb_focus_in_event_t, event, handleFocusInEvent);
453  case XCB_FOCUS_OUT:
454  HANDLE_PLATFORM_WINDOW_EVENT(xcb_focus_out_event_t, event, handleFocusOutEvent);
455  case XCB_KEY_PRESS:
456  HANDLE_KEYBOARD_EVENT(xcb_key_press_event_t, handleKeyPressEvent);
457  case XCB_KEY_RELEASE:
458  HANDLE_KEYBOARD_EVENT(xcb_key_release_event_t, handleKeyReleaseEvent);
459  case XCB_MAPPING_NOTIFY:
460  m_keyboard->handleMappingNotifyEvent((xcb_mapping_notify_event_t *)event);
461  break;
462  default:
463  handled = false;
464  break;
465  }
466  if (handled)
467  printXcbEvent("Handled XCB event", event);
468  else
469  printXcbEvent("Unhandled XCB event", event);
470  }
471 
472  xcb_flush(xcb_connection());
473 }
QVector< CallInfo > m_callLog
#define HANDLE_PLATFORM_WINDOW_EVENT(event_t, window, handler)
void handleMappingNotifyEvent(const xcb_mapping_notify_event_t *event)
xcb_connection_t * xcb_connection() const
virtual bool event(QEvent *)
This virtual function receives events to an object and should return true if the event e was recogniz...
Definition: qobject.cpp:1200
void printXcbEvent(const char *message, xcb_generic_event_t *event)
NSWindow * window
void handleXcbError(xcb_generic_error_t *error)
QXcbKeyboard * m_keyboard
unsigned int uint
Definition: qglobal.h:996
#define HANDLE_KEYBOARD_EVENT(event_t, handler)

◆ screens()

QList<QXcbScreen *> QXcbConnection::screens ( ) const
inline

Definition at line 229 of file qxcbconnection.h.

Referenced by QXcbIntegration::QXcbIntegration().

229 { return m_screens; }
QList< QXcbScreen * > m_screens

◆ sendConnectionEvent()

void QXcbConnection::sendConnectionEvent ( QXcbAtom::Atom  atom,
uint  id = 0 
)
private

◆ sync()

void QXcbConnection::sync ( )

Definition at line 666 of file qxcbconnection.cpp.

Referenced by QXcbWindowSurface::flush(), QXcbShmImage::preparePaint(), QXcbConnection(), QXcbWindow::requestActivateWindow(), QXcbWindow::setVisible(), and QXcbWindow::updateSyncRequestCounter().

667 {
668  // from xcb_aux_sync
669  xcb_get_input_focus_cookie_t cookie = Q_XCB_CALL(xcb_get_input_focus(xcb_connection()));
670  free(xcb_get_input_focus_reply(xcb_connection(), cookie, 0));
671 }
xcb_connection_t * xcb_connection() const
#define Q_XCB_CALL(x)

◆ xcb_connection()

xcb_connection_t* QXcbConnection::xcb_connection ( ) const
inline

Friends and Related Functions

◆ q_xcb_call_template

template<typename cookie_t >
cookie_t q_xcb_call_template ( const cookie_t &  cookie,
QXcbConnection connection,
const char *  file,
int  line 
)
friend

Definition at line 312 of file qxcbconnection.h.

313 {
314  connection->log(file, line, cookie.sequence);
315  return cookie;
316 }
void log(const char *file, int line, int sequence)

Properties

◆ m_allAtoms

xcb_atom_t QXcbConnection::m_allAtoms[QXcbAtom::NAtoms]
private

Definition at line 274 of file qxcbconnection.h.

Referenced by atom(), and initializeAllAtoms().

◆ m_callLog

QVector<CallInfo> QXcbConnection::m_callLog
private

Definition at line 301 of file qxcbconnection.h.

Referenced by handleXcbError(), log(), and processXcbEvents().

◆ m_connection

xcb_connection_t* QXcbConnection::m_connection
private

Definition at line 268 of file qxcbconnection.h.

Referenced by QXcbConnection(), and sync().

◆ m_displayName

QByteArray QXcbConnection::m_displayName
private

Definition at line 276 of file qxcbconnection.h.

Referenced by initializeAllAtoms(), and QXcbConnection().

◆ m_keyboard

QXcbKeyboard* QXcbConnection::m_keyboard
private

Definition at line 278 of file qxcbconnection.h.

Referenced by processXcbEvents(), QXcbConnection(), and ~QXcbConnection().

◆ m_primaryScreen

int QXcbConnection::m_primaryScreen
private

Definition at line 272 of file qxcbconnection.h.

◆ m_screens

QList<QXcbScreen *> QXcbConnection::m_screens
private

Definition at line 271 of file qxcbconnection.h.

Referenced by QXcbConnection(), sync(), and ~QXcbConnection().

◆ m_setup

const xcb_setup_t* QXcbConnection::m_setup
private

Definition at line 269 of file qxcbconnection.h.

Referenced by QXcbConnection().


The documentation for this class was generated from the following files: