]> Dogcows Code - chaz/openbox/commitdiff
all events are dispatched
authorDana Jansens <danakj@orodu.net>
Mon, 17 Mar 2003 20:16:32 +0000 (20:16 +0000)
committerDana Jansens <danakj@orodu.net>
Mon, 17 Mar 2003 20:16:32 +0000 (20:16 +0000)
openbox/client.c
openbox/dispatch.c
openbox/dispatch.h
openbox/event.c
openbox/focus.c
openbox/openbox.c
openbox/screen.c

index fcc7fd6ae2a2e6820ede0bf1df35409ceb5ff3ed..4537f856f4345c3b0ad1aac8e440a4b623b4a40e 100644 (file)
@@ -7,6 +7,7 @@
 #include "event.h"
 #include "focus.h"
 #include "stacking.h"
+#include "dispatch.h"
 
 #include <glib.h>
 #include <X11/Xutil.h>
@@ -194,10 +195,12 @@ void client_manage(Window window)
 
     screen_update_struts();
 
-    /*HOOKFIRECLIENT(managed, client);XXX*/
+    dispatch_client(Event_Client_New, client);
 
     client_showhide(client);
 
+    dispatch_client(Event_Client_Mapped, client);
+
     /* grab all mouse bindings */
     /*pointer_grab_all(client, TRUE);XXX*/
 
@@ -220,7 +223,7 @@ void client_unmanage(Client *client)
 
     g_message("Unmanaging window: %lx", client->window);
 
-    /*HOOKFIRECLIENT(closed, client);XXX*/
+    dispatch_client(Event_Client_Destroy, client);
 
     /* remove the window from our save set */
     XChangeSaveSet(ob_display, client->window, SetModeDelete);
@@ -923,7 +926,7 @@ void client_update_wmhints(Client *self)
        /* fire the urgent callback if we're mapped, otherwise, wait until
           after we're mapped */
        if (self->frame)
-           /*HOOKFIRECLIENT(urgent, self)XXX*/;
+            dispatch_client(Event_Client_Urgent, self);
     }
 }
 
@@ -1218,7 +1221,7 @@ static void client_showhide(Client *self)
     else
         engine_frame_hide(self->frame);
 
-    /*HOOKFIRECLIENT(visible, self);XXX*/
+    dispatch_client(Event_Client_Visible, self);
 }
 
 gboolean client_normal(Client *self) {
@@ -1243,7 +1246,7 @@ static void client_apply_startup_state(Client *self)
        client_shade(self, TRUE);
     }
     if (self->urgent)
-       /*HOOKFIRECLIENT(urgent, self)XXX*/;
+        dispatch_client(Event_Client_Urgent, self);
   
     if (self->max_vert && self->max_horz) {
        self->max_vert = self->max_horz = FALSE;
index c710dec73bc55284c6f03b8756ff340c09b0bda1..f65a723afdbda38d0538ab42bd97fcc7dada436a 100644 (file)
@@ -1,4 +1,5 @@
 #include "dispatch.h"
+#include "extensions.h"
 
 #include <glib.h>
 
@@ -26,8 +27,10 @@ void dispatch_shutdown()
     guint i;
     EventType j;
 
-    for (i = 0, j = 1; j < EVENT_RANGE; ++i, j <<= 1)
+    for (i = 0, j = 1; j < EVENT_RANGE; ++i, j <<= 1) {
         g_slist_free(funcs[i]);
+        funcs[i] = NULL;
+    }
 
     g_free(funcs);
 }
@@ -47,7 +50,7 @@ void dispatch_register(EventHandler h, EventMask mask)
     }
 }
 
-void dispatch_x(XEvent *xe)
+void dispatch_x(XEvent *xe, Client *c)
 {
     EventType e;
     guint i;
@@ -77,11 +80,20 @@ void dispatch_x(XEvent *xe)
         e = Event_X_MotionNotify;
         break;
     default:
+       /* XKB events */
+       if (xe->type == extensions_xkb_event_basep) {
+           switch (((XkbAnyEvent*)&e)->xkb_type) {
+           case XkbBellNotify:
+               e = Event_X_Bell;
+               break;
+           }
+       }
         return;
     }
 
     obe.type = e;
