]> Dogcows Code - chaz/openbox/blob - openbox/hooks.c
7d7f70072972bac13809c133f7188cb306f8c692
[chaz/openbox] / openbox / hooks.c
1 #include "hooks.h"
2 #include "actions.h"
3 #include "client.h"
4 #include "focus.h"
5 #include "debug.h"
6
7 #include <glib.h>
8
9 static GSList *hooks[OB_NUM_HOOKS];
10 static const gchar *names[OB_NUM_HOOKS];
11
12 void hooks_startup(gboolean reconfig)
13 {
14 gint i;
15
16 for (i = 0; i < OB_NUM_HOOKS; ++i)
17 hooks[i] = NULL;
18
19 names[OB_HOOK_WIN_NEW] = "WindowNew";
20 names[OB_HOOK_WIN_CLOSE] = "WindowClosed";
21 names[OB_HOOK_WIN_VISIBLE] = "WindowVisible";
22 names[OB_HOOK_WIN_INVISIBLE] = "WindowInvisible";
23 names[OB_HOOK_WIN_ICONIC] = "WindowIconified";
24 names[OB_HOOK_WIN_UNICONIC] = "WindowUniconified";
25 names[OB_HOOK_WIN_MAX] = "WindowMaximized";
26 names[OB_HOOK_WIN_UNMAX] = "WindowUnmaximized";
27 names[OB_HOOK_WIN_SHADE] = "WindowShaded";
28 names[OB_HOOK_WIN_UNSHADE] = "WindowUnshaded";
29 names[OB_HOOK_WIN_FOCUS] = "WindowFocused";
30 names[OB_HOOK_WIN_UNFOCUS] = "WindowUnfocused";
31 names[OB_HOOK_WIN_DESK_CHANGE] = "WindowOnNewDesktop";
32 names[OB_HOOK_WIN_DECORATED] = "WindowDecorated";
33 names[OB_HOOK_WIN_UNDECORATED] = "WindowUndecorated";
34 names[OB_HOOK_SCREEN_DESK_CHANGE] = "DesktopChanged";
35 }
36
37 void hooks_shutdown(gboolean reconfig)
38 {
39 gint i;
40
41 for (i = 0; i < OB_NUM_HOOKS; ++i)
42 while (hooks[i]) {
43 actions_act_unref(hooks[i]->data);
44 hooks[i] = g_slist_delete_link(hooks[i], hooks[i]);
45 }
46 }
47
48 ObHook hooks_hook_from_name(const gchar *n)
49 {
50 gint i;
51
52 for (i = 1; i < OB_NUM_HOOKS; ++i)
53 if (!g_ascii_strcasecmp(n, names[i]))
54 return (ObHook)i;
55 return OB_HOOK_INVALID;
56 }
57
58 void hooks_run(ObHook hook, struct _ObClient *client)
59 {
60 GSList *it;
61
62 g_assert(hook < OB_NUM_HOOKS && hook > OB_HOOK_INVALID);
63
64 ob_debug("Running hook %s for client 0x%x", names[hook],
65 (client ? client->window : 0));
66 actions_run_acts(hooks[hook],
67 OB_USER_ACTION_HOOK,
68 0, -1, -1, 0,
69 OB_FRAME_CONTEXT_NONE,
70 client);
71 }
72
73 void hooks_add(ObHook hook, struct _ObActionsAct *act)
74 {
75 g_assert(hook < OB_NUM_HOOKS && hook > OB_HOOK_INVALID);
76
77 /* append so they are executed in the same order as they appear in the
78 config file */
79 hooks[hook] = g_slist_append(hooks[hook], act);
80 }
This page took 0.041885 seconds and 3 git commands to generate.