Qt 4.8
qeventdispatcher_glib_qws.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 
43 
44 #include "qapplication.h"
45 
46 #include "qplatformdefs.h"
47 #include "qapplication.h"
48 #include "private/qwscommand_qws_p.h"
49 #include "qwsdisplay_qws.h"
50 #include "qwsevent_qws.h"
51 #include "qwindowsystem_qws.h"
52 
53 #include <glib.h>
54 
56 
57 // from qapplication_qws.cpp
58 extern QWSDisplay* qt_fbdpy; // QWS `display'
59 
60 //from qwindowsystem_qws.cpp
62 
64 {
65  GSource source;
66  QEventLoop::ProcessEventsFlags flags;
69 };
70 
72 {
74 
75 public:
79 };
80 
81 static gboolean qwsEventSourcePrepare(GSource *s, gint *timeout)
82 {
83  if (timeout)
84  *timeout = -1;
85  GQWSEventSource *source = reinterpret_cast<GQWSEventSource *>(s);
86  return qt_fbdpy->eventPending() || !source->d->queuedUserInputEvents.isEmpty()
87  || !qt_get_server_queue()->isEmpty() ;
88 }
89 
90 static gboolean qwsEventSourceCheck(GSource *s)
91 {
92  GQWSEventSource *source = reinterpret_cast<GQWSEventSource *>(s);
93  return qt_fbdpy->eventPending() || !source->d->queuedUserInputEvents.isEmpty()
94  || !qt_get_server_queue()->isEmpty() ;
95 }
96 
97 static gboolean qwsEventSourceDispatch(GSource *s, GSourceFunc callback, gpointer user_data)
98 {
99  GQWSEventSource *source = reinterpret_cast<GQWSEventSource *>(s);
100 
101  //??? ulong marker = XNextRequest(X11->display);
102  do {
103  QWSEvent *event;
105  && !source->d->queuedUserInputEvents.isEmpty()) {
106  // process a pending user input event
107  event = source->d->queuedUserInputEvents.takeFirst();
108  } else if (qt_fbdpy->eventPending()) {
109  event = qt_fbdpy->getEvent();
110 
112  // queue user input events
113 
114  if (event->type == QWSEvent::Mouse || event->type == QWSEvent::Key) {
115  source->d->queuedUserInputEvents.append(event);
116  continue;
117  }
118  }
119  } else {
120  // no event to process
121  break;
122  }
123 
124  // send through event filter
125  if (source->q->filterEvent(event)) {
126  delete event;
127  continue;
128  }
129 
130  bool ret = qApp->qwsProcessEvent(event) == 1;
131  delete event;
132  if (ret) {
133  return true;
134  }
135 
136  } while (qt_fbdpy->eventPending());
137 
138  if (callback)
139  callback(user_data);
140  return true;
141 }
142 
143 static GSourceFuncs qwsEventSourceFuncs = {
147  NULL,
148  NULL,
149  NULL
150 };
151 
153 {
154  qwsEventSource = reinterpret_cast<GQWSEventSource *>(g_source_new(&qwsEventSourceFuncs,
155  sizeof(GQWSEventSource)));
156  g_source_set_can_recurse(&qwsEventSource->source, true);
157 
158  qwsEventSource->flags = QEventLoop::AllEvents;
159  qwsEventSource->q = 0;
160  qwsEventSource->d = 0;
161 
162  g_source_attach(&qwsEventSource->source, mainContext);
163 }
164 
167 {
168 }
169 
171 {
173 
174  g_source_destroy(&d->qwsEventSource->source);
175  d->qwsEventSource = 0;
176 }
177 
178 bool QWSEventDispatcherGlib::processEvents(QEventLoop::ProcessEventsFlags flags)
179 {
181  QEventLoop::ProcessEventsFlags saved_flags = d->qwsEventSource->flags;
182  d->qwsEventSource->flags = flags;
183  bool returnValue = QEventDispatcherGlib::processEvents(flags);
184  d->qwsEventSource->flags = saved_flags;
185  return returnValue;
186 }
187 
189 {
191  d->qwsEventSource->q = this;
192  d->qwsEventSource->d = d;
193 }
194 
double d
Definition: qnumeric_p.h:62
The QWSDisplay class provides a display for QWS; it is an internal class.
static gboolean qwsEventSourceDispatch(GSource *s, GSourceFunc callback, gpointer user_data)
static void callback(AuServer *, AuEventHandlerRec *, AuEvent *e, AuPointer p)
Definition: qsound_x11.cpp:170
static gboolean qwsEventSourcePrepare(GSource *s, gint *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
EventRef event
QWSEventDispatcherGlib * q
static gboolean qwsEventSourceCheck(GSource *s)
QWSEventDispatcherGlib(QObject *parent=0)
bool eventPending() const
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
#define Q_D(Class)
Definition: qglobal.h:2482
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
The QWSEvent class encapsulates an event in Qt for Embedded Linux.
Definition: qwsevent_qws.h:59
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
T takeFirst()
Removes the first item in the list and returns it.
Definition: qlist.h:489
#define qApp
static GSourceFuncs qwsEventSourceFuncs
QWSDisplay * qt_fbdpy
bool processEvents(QEventLoop::ProcessEventsFlags flags)
Processes pending events that match flags until there are no more events to process.
QWSEventDispatcherGlibPrivate * d
QWSEvent * getEvent()
#define Q_DECLARE_PUBLIC(Class)
Definition: qglobal.h:2477
QList< QWSCommand * > * qt_get_server_queue()
QEventLoop::ProcessEventsFlags flags
bool processEvents(QEventLoop::ProcessEventsFlags flags)
Processes pending events that match flags until there are no more events to process.
The QList class is a template class that provides lists.
Definition: qdatastream.h:62