-    obe.data.x = xe;
+    obe.data.x.e = xe;
+    obe.data.x.client = c;
 
     i = 0;
     while (e > 1) {
index c8371b990f93f6cbfff411fa522f7ba5e8330572..9561e7e6088a1775b538ef993f8ab838e0842bf1 100644 (file)
@@ -15,26 +15,35 @@ typedef enum {
     Event_X_ButtonPress   = 1 << 4,
     Event_X_ButtonRelease = 1 << 5,
     Event_X_MotionNotify  = 1 << 6,
+    Event_X_Bell          = 1 << 7,
 
-    Event_Client_New      = 1 << 7, /* new window, before mapping */
-    Event_Client_Mapped   = 1 << 8, /* new window, after mapping */
-    Event_Client_Destroy  = 1 << 9, /* unmanaged */
-    Event_Client_Focus    = 1 << 10,
-    Event_Client_Unfocus  = 1 << 11,
+    Event_Client_New      = 1 << 8, /* new window, before mapping */
+    Event_Client_Mapped   = 1 << 9, /* new window, after mapping */
+    Event_Client_Destroy  = 1 << 10, /* unmanaged */
+    Event_Client_Focus    = 1 << 11, /* focused */
+    Event_Client_Unfocus  = 1 << 12, /* unfocused */
+    Event_Client_Urgent   = 1 << 13, /* entered/left urgent state */
+    Event_Client_Visible  = 1 << 14, /* shown/hidden (not on a workspace or
+                                        show-the-desktop change though) */
 
-    Event_Ob_Desktop      = 1 << 12, /* changed desktops */
-    Event_Ob_NumDesktops  = 1 << 13, /* changed the number of desktops */
-    Event_Ob_ShowDesktop  = 1 << 14, /* entered/left show-the-desktop mode */
-    Event_Ob_Startup      = 1 << 15, /* startup complete */
-    Event_Ob_Shutdown     = 1 << 16, /* shutdown about to start */
+    Event_Ob_Desktop      = 1 << 15, /* changed desktops */
+    Event_Ob_NumDesktops  = 1 << 16, /* changed the number of desktops */
+    Event_Ob_ShowDesktop  = 1 << 17, /* entered/left show-the-desktop mode */
+    Event_Ob_Startup      = 1 << 18, /* startup complete */
+    Event_Ob_Shutdown     = 1 << 19, /* shutdown about to start */
 
-    Event_Signal          = 1 << 17,
+    Event_Signal          = 1 << 20,
 
-    EVENT_RANGE           = 1 << 18
+    EVENT_RANGE           = 1 << 21
 } EventType;
 
+typedef struct {
+    XEvent *e;
+    Client *client;
+} EventData_X;
+
 typedef union {
-    XEvent *x; /* for Event_X_* event types */
+    EventData_X x; /* for Event_X_* event types */
     Client *client; /* for Event_Client_* event types */
     int signal;
 } EventData;
@@ -50,7 +59,7 @@ typedef unsigned int EventMask;
 
 void dispatch_register(EventHandler h, EventMask mask);
 
-void dispatch_x(XEvent *e);
+void dispatch_x(XEvent *e, Client *c);
 void dispatch_client(EventType e, Client *c);
 void dispatch_ob(EventType e);
 void dispatch_signal(int signal);
index 341db70641ec27dcdf0e04fb4bb2e5a1a6ec1e3b..cb2ed093bce4f7584770d85ce06b9207647200b1 100644 (file)
@@ -10,6 +10,7 @@
 #include "extensions.h"
 #include "timer.h"
 #include "engine.h"
+#include "dispatch.h"
 
 #include <X11/Xlib.h>
 #include <X11/keysym.h>
@@ -252,6 +253,7 @@ void event_process(XEvent *e)
 
     client = g_hash_table_lookup(client_map, (gpointer)window);
 
+    /* deal with it in the kernel */
     if (client) {
        event_handle_client(client, e);
     } else if (window == ob_root)
@@ -279,45 +281,8 @@ void event_process(XEvent *e)
        xerror_set_ignore(FALSE);
     }
 
