1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** All rights reserved.
|
---|
5 | ** Contact: Nokia Corporation (qt-info@nokia.com)
|
---|
6 | **
|
---|
7 | ** This file is part of the QtGui module of the Qt Toolkit.
|
---|
8 | **
|
---|
9 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
10 | ** Commercial Usage
|
---|
11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
12 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
13 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
14 | ** a written agreement between you and Nokia.
|
---|
15 | **
|
---|
16 | ** GNU Lesser General Public License Usage
|
---|
17 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
18 | ** General Public License version 2.1 as published by the Free Software
|
---|
19 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
20 | ** packaging of this file. Please review the following information to
|
---|
21 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
23 | **
|
---|
24 | ** In addition, as a special exception, Nokia gives you certain additional
|
---|
25 | ** rights. These rights are described in the Nokia Qt LGPL Exception
|
---|
26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
---|
27 | **
|
---|
28 | ** GNU General Public License Usage
|
---|
29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
30 | ** General Public License version 3.0 as published by the Free Software
|
---|
31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
32 | ** packaging of this file. Please review the following information to
|
---|
33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
35 | **
|
---|
36 | ** If you have questions regarding the use of this file, please contact
|
---|
37 | ** Nokia at qt-info@nokia.com.
|
---|
38 | ** $QT_END_LICENSE$
|
---|
39 | **
|
---|
40 | ****************************************************************************/
|
---|
41 |
|
---|
42 | #include "qeventdispatcher_glib_qws_p.h"
|
---|
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 |
|
---|
55 | QT_BEGIN_NAMESPACE
|
---|
56 |
|
---|
57 | // from qapplication_qws.cpp
|
---|
58 | extern QWSDisplay* qt_fbdpy; // QWS `display'
|
---|
59 |
|
---|
60 | //from qwindowsystem_qws.cpp
|
---|
61 | extern QList<QWSCommand*> *qt_get_server_queue();
|
---|
62 |
|
---|
63 | struct GQWSEventSource
|
---|
64 | {
|
---|
65 | GSource source;
|
---|
66 | QEventLoop::ProcessEventsFlags flags;
|
---|
67 | QWSEventDispatcherGlib *q;
|
---|
68 | QWSEventDispatcherGlibPrivate *d;
|
---|
69 | };
|
---|
70 |
|
---|
71 | class QWSEventDispatcherGlibPrivate : public QEventDispatcherGlibPrivate
|
---|
72 | {
|
---|
73 | Q_DECLARE_PUBLIC(QWSEventDispatcherGlib)
|
---|
74 |
|
---|
75 | public:
|
---|
76 | QWSEventDispatcherGlibPrivate();
|
---|
77 | GQWSEventSource *qwsEventSource;
|
---|
78 | QList<QWSEvent*> queuedUserInputEvents;
|
---|
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;
|
---|
104 | if (!(source->flags & QEventLoop::ExcludeUserInputEvents)
|
---|
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 |
|
---|
111 | if (source->flags & QEventLoop::ExcludeUserInputEvents) {
|
---|
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 = {
|
---|
144 | qwsEventSourcePrepare,
|
---|
145 | qwsEventSourceCheck,
|
---|
146 | qwsEventSourceDispatch,
|
---|
147 | NULL,
|
---|
148 | NULL,
|
---|
149 | NULL
|
---|
150 | };
|
---|
151 |
|
---|
152 | QWSEventDispatcherGlibPrivate::QWSEventDispatcherGlibPrivate()
|
---|
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 |
|
---|
165 | QWSEventDispatcherGlib::QWSEventDispatcherGlib(QObject *parent)
|
---|
166 | : QEventDispatcherGlib(*new QWSEventDispatcherGlibPrivate, parent)
|
---|
167 | {
|
---|
168 | }
|
---|
169 |
|
---|
170 | QWSEventDispatcherGlib::~QWSEventDispatcherGlib()
|
---|
171 | {
|
---|
172 | Q_D(QWSEventDispatcherGlib);
|
---|
173 |
|
---|
174 | g_source_destroy(&d->qwsEventSource->source);
|
---|
175 | d->qwsEventSource = 0;
|
---|
176 | }
|
---|
177 |
|
---|
178 | bool QWSEventDispatcherGlib::processEvents(QEventLoop::ProcessEventsFlags flags)
|
---|
179 | {
|
---|
180 | Q_D(QWSEventDispatcherGlib);
|
---|
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 |
|
---|
188 | void QWSEventDispatcherGlib::startingUp()
|
---|
189 | {
|
---|
190 | Q_D(QWSEventDispatcherGlib);
|
---|
191 | d->qwsEventSource->q = this;
|
---|
192 | d->qwsEventSource->d = d;
|
---|
193 | }
|
---|
194 |
|
---|
195 | QT_END_NAMESPACE
|
---|