]> Dogcows Code - chaz/openbox/commitdiff
Get hooks working
authorDana Jansens <danakj@orodu.net>
Sat, 1 Mar 2008 05:04:28 +0000 (00:04 -0500)
committerDana Jansens <danakj@orodu.net>
Sat, 1 Mar 2008 05:04:28 +0000 (00:04 -0500)
openbox/event.c
openbox/event.h
openbox/hooks.c
openbox/openbox.c

index 4d1b6abaa90009d88c7925004c9b5f295c3cbb06..142cf1f2fd1b44f45966f3a595f55f500480d2eb 100644 (file)
@@ -1884,11 +1884,16 @@ static void event_handle_user_input(ObClient *client, XEvent *e)
             if (!client || !frame_iconify_animating(client->frame))
                 mouse_event(client, e);
         } else
-            keyboard_event((focus_cycle_target ? focus_cycle_target :
-                            (client ? client : focus_client)), e);
+            keyboard_event(event_target_client(client), e);
     }
 }
 
+ObClient* event_target_client(ObClient *client)
+{
+    return (focus_cycle_target ? focus_cycle_target :
+            (client ? client : focus_client));
+}
+
 static void focus_delay_dest(gpointer data)
 {
     g_free(data);
index 4e6fc325726f7a97a2ece5abcafeb89baca77727..ba5a03ea15cfdee8f52fa6f66b4b3113dfd17177 100644 (file)
@@ -64,4 +64,8 @@ gboolean event_time_after(Time t1, Time t2);
 
 Time event_get_server_time(void);
 
+/*! Given a possible target client, returns what the target client really
+  should be for actions */
+struct _ObClient* event_target_client(struct _ObClient *client);
+
 #endif
index 2a346c393bae85c2108b84720eb4550689bd650d..ea46192528155f8120af1815e6c5655df99df92c 100644 (file)
@@ -1,9 +1,13 @@
 #include "hooks.h"
 #include "actions.h"
+#include "client.h"
+#include "focus.h"
+#include "debug.h"
 
 #include <glib.h>
 
 static GSList *hooks[OB_NUM_HOOKS];
+static const gchar *names[OB_NUM_HOOKS];
 
 void hooks_startup(gboolean reconfig)
 {
@@ -11,6 +15,23 @@ void hooks_startup(gboolean reconfig)
 
     for (i = 0; i < OB_NUM_HOOKS; ++i)
         hooks[i] = NULL;
+
+    names[OB_HOOK_WIN_NEW] = "WindowNew";
+    names[OB_HOOK_WIN_CLOSE] = "WindowClosed";
+    names[OB_HOOK_WIN_VISIBLE] = "WindowVisible";
+    names[OB_HOOK_WIN_INVISIBLE] = "WindowInvisible";
+    names[OB_HOOK_WIN_ICONIC] = "WindowIconified";
+    names[OB_HOOK_WIN_UNICONIC] = "WindowUniconified";
+    names[OB_HOOK_WIN_MAX] = "WindowMaximized";
+    names[OB_HOOK_WIN_UNMAX] = "WindowUnmaximized";
+    names[OB_HOOK_WIN_SHADE] = "WindowShaded";
+    names[OB_HOOK_WIN_UNSHADE] = "WindowUnshaded";
+    names[OB_HOOK_WIN_FOCUS] = "WindowFocused";
+    names[OB_HOOK_WIN_UNFOCUS] = "WindowUnfocused";
+    names[OB_HOOK_WIN_DESK_CHANGE] = "WindowOnNewDesktop";
+    names[OB_HOOK_WIN_DECORATED] = "WindowDecorated";
+    names[OB_HOOK_WIN_UNDECORATED] = "WindowUndecorated";
+    names[OB_HOOK_SCREEN_DESK_CHANGE] = "DesktopChanged";
 }
 
 void hooks_shutdown(gboolean reconfig)
@@ -26,57 +47,32 @@ void hooks_shutdown(gboolean reconfig)
 
 ObHook hooks_hook_from_name(const gchar *n)
 {
-    if (!g_ascii_strcasecmp(n, "WindowNew"))
-        return OB_HOOK_WIN_NEW;
-    if (!g_ascii_strcasecmp(n, "WindowClosed"))
-        return OB_HOOK_WIN_CLOSE;
-    if (!g_ascii_strcasecmp(n, "WindowVisible"))
-        return OB_HOOK_WIN_VISIBLE;
-    if (!g_ascii_strcasecmp(n, "WindowInvisible"))
-        return OB_HOOK_WIN_INVISIBLE;
-    if (!g_ascii_strcasecmp(n, "WindowIconified"))
-        return OB_HOOK_WIN_ICONIC;
-    if (!g_ascii_strcasecmp(n, "WindowUniconified"))
-        return OB_HOOK_WIN_UNICONIC;
-    if (!g_ascii_strcasecmp(n, "WindowMaximized"))
-        return OB_HOOK_WIN_MAX;
-    if (!g_ascii_strcasecmp(n, "WindowUnmaximized"))
-        return OB_HOOK_WIN_UNMAX;
-    if (!g_ascii_strcasecmp(n, "WindowShaded"))
-        return OB_HOOK_WIN_SHADE;
-    if (!g_ascii_strcasecmp(n, "WindowUnshaded"))
-        return OB_HOOK_WIN_UNSHADE;
-    if (!g_ascii_strcasecmp(n, "WindowFocused"))
-        return OB_HOOK_WIN_FOCUS;
-    if (!g_ascii_strcasecmp(n, "WindowUnfocused"))
-        return OB_HOOK_WIN_UNFOCUS;
-    if (!g_ascii_strcasecmp(n, "WindowOnNewDesktop"))
-        return OB_HOOK_WIN_DESK_CHANGE;
-    if (!g_ascii_strcasecmp(n, "WindowDecorated"))
-        return OB_HOOK_WIN_DECORATED;
-    if (!g_ascii_strcasecmp(n, "WindowUndecorated"))
-        return OB_HOOK_WIN_UNDECORATED;
-    if (!g_ascii_strcasecmp(n, "DesktopChanged"))
-        return OB_HOOK_SCREEN_DESK_CHANGE;
+    gint i;
+
+    for (i = 1; i < OB_NUM_HOOKS; ++i)
+        if (!g_ascii_strcasecmp(n, names[i]))
+            return (ObHook)i;
     return OB_HOOK_INVALID;
 }
 
-void hooks_run(ObHook hook, struct _ObClient *c)
+void hooks_run(ObHook hook, struct _ObClient *client)
 {
     GSList *it;
 
-    g_assert(hook < OB_NUM_HOOKS);
+    g_assert(hook < OB_NUM_HOOKS && hook > OB_HOOK_INVALID);
 
+    ob_debug("Running hook %s for client 0x%x", names[hook],
+             (client ? client->window : 0));
     actions_run_acts(hooks[hook],
                      OB_USER_ACTION_HOOK,
                      0, -1, -1, 0,
                      OB_FRAME_CONTEXT_NONE,
-                     c);
+                     event_target_client(client));
 }
 
 void hooks_add(ObHook hook, struct _ObActionsAct *act)
 {
-    g_assert(hook < OB_NUM_HOOKS);
+    g_assert(hook < OB_NUM_HOOKS && hook > OB_HOOK_INVALID);
 
     /* append so they are executed in the same order as they appear in the
        config file */
index 79b080d2022fbeace69ec85140875fedaf4910bb..01aa58a2de0819b520679797acd91f3864d78d6c 100644 (file)
@@ -233,6 +233,7 @@ gint main(gint argc, gchar **argv)
 
                 /* register all the available actions */
                 actions_startup(reconfigure);
+                hooks_startup(reconfigure);
                 /* start up config which sets up with the parser */
                 config_startup(i);
 
@@ -298,7 +299,6 @@ gint main(gint argc, gchar **argv)
             /* focus_backup is used for stacking, so this needs to come before
                anything that calls stacking_add */
             sn_startup(reconfigure);
-            hooks_startup(reconfigure);
             window_startup(reconfigure);
             focus_startup(reconfigure);
             focus_cycle_startup(reconfigure);
@@ -375,10 +375,10 @@ gint main(gint argc, gchar **argv)
             focus_cycle_shutdown(reconfigure);
             focus_shutdown(reconfigure);
             window_shutdown(reconfigure);
-            hooks_shutdown(reconfigure);
             sn_shutdown(reconfigure);
             event_shutdown(reconfigure);
             config_shutdown();
+            hooks_shutdown(reconfigure);
             actions_shutdown(reconfigure);
         } while (reconfigure);
     }
This page took 0.027641 seconds and 4 git commands to generate.