-    /* dispatch Crossing, Pointer and Key events to the hooks */
-    switch(e->type) {
-    case EnterNotify:
-        if (client != NULL) engine_mouse_enter(client->frame, window);
-       /*HOOKFIRECLIENT(pointerenter, client);XXX*/
-       break;
-    case LeaveNotify:
-        if (client != NULL) engine_mouse_leave(client->frame, window);
-       /*HOOKFIRECLIENT(pointerleave, client);XXX*/
-       break;
-    case ButtonPress:
-        if (client != NULL) 
-            engine_mouse_press(client->frame, window,
-                               e->xbutton.x, e->xbutton.y);
-       /*pointer_event(e, client);XXX*/
-        break;
-    case ButtonRelease:
-        if (client != NULL)
-            engine_mouse_release(client->frame, window,
-                                 e->xbutton.x, e->xbutton.y);
-       /*pointer_event(e, client);XXX*/
-        break;
-    case MotionNotify:
-       /*pointer_event(e, client);XXX*/
-       break;
-    case KeyPress:     
-    case KeyRelease:
-       /*keyboard_event(&e->xkey);XXX*/
-       break;
-    default:
-       /* XKB events */
-       if (e->type == extensions_xkb_event_basep) {
-           switch (((XkbAnyEvent*)&e)->xkb_type) {
-           case XkbBellNotify:
-               /*HOOKFIRECLIENT(bell, client);XXX*/
-               break;
-           }
-       }
-    }
+    /* dispatch the event to registered handlers */
+    dispatch_x(e, client);
 }
 
 static void event_handle_root(XEvent *e)
index 4ef4b90ca2bd47af18f8b259b5efd53fe7d853ba..db78183d8046b62d7b22eb43bc186255883e7e18 100644 (file)
@@ -2,6 +2,7 @@
 #include "client.h"
 #include "screen.h"
 #include "prop.h"
+#include "dispatch.h"
 
 #include <X11/Xlib.h>
 
@@ -46,11 +47,15 @@ void focus_set_client(Client *client)
        XSetInputFocus(ob_display, focus_backup, RevertToNone, CurrentTime);
     }
 
+    if (focus_client != NULL)
+        dispatch_client(Event_Client_Unfocus, focus_client);
+
     focus_client = client;
 
     /* set the NET_ACTIVE_WINDOW hint */
     active = client ? client->window : None;
     PROP_SET32(ob_root, net_active_window, window, active);
 
-    /*HOOKFIRECLIENT(focused, client);XXX*/
+    if (focus_client != NULL)
+        dispatch_client(Event_Client_Focus, focus_client);
 }
index c0ffa4203fa9a707e0f6dc410a356a045e415c63..e6ee886081d50c89f7e6ebf5ed533cd25f1ecde5 100644 (file)
@@ -47,7 +47,7 @@ gboolean ob_remote   = FALSE;
 gboolean ob_sync     = TRUE;
 Cursors  ob_cursors;
 
