summaryrefslogtreecommitdiff
path: root/src/hook.c
diff options
context:
space:
mode:
authorsabetts <sabetts>2003-07-17 05:41:41 +0000
committersabetts <sabetts>2003-07-17 05:41:41 +0000
commitb7d55a9ae282d35b3a42267749f8f443620728d7 (patch)
treeb919f3c6dee8331981ab696fe7923c507bafd888 /src/hook.c
parent19a5e7a0eb033abbd4d61b72a2023a8d012c9a5e (diff)
downloadratpoison-b7d55a9ae282d35b3a42267749f8f443620728d7.zip
* src/window.c (set_active_window): run the switch window hook.
* src/split.c (set_active_frame): run the switch frame hook. * src/ratpoison.h: include hook.h * src/group.h (set_current_group): new prototype * src/group.c (set_current_group): new function * src/globals.h (rp_prefix_hook): new extern (rp_switch_win_hook): likewise (rp_switch_frame_hook): likewise (rp_switch_group_hook): likewise (rp_hook_db): likewise * src/globals.c (rp_prefix_hook): new hook (rp_switch_win_hook): likewise (rp_switch_frame_hook): likewise (rp_switch_group_hook): likewise (rp_hook_db): new global * src/events.c (handle_key): call the prefix hook. * src/data.h (struct rp_hook_db_entry): new struct * src/actions.h (cmd_addhook): new prototype (cmd_remhook): likewise * src/actions.c (user_commands): add commands addhook and remhook. (cmd_windows): show the window bar no matter what if the bar timeout is > 0. (cmd_gnext): call set_current_group (cmd_gprev): likewise (cmd_gnew): likewise (cmd_gselect): likewise (cmd_addhook): new function (cmd_remhook): likewise * src/Makefile.am (ratpoison_SOURCES): add hook.c and hook.h
Diffstat (limited to 'src/hook.c')
-rw-r--r--src/hook.c84
1 files changed, 84 insertions, 0 deletions
diff --git a/src/hook.c b/src/hook.c
new file mode 100644
index 0000000..830099d
--- /dev/null
+++ b/src/hook.c
@@ -0,0 +1,84 @@
+/* Copyright (C) 2000, 2001, 2002, 2003 Shawn Betts
+ *
+ * This file is part of ratpoison.
+ *
+ * ratpoison is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * ratpoison is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this software; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
+ * Boston, MA 02111-1307 USA
+ */
+
+/* A hook is simply a list of strings that get passed to command() in
+ sequence. */
+
+#include "ratpoison.h"
+
+void
+hook_add (struct list_head *hook, struct sbuf *s)
+{
+ struct sbuf *cur;
+
+ /* Check if it's in the list already. */
+ list_for_each_entry (cur, hook, node)
+ {
+ if (!strcmp (sbuf_get (cur), sbuf_get (s)))
+ return;
+ }
+
+ /* It's not in the list, so add it. */
+ list_add_tail (&s->node, hook);
+}
+
+void
+hook_remove (struct list_head *hook, struct sbuf *s)
+{
+ struct list_head *tmp, *iter;
+ struct sbuf *cur;
+
+ /* If it's in the list, delete it. */
+ list_for_each_safe_entry (cur, iter, tmp, hook, node)
+ {
+ if (!strcmp (sbuf_get (cur), sbuf_get (s)))
+ {
+ list_del (&cur->node);
+ sbuf_free (cur);
+ }
+ }
+}
+
+void
+hook_run (struct list_head *hook)
+{
+ struct sbuf *cur;
+
+ list_for_each_entry (cur, hook, node)
+ {
+ command (1, sbuf_get (cur));
+ }
+}
+
+struct list_head *
+hook_lookup (char *s)
+{
+ struct rp_hook_db_entry *entry;
+
+ for (entry = rp_hook_db; entry->name; entry++)
+ {
+ if (!strcmp (s, entry->name))
+ {
+ return entry->hook;
+ }
+ }
+
+ return NULL;
+}