summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Davenport <qball@gmpclient.org>2016-01-18 22:02:07 +0100
committerDave Davenport <qball@gmpclient.org>2016-01-18 22:02:07 +0100
commit42ee408d0f9dbeafcfb59ff71b0fa080d4902608 (patch)
treefb4028e80150525839c8fe6a5b38e99c381522a4
parent6692f364233dbf55d32ef55181da193b4976cf91 (diff)
Move X11EventSource into separate file.
-rw-r--r--Makefile.am2
-rw-r--r--include/x11-event-source.h5
-rw-r--r--source/rofi.c55
-rw-r--r--source/x11-event-source.c60
4 files changed, 71 insertions, 51 deletions
diff --git a/Makefile.am b/Makefile.am
index 63798985..e3af6059 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -44,6 +44,7 @@ rofi_SOURCES=\
source/i3-support.c\
source/xrmoptions.c\
source/x11-helper.c\
+ source/x11-event-source.c\
source/dialogs/run.c\
source/dialogs/ssh.c\
source/dialogs/drun.c\
@@ -65,6 +66,7 @@ rofi_SOURCES=\
include/xrmoptions.h\
include/i3-support.h\
include/x11-helper.h\
+ include/x11-event-source.h\
include/dialogs/ssh.h\
include/dialogs/run.h\
include/dialogs/drun.h\
diff --git a/include/x11-event-source.h b/include/x11-event-source.h
new file mode 100644
index 00000000..a7521fce
--- /dev/null
+++ b/include/x11-event-source.h
@@ -0,0 +1,5 @@
+#ifndef ROFI_X11_EVENT_SOURCE_H
+#define ROFI_X11_EVENT_SOURCE_H
+
+GSource * x11_event_source_new ( Display *display );
+#endif // ROFI_X11_EVENT_SOURCE_H
diff --git a/source/rofi.c b/source/rofi.c
index 2314495e..a350236c 100644
--- a/source/rofi.c
+++ b/source/rofi.c
@@ -60,6 +60,7 @@
#include "textbox.h"
#include "scrollbar.h"
#include "x11-helper.h"
+#include "x11-event-source.h"
#include "xrmoptions.h"
#include "dialogs/dialogs.h"
@@ -2232,50 +2233,6 @@ static void error_trap_push ( G_GNUC_UNUSED SnDisplay *display, G_GNUC_UNUSED Di
++error_trap_depth;
}
-/**
- * Custom X11 Source implementation.
- */
-typedef struct _X11EventSource
-{
- // Source
- GSource source;
- // Polling field
- GPollFD fd_x11;
-} X11EventSource;
-
-static gboolean x11_event_source_prepare ( G_GNUC_UNUSED GSource * base, gint * timeout )
-{
- *timeout = -1;
- return XPending ( display );
-}
-
-static gboolean x11_event_source_check ( GSource * base )
-{
- X11EventSource *xs = (X11EventSource *) base;
- if ( xs->fd_x11.revents ) {
- return TRUE;
- }
- return FALSE;
-}
-
-static gboolean x11_event_source_dispatch ( GSource * base, GSourceFunc callback, gpointer data )
-{
- X11EventSource *xs = (X11EventSource *) base;
- if ( callback ) {
- if ( xs->fd_x11.revents ) {
- callback ( data );
- }
- }
- return G_SOURCE_CONTINUE;;
-}
-
-static GSourceFuncs x11_event_source_funcs = {
- x11_event_source_prepare,
- x11_event_source_check,
- x11_event_source_dispatch,
- NULL
-};
-
static void error_trap_pop ( G_GNUC_UNUSED SnDisplay *display, Display *xdisplay )
{
if ( error_trap_depth == 0 ) {
@@ -2503,14 +2460,10 @@ int main ( int argc, char *argv[] )
// It also listens from messages from the signal process.
XSelectInput ( display, DefaultRootWindow ( display ), KeyPressMask );
XFlush ( display );
- int x11_fd = ConnectionNumber ( display );
- X11EventSource *source = (X11EventSource *) g_source_new ( &x11_event_source_funcs, sizeof ( X11EventSource ) );
- source->fd_x11.fd = x11_fd;
- source->fd_x11.events = G_IO_IN | G_IO_ERR;
- g_source_add_poll ( (GSource *) source, &source->fd_x11 );
main_loop = g_main_loop_new ( NULL, FALSE );
- g_source_attach ( (GSource *) source, NULL );
- g_source_set_callback ( (GSource *) source, main_loop_x11_event_handler, NULL, NULL );
+ GSource *source = x11_event_source_new ( display );
+ g_source_attach ( source, NULL );
+ g_source_set_callback ( source, main_loop_x11_event_handler, NULL, NULL );
// Setup signal handling sources.
// SIGHup signal.
diff --git a/source/x11-event-source.c b/source/x11-event-source.c
new file mode 100644
index 00000000..fe3544f6
--- /dev/null
+++ b/source/x11-event-source.c
@@ -0,0 +1,60 @@
+#include <glib.h>
+#include <X11/Xlib.h>
+#include "x11-event-source.h"
+
+/**
+ * Custom X11 Source implementation.
+ */
+typedef struct _X11EventSource
+{
+ // Source
+ GSource source;
+ // Polling field
+ GPollFD fd_x11;
+ Display *display;
+} X11EventSource;
+
+static gboolean x11_event_source_prepare ( GSource * base, gint * timeout )
+{
+ X11EventSource *xs = (X11EventSource *) base;
+ *timeout = -1;
+ return XPending ( xs->display );
+}
+
+static gboolean x11_event_source_check ( GSource * base )
+{
+ X11EventSource *xs = (X11EventSource *) base;
+ if ( xs->fd_x11.revents ) {
+ return TRUE;
+ }
+ return FALSE;
+}
+
+static gboolean x11_event_source_dispatch ( GSource * base, GSourceFunc callback, gpointer data )
+{
+ X11EventSource *xs = (X11EventSource *) base;
+ if ( callback ) {
+ if ( xs->fd_x11.revents ) {
+ callback ( data );
+ }
+ }
+ return G_SOURCE_CONTINUE;;
+}
+
+static GSourceFuncs x11_event_source_funcs = {
+ x11_event_source_prepare,
+ x11_event_source_check,
+ x11_event_source_dispatch,
+ NULL
+};
+
+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.fd = x11_fd;
+ source->fd_x11.events = G_IO_IN | G_IO_ERR;
+ g_source_add_poll ( (GSource *) source, &source->fd_x11 );
+ return (GSource *) source;
+}