]> Pileus Git - ~andy/gtk/blob - gdk/broadway/gdkeventsource.c
[broadway] Rename X11 -> Broadway in all code
[~andy/gtk] / gdk / broadway / gdkeventsource.c
1 /* GDK - The GIMP Drawing Kit
2  * Copyright (C) 2009 Carlos Garnacho <carlosg@gnome.org>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19
20 #include "config.h"
21
22 #include "gdkeventsource.h"
23
24 #include "gdkinternals.h"
25
26 static gboolean gdk_event_source_prepare  (GSource     *source,
27                                            gint        *timeout);
28 static gboolean gdk_event_source_check    (GSource     *source);
29 static gboolean gdk_event_source_dispatch (GSource     *source,
30                                            GSourceFunc  callback,
31                                            gpointer     user_data);
32 static void     gdk_event_source_finalize (GSource     *source);
33
34 #define HAS_FOCUS(toplevel)                           \
35   ((toplevel)->has_focus || (toplevel)->has_pointer_focus)
36
37 struct _GdkEventSource
38 {
39   GSource source;
40
41   GdkDisplay *display;
42   GPollFD event_poll_fd;
43 };
44
45 static GSourceFuncs event_funcs = {
46   gdk_event_source_prepare,
47   gdk_event_source_check,
48   gdk_event_source_dispatch,
49   gdk_event_source_finalize
50 };
51
52 static GList *event_sources = NULL;
53
54 static gboolean
55 gdk_event_source_prepare (GSource *source,
56                           gint    *timeout)
57 {
58   GdkDisplay *display = ((GdkEventSource*) source)->display;
59   gboolean retval;
60
61   GDK_THREADS_ENTER ();
62
63   *timeout = -1;
64   retval = (_gdk_event_queue_find_first (display) != NULL);
65
66   GDK_THREADS_LEAVE ();
67
68   return retval;
69 }
70
71 static gboolean
72 gdk_event_source_check (GSource *source)
73 {
74   GdkEventSource *event_source = (GdkEventSource*) source;
75   gboolean retval;
76
77   GDK_THREADS_ENTER ();
78
79   if (event_source->event_poll_fd.revents & G_IO_IN)
80     retval = (_gdk_event_queue_find_first (event_source->display) != NULL);
81   else
82     retval = FALSE;
83
84   GDK_THREADS_LEAVE ();
85
86   return retval;
87 }
88
89 void
90 _gdk_events_queue (GdkDisplay *display)
91 {
92 }
93
94 static gboolean
95 gdk_event_source_dispatch (GSource     *source,
96                            GSourceFunc  callback,
97                            gpointer     user_data)
98 {
99   GdkDisplay *display = ((GdkEventSource*) source)->display;
100   GdkEvent *event;
101
102   GDK_THREADS_ENTER ();
103
104   event = gdk_display_get_event (display);
105
106   if (event)
107     {
108       if (_gdk_event_func)
109         (*_gdk_event_func) (event, _gdk_event_data);
110
111       gdk_event_free (event);
112     }
113
114   GDK_THREADS_LEAVE ();
115
116   return TRUE;
117 }
118
119 static void
120 gdk_event_source_finalize (GSource *source)
121 {
122   GdkEventSource *event_source = (GdkEventSource *)source;
123
124   event_sources = g_list_remove (event_sources, event_source);
125 }
126
127 GSource *
128 gdk_event_source_new (GdkDisplay *display)
129 {
130   GSource *source;
131   GdkEventSource *event_source;
132   char *name;
133
134   source = g_source_new (&event_funcs, sizeof (GdkEventSource));
135   name = g_strdup_printf ("GDK Broadway Event source (%s)",
136                           gdk_display_get_name (display));
137   g_source_set_name (source, name);
138   g_free (name);
139   event_source = (GdkEventSource *) source;
140   event_source->display = display;
141
142   g_source_set_priority (source, GDK_PRIORITY_EVENTS);
143   g_source_set_can_recurse (source, TRUE);
144   g_source_attach (source, NULL);
145
146   event_sources = g_list_prepend (event_sources, source);
147
148   return source;
149 }
150
151 void
152 gdk_event_source_select_events (GdkEventSource *source,
153                                 Window          window,
154                                 GdkEventMask    event_mask,
155                                 unsigned int    extra_x_mask)
156 {
157 }
158
159 gboolean
160 gdk_events_pending (void)
161 {
162   GList *tmp_list;
163
164   for (tmp_list = event_sources; tmp_list; tmp_list = tmp_list->next)
165     {
166       GdkEventSource *tmp_source = tmp_list->data;
167       GdkDisplay *display = tmp_source->display;
168
169       if (_gdk_event_queue_find_first (display))
170         return TRUE;
171     }
172
173   return FALSE;
174 }