summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/x11-event-source.h1
-rw-r--r--source/rofi.c3
-rw-r--r--source/x11-event-source.c19
3 files changed, 15 insertions, 8 deletions
diff --git a/include/x11-event-source.h b/include/x11-event-source.h
index a7521fce..2c129eb0 100644
--- a/include/x11-event-source.h
+++ b/include/x11-event-source.h
@@ -2,4 +2,5 @@
#define ROFI_X11_EVENT_SOURCE_H
GSource * x11_event_source_new ( Display *display );
+void x11_event_source_set_callback ( GSource *source, GSourceFunc callback );
#endif // ROFI_X11_EVENT_SOURCE_H
diff --git a/source/rofi.c b/source/rofi.c
index 85d5f587..3eb1f1b2 100644
--- a/source/rofi.c
+++ b/source/rofi.c
@@ -2436,8 +2436,7 @@ int main ( int argc, char *argv[] )
XFlush ( display );
main_loop = g_main_loop_new ( NULL, FALSE );
GSource *source = x11_event_source_new ( display );
- g_source_attach ( source, NULL );
- g_source_set_callback ( source, main_loop_x11_event_handler, NULL, NULL );
+ x11_event_source_set_callback ( source, main_loop_x11_event_handler );
// Setup signal handling sources.
// SIGHup signal.
diff --git a/source/x11-event-source.c b/source/x11-event-source.c
index 3f307f77..7280a134 100644
--- a/source/x11-event-source.c
+++ b/source/x11-event-source.c
@@ -8,10 +8,10 @@
typedef struct _X11EventSource
{
// Source
- GSource source;
+ GSource source;
// Polling field
gpointer fd_x11;
- Display *display;
+ Display *display;
} X11EventSource;
static gboolean x11_event_source_prepare ( GSource * base, gint * timeout )
@@ -24,7 +24,7 @@ static gboolean x11_event_source_prepare ( GSource * base, gint * timeout )
static gboolean x11_event_source_check ( GSource * base )
{
X11EventSource *xs = (X11EventSource *) base;
- if ( g_source_query_unix_fd (base, xs->fd_x11) ) {
+ if ( g_source_query_unix_fd ( base, xs->fd_x11 ) ) {
return TRUE;
}
return FALSE;
@@ -34,7 +34,7 @@ static gboolean x11_event_source_dispatch ( GSource * base, GSourceFunc callback
{
X11EventSource *xs = (X11EventSource *) base;
if ( callback ) {
- if ( g_source_query_unix_fd (base, xs->fd_x11) ) {
+ if ( g_source_query_unix_fd ( base, xs->fd_x11 ) ) {
callback ( data );
}
}
@@ -52,7 +52,14 @@ GSource * x11_event_source_new ( Display *display )
{
int x11_fd = ConnectionNumber ( display );
X11EventSource *source = (X11EventSource *) g_source_new ( &x11_event_source_funcs, sizeof ( X11EventSource ) );
- source->display = display;
- source->fd_x11 = g_source_add_unix_fd ( (GSource *)source, x11_fd, G_IO_IN | G_IO_ERR );
+ source->display = display;
+ source->fd_x11 = g_source_add_unix_fd ( (GSource *) source, x11_fd, G_IO_IN | G_IO_ERR );
+
+ // Attach it to main loop.
+ g_source_attach ( (GSource *) source, NULL );
return (GSource *) source;
}
+void x11_event_source_set_callback ( GSource *source, GSourceFunc callback )
+{
+ g_source_set_callback ( source, callback, NULL, NULL );
+}