]> Dogcows Code - chaz/openbox/blobdiff - obt/xevent.c
parse key/value pairs from the .desktop file and save them in a hashtable
[chaz/openbox] / obt / xevent.c
index e770ddae11b554822cc42da58b546c89d81a6495..1077165766935301c2ac0551491c92d9dd2c6b53 100644 (file)
@@ -43,12 +43,13 @@ struct _ObtXEventBinding
 static void xevent_handler(const XEvent *e, gpointer data);
 static guint window_hash(Window *w) { return *w; }
 static gboolean window_comp(Window *w1, Window *w2) { return *w1 == *w2; }
+static void binding_free(gpointer b);
 
-ObtXEventHandler* xevent_new()
+ObtXEventHandler* xevent_new(void)
 {
     ObtXEventHandler *h;
 
-    h = g_new0(ObtXEventHandler, 1);
+    h = g_slice_new0(ObtXEventHandler);
     h->ref = 1;
 
     return h;
@@ -70,7 +71,7 @@ void xevent_unref(ObtXEventHandler *h)
             g_hash_table_destroy(h->bindings[i]);
         g_free(h->bindings);
 
-        obt_free0(h, ObtXEventHandler, 1);
+        g_slice_free(ObtXEventHandler, h);
     }
 }
 
@@ -85,7 +86,6 @@ void xevent_set_handler(ObtXEventHandler *h, gint type, Window win,
 {
     ObtXEventBinding *b;
 
-    g_assert(win);
     g_assert(func);
 
     /* make sure we have a spot for the event */
@@ -95,17 +95,22 @@ void xevent_set_handler(ObtXEventHandler *h, gint type, Window win,
         for (i = h->num_event_types; i < type + 1; ++i)
             h->bindings[i] = g_hash_table_new_full((GHashFunc)window_hash,
                                                    (GEqualFunc)window_comp,
-                                                   NULL, g_free);
+                                                   NULL, binding_free);
         h->num_event_types = type + 1;
     }
 
-    b = g_new(ObtXEventBinding, 1);
+    b = g_slice_new(ObtXEventBinding);
     b->win = win;
     b->func = func;
     b->data = data;
     g_hash_table_replace(h->bindings[type], &b->win, b);
 }
 
+static void binding_free(gpointer b)
+{
+    g_slice_free(ObtXEventBinding, b);
+}
+
 void xevent_remove_handler(ObtXEventHandler *h, gint type, Window win)
 {
     g_assert(type < h->num_event_types);
@@ -119,8 +124,14 @@ static void xevent_handler(const XEvent *e, gpointer data)
     ObtXEventHandler *h;
     ObtXEventBinding *b;
 
+    h = data;
+
     if (e->type < h->num_event_types) {
-        h = data;
+        const gint all = OBT_XEVENT_ALL_WINDOWS;
+        /* run the all_windows handler first */
+        b = g_hash_table_lookup(h->bindings[e->xany.type], &all);
+        if (b) b->func(e, b->data);
+        /* then run the per-window handler */
         b = g_hash_table_lookup(h->bindings[e->xany.type], &e->xany.window);
         if (b) b->func(e, b->data);
     }
This page took 0.02147 seconds and 4 git commands to generate.