summaryrefslogtreecommitdiff
path: root/openbox/hooks.c
diff options
context:
space:
mode:
authorDana Jansens <danakj@orodu.net>2008-03-01 01:52:38 -0500
committerDana Jansens <danakj@orodu.net>2008-03-01 01:52:38 -0500
commita47d0a53652a96ca1df96fc9268757df1431ae55 (patch)
tree5815a3fab5d8332a5a62b148ab9486ba28e66c15 /openbox/hooks.c
parent93a38d46bfec781ff9783c0d5ff065f7b2f2b875 (diff)
queue hooks so that they don't run as each thing happens, instead run them at the end. keep the openbox code paths fast.
Diffstat (limited to 'openbox/hooks.c')
-rw-r--r--openbox/hooks.c54
1 files changed, 46 insertions, 8 deletions
diff --git a/openbox/hooks.c b/openbox/hooks.c
index 7d7f7007..ad57fdb8 100644
--- a/openbox/hooks.c
+++ b/openbox/hooks.c
@@ -3,12 +3,22 @@
#include "client.h"
#include "focus.h"
#include "debug.h"
+#include "obt/display.h"
#include <glib.h>
static GSList *hooks[OB_NUM_HOOKS];
static const gchar *names[OB_NUM_HOOKS];
+typedef struct {
+ ObHook hook;
+ struct _ObClient *client;
+} ObHookQueue;
+
+#define QUEUE_SIZE 20
+ObHookQueue run_queue[QUEUE_SIZE];
+gint queue_size;
+
void hooks_startup(gboolean reconfig)
{
gint i;
@@ -16,6 +26,8 @@ void hooks_startup(gboolean reconfig)
for (i = 0; i < OB_NUM_HOOKS; ++i)
hooks[i] = NULL;
+ queue_size = 0;
+
names[OB_HOOK_WIN_NEW] = "WindowNew";
names[OB_HOOK_WIN_CLOSE] = "WindowClosed";
names[OB_HOOK_WIN_VISIBLE] = "WindowVisible";
@@ -55,19 +67,27 @@ ObHook hooks_hook_from_name(const gchar *n)
return OB_HOOK_INVALID;
}
-void hooks_run(ObHook hook, struct _ObClient *client)
+void hooks_queue(ObHook hook, struct _ObClient *client)
{
- GSList *it;
+ ObHookQueue *q;
g_assert(hook < OB_NUM_HOOKS && hook > OB_HOOK_INVALID);
- ob_debug("Running hook %s for client 0x%x", names[hook],
+ ob_debug("Queing 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,
- client);
+ q = &run_queue[queue_size++];
+ q->hook = hook;
+ q->client = client;
+
+ if (queue_size == QUEUE_SIZE)
+ /* queue is full */
+ hooks_run_queue();
+}
+
+void hooks_run(ObHook hook, struct _ObClient *c)
+{
+ hooks_queue(hook, c);
+ hooks_run_queue();
}
void hooks_add(ObHook hook, struct _ObActionsAct *act)
@@ -78,3 +98,21 @@ void hooks_add(ObHook hook, struct _ObActionsAct *act)
config file */
hooks[hook] = g_slist_append(hooks[hook], act);
}
+
+void hooks_run_queue(void)
+{
+ gint i;
+
+ for (i = 0; i < queue_size; ++i) {
+ const ObHookQueue *q = &run_queue[i];
+
+ ob_debug("Running hook %s for client 0x%x", names[q->hook],
+ (q->client ? q->client->window : 0));
+ actions_run_acts(hooks[q->hook],
+ OB_USER_ACTION_HOOK,
+ 0, -1, -1, 0,
+ OB_FRAME_CONTEXT_NONE,
+ q->client);
+ }
+ queue_size = 0;
+}