Qt 4.8
qeventdispatcher_glib_qpa.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 QtCore 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 
49 #include <glib.h>
50 #include "qapplication_p.h"
51 
52 #include <qdebug.h>
53 
55 
57 {
58  GSource source;
60 };
61 
62 static gboolean userEventSourcePrepare(GSource *s, gint *timeout)
63 {
64  Q_UNUSED(s)
65  Q_UNUSED(timeout)
66 
68 }
69 
70 static gboolean userEventSourceCheck(GSource *source)
71 {
72  return userEventSourcePrepare(source, 0);
73 }
74 
75 static gboolean userEventSourceDispatch(GSource *s, GSourceFunc, gpointer)
76 {
77  GUserEventSource * source = reinterpret_cast<GUserEventSource *>(s);
78 
82  if (!event)
83  break;
84 
85  // send through event filter
86  if (source->q->filterEvent(event)) {
87  delete event;
88  continue;
89  }
90  QApplicationPrivate::processWindowSystemEvent(event);
91  delete event;
92  }
93 
94  return true;
95 }
96 
97 
98 static GSourceFuncs userEventSourceFuncs = {
102  NULL,
103  NULL,
104  NULL
105 };
106 
108  : QEventDispatcherGlibPrivate(context)
109 {
110  userEventSource = reinterpret_cast<GUserEventSource *>(g_source_new(&userEventSourceFuncs,
111  sizeof(GUserEventSource)));
112  userEventSource->q = 0;
113  g_source_set_can_recurse(&userEventSource->source, true);
114  g_source_attach(&userEventSource->source, mainContext);
115 }
116 
117 
120 {
122  d->userEventSource->q = this;
123 }
124 
126 {
128 
129  g_source_destroy(&d->userEventSource->source);
130  g_source_unref(&d->userEventSource->source);
131  d->userEventSource = 0;
132 }
133 
134 bool QPAEventDispatcherGlib::processEvents(QEventLoop::ProcessEventsFlags flags)
135 {
136  static bool init = false;
137  if (!init) {
138  if (QApplicationPrivate::platformIntegration()->createEventLoopIntegration()) {
139  qWarning("Eventloop integration is not supported by the glib event dispatcher");
140  qWarning("Use the UNIX event dispatcher by defining environment variable QT_NO_GLIB=1");
141  }
142  init = true;
143  }
145 }
146 
double d
Definition: qnumeric_p.h:62
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
QPAEventDispatcherGlib(QObject *parent=0)
static GSourceFuncs userEventSourceFuncs
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
#define Q_D(Class)
Definition: qglobal.h:2482
static gboolean userEventSourcePrepare(GSource *s, gint *timeout)
static gboolean userEventSourceCheck(GSource *source)
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
static bool init
Q_CORE_EXPORT void qWarning(const char *,...)
QPAEventDispatcherGlib * q
bool processEvents(QEventLoop::ProcessEventsFlags flags)
Processes pending events that match flags until there are no more events to process.
static gboolean userEventSourceDispatch(GSource *s, GSourceFunc, gpointer)
static WindowSystemEvent * getWindowSystemEvent()
QObject * parent
Definition: qobject.h:92
struct _GMainContext GMainContext
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
bool processEvents(QEventLoop::ProcessEventsFlags flags)
Processes pending events that match flags until there are no more events to process.
QPAEventDispatcherGlibPrivate(GMainContext *context=0)