2 * AT-SPI - Assistive Technology Service Provider Interface
3 * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
5 * Copyright 2009 Nokia.
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
25 #include "event-source.h"
27 typedef struct _DisplaySource
32 GPollFD event_poll_fd;
35 /*---------------------------------------------------------------------------*/
37 static void (*_spi_default_filter) (XEvent*, void*) = NULL;
38 static void* _spi_default_filter_data = NULL;
40 /*---------------------------------------------------------------------------*/
43 event_prepare (GSource *source, gint *timeout)
45 Display *display = ((DisplaySource *)source)->display;
49 retval = XPending (display);
55 event_check (GSource *source)
57 DisplaySource *display_source = (DisplaySource*)source;
60 if (display_source->event_poll_fd.revents & G_IO_IN)
61 retval = XPending (display_source->display);
69 event_dispatch (GSource *source, GSourceFunc callback, gpointer user_data)
71 Display *display = ((DisplaySource*)source)->display;
74 /* TODO - Should this be "if (XPending (display))"?
75 * The effect of this might be to run other main loop functions
76 * before dispatching the next XEvent.
78 while (XPending (display))
80 XNextEvent (display, &xevent);
88 if (XFilterEvent (&xevent, None))
92 if (_spi_default_filter)
94 _spi_default_filter (&xevent, _spi_default_filter_data);
101 /*---------------------------------------------------------------------------*/
103 static GSourceFuncs event_funcs = {
111 display_source_new (Display *display)
113 GSource *source = g_source_new (&event_funcs, sizeof (DisplaySource));
114 DisplaySource *display_source = (DisplaySource *) source;
116 display_source->display = display;
121 /*---------------------------------------------------------------------------*/
123 static DisplaySource *spi_display_source = NULL;
126 spi_events_init (Display *display)
130 int connection_number = ConnectionNumber (display);
132 source = display_source_new (display);
133 spi_display_source = (DisplaySource*) source;
135 g_source_set_priority (source, G_PRIORITY_DEFAULT);
137 spi_display_source->event_poll_fd.fd = connection_number;
138 spi_display_source->event_poll_fd.events = G_IO_IN;
140 g_source_add_poll (source, &spi_display_source->event_poll_fd);
141 g_source_set_can_recurse (source, TRUE);
142 g_source_attach (source, NULL);
148 if (spi_display_source)
150 g_source_destroy ((GSource *) spi_display_source);
151 g_source_unref ((GSource *) spi_display_source);
152 spi_display_source = NULL;
157 spi_set_events (long event_mask)
159 long xevent_mask = StructureNotifyMask | PropertyChangeMask;
160 xevent_mask |= event_mask;
162 XSelectInput (spi_display_source->display,
163 DefaultRootWindow (spi_display_source->display),
168 spi_set_filter (void (*filter) (XEvent*, void*), void* data)
170 _spi_default_filter = filter;
171 _spi_default_filter_data = data;
174 /*END------------------------------------------------------------------------*/