-void signal_handler(int signal);
+void signal_handler(const ObEvent *e);
 
 int main(int argc, char **argv)
 {
@@ -63,9 +63,13 @@ int main(int argc, char **argv)
     bind_textdomain_codeset(PACKAGE, "UTF-8");
     textdomain(PACKAGE);
 
+    /* start our event dispatcher and register for signals */
+    dispatch_startup();
+    dispatch_register(signal_handler, Event_Signal);
+
     /* set up signal handler */
     sigemptyset(&sigset);
-    action.sa_handler = signal_handler;
+    action.sa_handler = dispatch_signal;
     action.sa_mask = sigset;
     action.sa_flags = SA_NOCLDSTOP | SA_NODEFER;
     sigaction(SIGUSR1, &action, (struct sigaction *) NULL);
@@ -124,7 +128,6 @@ int main(int argc, char **argv)
      
     if (screen_annex()) { /* it will be ours! */
        timer_startup();
-        dispatch_startup();
        render_startup();
        font_startup();
        themerc_startup();
@@ -133,8 +136,8 @@ int main(int argc, char **argv)
        screen_startup();
        focus_startup();
        client_startup();
-         
-       /*HOOKFIRE(startup, "()");XXX*/
+
+        dispatch_ob(Event_Ob_Startup);
 
        /* get all the existing windows */
        client_manage_all();
@@ -147,7 +150,7 @@ int main(int argc, char **argv)
 
        client_unmanage_all();
 
-       /*HOOKFIRE(shutdown, "()");XXX*/
+        dispatch_ob(Event_Ob_Shutdown);
 
        client_shutdown();
        screen_shutdown();
@@ -155,20 +158,21 @@ int main(int argc, char **argv)
        engine_shutdown();
        themerc_shutdown();
        render_shutdown();
-        dispatch_shutdown();
        timer_shutdown();
     }
          
     XCloseDisplay(ob_display);
 
+    dispatch_shutdown();
+
     /* XXX if (ob_restart) */
      
     return 0;
 }
 
-void signal_handler(int signal)
+void signal_handler(const ObEvent *e)
 {
-    switch (signal) {
+    switch (e->data.signal) {
     case SIGUSR1:
        g_message("Caught SIGUSR1 signal. Restarting.");
        ob_shutdown = ob_restart = TRUE;
@@ -182,12 +186,12 @@ void signal_handler(int signal)
     case SIGINT:
     case SIGTERM:
     case SIGPIPE:
-       g_message("Caught signal %d. Exiting.", signal);
+       g_message("Caught signal %d. Exiting.", e->data.signal);
        ob_shutdown = TRUE;
        break;
 
     case SIGFPE:
     case SIGSEGV:
-       g_error("Caught signal %d. Aborting and dumping core.", signal);
+       g_error("Caught signal %d. Aborting and dumping core.",e->data.signal);
     }
 }
index 3c83baa4d0f1a0a2218efca6cc727aac855467a2..f82275c0a66738e43c7eacafa39cb44d0756d8ab 100644 (file)
@@ -5,6 +5,8 @@
 #include "frame.h"
 #include "engine.h"
 #include "focus.h"
+#include "dispatch.h"
+#include "../render/render.h"
 
 #include <X11/Xlib.h>
 #ifdef HAVE_UNISTD_H
@@ -233,6 +235,8 @@ void screen_set_num_desktops(guint num)
     /* may be some unnamed desktops that we need to fill in with names */
     screen_update_desktop_names();
 
+    dispatch_ob(Event_Ob_NumDesktops);
+
     /* change our desktop if we're on one that no longer exists! */
     if (screen_desktop >= screen_num_desktops)
        screen_set_desktop(num - 1);
@@ -267,9 +271,7 @@ void screen_set_desktop(guint num)
             engine_frame_show(c->frame);
     }
 
-    /* force the callbacks to fire */
-    if (focus_client == NULL)
-       focus_set_client(NULL);
+    dispatch_ob(Event_Ob_Desktop);
 }
 
 void screen_update_layout()
@@ -392,18 +394,17 @@ void screen_show_desktop(gboolean show)
 
     show = show ? 1 : 0; /* make it boolean */
     PROP_SET32(ob_root, net_showing_desktop, cardinal, show);
+
+    dispatch_ob(Event_Ob_ShowDesktop);
 }
 
 void screen_install_colormap(Client *client, gboolean install)
 {
     if (client == NULL) {
-       /* XXX DONT USE THE DEFAULT SHIT HERE */
        if (install)
-           XInstallColormap(ob_display,
-                            DefaultColormap(ob_display, ob_screen));
+           XInstallColormap(ob_display, render_colormap);
        else
-           XUninstallColormap(ob_display,
-                              DefaultColormap(ob_display, ob_screen));
+           XUninstallColormap(ob_display, render_colormap);
     } else {
        XWindowAttributes wa;
        if (XGetWindowAttributes(ob_display, client->window, &wa)) {
This page took 0.041432 seconds and 4 git commands to generate.