]> Dogcows Code - chaz/openbox/commitdiff
make the mainloop not depend on an X display, and make it uses the obt_display automa...
authorDana Jansens <danakj@orodu.net>
Sat, 28 Jul 2007 19:38:29 +0000 (15:38 -0400)
committerDana Jansens <danakj@orodu.net>
Sun, 20 Jan 2008 06:36:56 +0000 (01:36 -0500)
obt/mainloop.c
obt/mainloop.h
openbox/openbox.c

index 9797770d9f3e19528a2c29026b3cd7fececf565f..f6f2fa07b76349c982a8c874af9097899a8590ac 100644 (file)
@@ -18,6 +18,7 @@
 */
 
 #include "obt/mainloop.h"
+#include "obt/display.h"
 #include "obt/util.h"
 
 #include <stdio.h>
@@ -67,6 +68,7 @@ static gint core_signals[] =
 static void sighandler(gint sig);
 static void timer_dispatch(ObtMainLoop *loop, GTimeVal **wait);
 static void fd_handler_destroy(gpointer data);
+static void calc_max_fd(ObtMainLoop *loop);
 
 struct _ObtMainLoop
 {
@@ -138,17 +140,15 @@ struct _ObtMainLoopFdHandlerType
     GDestroyNotify destroy;
 };
 
-ObtMainLoop *obt_main_loop_new(Display *display)
+ObtMainLoop *obt_main_loop_new()
 {
     ObtMainLoop *loop;
 
     loop = g_new0(ObtMainLoop, 1);
     loop->ref = 1;
-    loop->display = display;
-    loop->fd_x = ConnectionNumber(display);
     FD_ZERO(&loop->fd_set);
-    FD_SET(loop->fd_x, &loop->fd_set);
-    loop->fd_max = loop->fd_x;
+    loop->fd_x = -1;
+    loop->fd_max = -1;
 
     loop->fd_handlers = g_hash_table_new_full(g_int_hash, g_int_equal,
                                               NULL, fd_handler_destroy);
@@ -339,11 +339,21 @@ void obt_main_loop_x_add(ObtMainLoop *loop,
     h->func = handler;
     h->data = data;
     h->destroy = notify;
+
+    if (!loop->x_handlers) {
+        g_assert(obt_display); /* is the display open? */
+
+        loop->display = obt_display;
+        loop->fd_x = ConnectionNumber(loop->display);
+        FD_SET(loop->fd_x, &loop->fd_set);
+        calc_max_fd(loop);
+    }
+
     loop->x_handlers = g_slist_prepend(loop->x_handlers, h);
 }
 
 void obt_main_loop_x_remove(ObtMainLoop *loop,
-                           ObtMainLoopXHandler handler)
+                            ObtMainLoopXHandler handler)
 {
     GSList *it, *next;
 
@@ -356,6 +366,11 @@ void obt_main_loop_x_remove(ObtMainLoop *loop,
             g_free(h);
         }
     }
+
+    if (!loop->x_handlers) {
+        FD_CLR(loop->fd_x, &loop->fd_set);
+        calc_max_fd(loop);
+    }
 }
 
 /*** SIGNAL WATCHERS ***/
@@ -502,6 +517,7 @@ void obt_main_loop_fd_remove(ObtMainLoop *loop,
                              gint fd)
 {
     g_hash_table_remove(loop->fd_handlers, &fd);
+    calc_max_fd(loop);
 }
 
 /*** TIMEOUTS ***/
index cdc0bd298ccfcc8902f5e5fc85a899fed2a3a1fb..cce7d5b512fa7f619f9178ca02efe6dce53def3c 100644 (file)
@@ -27,7 +27,7 @@ G_BEGIN_DECLS
 
 typedef struct _ObtMainLoop ObtMainLoop;
 
-ObtMainLoop *obt_main_loop_new(Display *display);
+ObtMainLoop *obt_main_loop_new();
 void        obt_main_loop_ref(ObtMainLoop *loop);
 void        obt_main_loop_unref(ObtMainLoop *loop);
 
index c9979325e3aee6fece82e91e7f80b49877f32484..8aefd76adcee0b9d26939eb41a9a23f9fc7cc427 100644 (file)
@@ -151,7 +151,7 @@ gint main(gint argc, gchar **argv)
         exit(EXIT_SUCCESS);
     }
 
-    ob_main_loop = obt_main_loop_new(obt_display);
+    ob_main_loop = obt_main_loop_new();
 
     /* set up signal handler */
     obt_main_loop_signal_add(ob_main_loop, SIGUSR1, signal_handler, NULL,NULL);
This page took 0.028871 seconds and 4 git commands to generate.