Qt 4.8
qeventdispatcher_x11.cpp
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 QtGui module 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 #include "qeventdispatcher_x11_p.h"
43 
44 #include "qapplication.h"
45 #include "qx11info_x11.h"
46 
47 #include "qt_x11_p.h"
48 #include <private/qeventdispatcher_unix_p.h>
49 
51 
53 {
55 public:
57  : xfd(-1)
58  { }
59  int xfd;
61 };
62 
65 { }
66 
68 { }
69 
70 bool QEventDispatcherX11::processEvents(QEventLoop::ProcessEventsFlags flags)
71 {
73 
74  d->interrupt = false;
76 
77  ulong marker = XNextRequest(X11->display);
78  int nevents = 0;
79  do {
80  while (!d->interrupt) {
81  XEvent event;
83  && !d->queuedUserInputEvents.isEmpty()) {
84  // process a pending user input event
85  event = d->queuedUserInputEvents.takeFirst();
86  } else if (XEventsQueued(X11->display, QueuedAlready)) {
87  // process events from the X server
88  XNextEvent(X11->display, &event);
89 
90  if (flags & QEventLoop::ExcludeUserInputEvents) {
91  // queue user input events
92  switch (event.type) {
93  case ButtonPress:
94  case ButtonRelease:
95  case MotionNotify:
96  case XKeyPress:
97  case XKeyRelease:
98  case EnterNotify:
99  case LeaveNotify:
100  d->queuedUserInputEvents.append(event);
101  continue;
102 
103  case ClientMessage:
104  // only keep the wm_take_focus and
105  // _qt_scrolldone protocols, queue all other
106  // client messages
107  if (event.xclient.format == 32) {
108  if (event.xclient.message_type == ATOM(WM_PROTOCOLS) &&
109  (Atom) event.xclient.data.l[0] == ATOM(WM_TAKE_FOCUS)) {
110  break;
111  } else if (event.xclient.message_type == ATOM(_QT_SCROLL_DONE)) {
112  break;
113  }
114  }
115  d->queuedUserInputEvents.append(event);
116  continue;
117 
118  default:
119  break;
120  }
121  }
122  } else {
123  // no event to process
124  break;
125  }
126 
127  // send through event filter
128  if (filterEvent(&event))
129  continue;
130 
131  nevents++;
132  if (qApp->x11ProcessEvent(&event) == 1)
133  return true;
134 
135  if (event.xany.serial >= marker) {
136  if (XEventsQueued(X11->display, QueuedAfterFlush))
138  goto out;
139  }
140  }
141  } while (!d->interrupt && XEventsQueued(X11->display, QueuedAfterFlush));
142 
143  out:
144  if (!d->interrupt) {
145  const uint exclude_all =
147  if (nevents > 0 && ((uint)flags & exclude_all) == exclude_all) {
149  return nevents > 0;
150  }
151  // return true if we handled events, false otherwise
152  return QEventDispatcherUNIX::processEvents(flags) || (nevents > 0);
153  }
154  return nevents > 0;
155 }
156 
158 {
159  extern uint qGlobalPostedEventsCount(); // from qapplication.cpp
160  return (qGlobalPostedEventsCount() || XPending(X11->display));
161 }
162 
164 {
165  XFlush(X11->display);
166 }
167 
169 {
171  d->xfd = XConnectionNumber(X11->display);
172 }
173 
175 {
177  d->xfd = -1;
178 }
179 
180 int QEventDispatcherX11::select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
181  timeval *timeout)
182 {
184  if (d->xfd > 0) {
185  nfds = qMax(nfds - 1, d->xfd) + 1;
186  FD_SET(d->xfd, readfds);
187  }
188  return QEventDispatcherUNIX::select(nfds, readfds, writefds, exceptfds, timeout);
189 }
190 
double d
Definition: qnumeric_p.h:62
int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, timeval *timeout)
bool filterEvent(void *message)
Sends message through the event filter that was set by setEventFilter().
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
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
#define X11
Definition: qt_x11_p.h:724
#define Q_D(Class)
Definition: qglobal.h:2482
bool processEvents(QEventLoop::ProcessEventsFlags flags)
Processes pending events that match flags until there are no more events to process.
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
union _XEvent XEvent
Definition: qwindowdefs.h:116
#define ATOM(x)
Definition: qt_x11_p.h:723
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
void flush()
Flushes the event queue.
QEventDispatcherX11(QObject *parent=0)
#define qApp
bool hasPendingEvents()
Returns true if there is an event waiting; otherwise returns false.
unsigned int uint
Definition: qglobal.h:996
static void sendPostedEvents()
unsigned long ulong
Definition: qglobal.h:997
Q_CORE_EXPORT uint qGlobalPostedEventsCount()
#define Q_DECLARE_PUBLIC(Class)
Definition: qglobal.h:2477
bool processEvents(QEventLoop::ProcessEventsFlags flags)
Processes pending events that match flags until there are no more events to process.
virtual int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, timeval *timeout)
QObject * parent
Definition: qobject.h:92