summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/ChangeLog10
-rw-r--r--src/actions.c149
-rw-r--r--src/actions.h5
-rw-r--r--src/data.h2
-rw-r--r--src/events.c47
-rw-r--r--src/main.c2
6 files changed, 119 insertions, 96 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index ef89b67..1974bcb 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,5 +1,15 @@
2001-02-19 Ryan Yeske <rcyeske@cut.hotdog.tmp>
+ * events.c (handle_key): Call find_keybinding() instead of looping
+ through keytable here.
+
+ * main.c (main): Call initialize_default_keybindings.
+
+ * actions.c (find_keybinding): Added.
+ (add_keybinding): Added.
+ (initialize_default_keybindings): Added. Do not use static table
+ of keybindings. Instead call add_keybinding() for each key.
+
* Makefile.am (ratpoison_SOURCES): add themes.h
* main.c (FONT_NAME): Rename to FONT
diff --git a/src/actions.c b/src/actions.c
index 346e140..c670f9f 100644
--- a/src/actions.c
+++ b/src/actions.c
@@ -33,76 +33,93 @@
#define S Mod3Mask /* Super */
#define H Mod4Mask /* Hyper */
-/* rp_key_prefix key_prefix[] = */
-/* { {XK_t, C, "main-prefix"}, */
-/* {0,0,NULL} }; */
+rp_action *key_actions;
+int key_actions_last;
+int key_actions_table_size;
-rp_action key_actions[] =
- { {XK_t, C, "other", command},
- {XK_t, 0, "generate", command},
-
-/* {XK_Escape, M, "generate", command}, */
-
- {XK_g, C, "abort", command},
-
- {XK_0, 0, "select 0", command},
- {XK_1, 0, "select 1", command},
- {XK_2, 0, "select 2", command},
- {XK_3, 0, "select 3", command},
- {XK_4, 0, "select 4", command},
- {XK_5, 0, "select 5", command},
- {XK_6, 0, "select 6", command},
- {XK_7, 0, "select 7", command},
- {XK_8, 0, "select 8", command},
- {XK_9, 0, "select 9", command},
-
- {XK_A, 0, "title", command},
- {XK_A, C, "title", command},
-
- {XK_K, 0, "kill", command},
- {XK_K, C, "kill", command},
-
- {XK_Return, 0, "next", command},
- {XK_Return, C, "next", command},
-
- {XK_a, 0, "clock", command},
- {XK_a, C, "clock", command},
-
- {XK_c, 0, "exec " TERM_PROG, command},
- {XK_c, C, "exec " TERM_PROG, command},
-
- {XK_colon, 0, "colon", command},
-
- {XK_e, 0, "exec " EMACS_PROG, command},
- {XK_e, C, "exec " EMACS_PROG, command},
-
- {XK_exclam, 0, "exec", command},
- {XK_exclam, C, "colon exec " TERM_PROG " -e ", command},
-
- {XK_k, 0, "delete", command},
- {XK_k, C, "delete", command},
-
- {XK_m, 0, "maximize", command},
- {XK_m, C, "maximize", command},
-
- {XK_n, 0, "next", command},
- {XK_n, C, "next", command},
-
- {XK_p, 0, "prev", command},
- {XK_p, C, "prev", command},
+char *
+find_keybinding (int keysym, int state)
+{
+ int i;
+ for (i = 0; i < key_actions_last; i++)
+ {
+ if (key_actions[i].key == keysym
+ && key_actions[i].state == state)
+ return strdup(key_actions[i].data);
+ }
+ return NULL;
+}
- {XK_quoteright, 0, "select", command},
- {XK_quoteright, C, "select", command},
+static void
+add_keybinding (int keysym, int state, char *cmd)
+{
+ if (key_actions_last >= key_actions_table_size)
+ {
+ /* double the key table size */
+ key_actions_table_size *= 2;
+ key_actions = (rp_action*) realloc (key_actions, sizeof (rp_action) * key_actions_table_size);
+ fprintf (stderr, "realloc()ed key_table %d\n", key_actions_table_size);
+ }
- {XK_space, 0, "next", command},
- {XK_space, C, "next", command},
+ key_actions[key_actions_last].key = keysym;
+ key_actions[key_actions_last].state = state;
+ key_actions[key_actions_last].data = cmd;
- {XK_v, 0, "version", command},
- {XK_v, C, "version", command},
+ ++key_actions_last;
+}
- {XK_w, 0, "windows", command},
- {XK_w, C, "windows", command},
- {0, 0, 0, 0 } };
+void
+initialize_default_keybindings (void)
+{
+ key_actions_table_size = 1;
+ key_actions = (rp_action*) malloc (sizeof (rp_action) * key_actions_table_size);
+ key_actions_last = 0;
+
+ add_keybinding (XK_t, C, "other");
+ add_keybinding (XK_t, 0, "generate");
+ add_keybinding (XK_g, C, "abort");
+ add_keybinding (XK_0, 0, "select 0");
+ add_keybinding (XK_1, 0, "select 1");
+ add_keybinding (XK_2, 0, "select 2");
+ add_keybinding (XK_3, 0, "select 3");
+ add_keybinding (XK_4, 0, "select 4");
+ add_keybinding (XK_5, 0, "select 5");
+ add_keybinding (XK_6, 0, "select 6");
+ add_keybinding (XK_7, 0, "select 7");
+ add_keybinding (XK_8, 0, "select 8");
+ add_keybinding (XK_9, 0, "select 9");
+ add_keybinding (XK_A, 0, "title");
+ add_keybinding (XK_A, C, "title");
+ add_keybinding (XK_K, 0, "kill");
+ add_keybinding (XK_K, C, "kill");
+ add_keybinding (XK_Return, 0, "next");
+ add_keybinding (XK_Return, C, "next");
+ add_keybinding (XK_a, 0, "clock");
+ add_keybinding (XK_a, C, "clock");
+ add_keybinding (XK_c, 0, "exec " TERM_PROG);
+ add_keybinding (XK_c, C, "exec " TERM_PROG);
+ add_keybinding (XK_colon, 0, "colon");
+ add_keybinding (XK_e, 0, "exec " EMACS_PROG);
+ add_keybinding (XK_e, C, "exec " EMACS_PROG);
+ add_keybinding (XK_exclam, 0, "exec");
+ add_keybinding (XK_exclam, C, "colon exec " TERM_PROG " -e ");
+ add_keybinding (XK_k, 0, "delete");
+ add_keybinding (XK_k, C, "delete");
+ add_keybinding (XK_m, 0, "maximize");
+ add_keybinding (XK_m, C, "maximize");
+ add_keybinding (XK_n, 0, "next");
+ add_keybinding (XK_n, C, "next");
+ add_keybinding (XK_p, 0, "prev");
+ add_keybinding (XK_p, C, "prev");
+ add_keybinding (XK_quoteright, 0, "select");
+ add_keybinding (XK_quoteright, C, "select");
+ add_keybinding (XK_space, 0, "next");
+ add_keybinding (XK_space, C, "next");
+ add_keybinding (XK_v, 0, "version");
+ add_keybinding (XK_v, C, "version");
+ add_keybinding (XK_w, 0, "windows");
+ add_keybinding (XK_w, C, "windows");
+}
user_command user_commands[] =
{ {"abort", cmd_abort, arg_VOID},
@@ -372,7 +389,7 @@ cmd_version (void *data)
}
void
-command (void *data)
+command (char *data)
{
char *cmd, *rest;
char *input;
diff --git a/src/actions.h b/src/actions.h
index 93287c6..bc1f410 100644
--- a/src/actions.h
+++ b/src/actions.h
@@ -39,7 +39,7 @@ user_command
void bye(void *dummy);
void spawn(void *data);
-void command (void *data);
+void command (char *data);
void maximize (void *data);
void cmd_newwm(void *which);
@@ -62,6 +62,7 @@ void cmd_unimplemented (void *data);
/* void cmd_xterm (void *data); */
-extern rp_action key_actions[];
+void initialize_default_keybindings (void);
+char *find_keybinding (int keysym, int state);
#endif /* ! _RATPOISON_ACTIONS_H */
diff --git a/src/data.h b/src/data.h
index 5e8a6fc..9ba8419 100644
--- a/src/data.h
+++ b/src/data.h
@@ -81,7 +81,7 @@ struct rp_action
int key;
int state;
void *data; /* misc data to be passed to the function */
- void (*func)(void *);
+/* void (*func)(void *); */
};
extern rp_window *rp_window_head, *rp_window_tail;
diff --git a/src/events.c b/src/events.c
index 6300086..5cbc08a 100644
--- a/src/events.c
+++ b/src/events.c
@@ -287,7 +287,7 @@ handle_key (screen_info *s)
{
char *keysym_name;
char *msg;
- const rp_action *i;
+ char *cmd;
int revert;
Window fwin; /* Window currently in focus */
KeySym keysym; /* Key pressed */
@@ -304,38 +304,31 @@ handle_key (screen_info *s)
read_key (&keysym, &mod);
- for (i = key_actions; i->key != 0; i++)
+ if ((cmd = find_keybinding (keysym, mod)))
{
- if (keysym == i->key)
- {
- if (mod == i->state)
- {
- /* Revert focus back to the current window before
- executing the command. */
- XSetInputFocus (dpy, fwin, revert, CurrentTime);
- (*i->func)(i->data);
- return;
- }
- }
+ XSetInputFocus (dpy, fwin, revert, CurrentTime);
+ command (cmd);
}
-
- keysym_name = keysym_to_string (keysym, mod);
- msg = (char *) malloc ( strlen ( keysym_name ) + 20 );
- if ( msg == NULL )
+ else
{
- PRINT_ERROR ("Out of memory\n");
- exit (EXIT_FAILURE);
- }
- snprintf (msg, strlen (keysym_name) + 13, "%s unbound key!", keysym_name);
- free (keysym_name);
+ keysym_name = keysym_to_string (keysym, mod);
+ msg = (char *) malloc ( strlen ( keysym_name ) + 20 );
+ if ( msg == NULL )
+ {
+ PRINT_ERROR ("Out of memory\n");
+ exit (EXIT_FAILURE);
+ }
+ snprintf (msg, strlen (keysym_name) + 13, "%s unbound key!", keysym_name);
+ free (keysym_name);
- PRINT_DEBUG ("%s\n", msg);
+ PRINT_DEBUG ("%s\n", msg);
- /* No key match, notify user. */
- XSetInputFocus (dpy, fwin, revert, CurrentTime);
- message (msg);
+ /* No key match, notify user. */
+ XSetInputFocus (dpy, fwin, revert, CurrentTime);
+ message (msg);
- free (msg);
+ free (msg);
+ }
}
void
diff --git a/src/main.c b/src/main.c
index 6edf808..16a7613 100644
--- a/src/main.c
+++ b/src/main.c
@@ -279,6 +279,8 @@ main (int argc, char *argv[])
init_screen (&screens[i], i);
}
+ initialize_default_keybindings ();
+
/* Set an initial window as active. */
set_active_window (rp_window_head);