diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/ChangeLog | 24 | ||||
-rw-r--r-- | src/actions.c | 67 | ||||
-rw-r--r-- | src/actions.h | 7 | ||||
-rw-r--r-- | src/conf.h | 3 | ||||
-rw-r--r-- | src/data.h | 13 | ||||
-rw-r--r-- | src/events.c | 2 | ||||
-rw-r--r-- | src/main.c | 5 | ||||
-rw-r--r-- | src/manage.c | 15 | ||||
-rw-r--r-- | src/manage.h | 3 |
9 files changed, 114 insertions, 25 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index 6e7be47..6c26428 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,6 +1,30 @@ 2001-02-27 shawn <sabetts@diggin.lamenet.tmp> + * manage.h (ungrab_prefix_key): new prototype + (grab_prefix_key): likewise + + * manage.c (ungrab_prefix_key): new function + + * main.c (main): calls initialize_default_keybindings after + init_window_list. + + * data.h (struct rp_action): key is of type KeySym. state is + unsigned int. + + * conf.h (KEY_PREFIX): set to XK_t + + * actions.h (cmd_escape): new prototype + + * actions.c (cmd_escape): new function + + * data.h (struct key): move from actions.h + (struct rp_key): rename from struct key. dependant code updated. + (prefix_key): new global variable. code dependant on KEY_PREFIX + and MODIFIER_PREFIX updated to use this. + * actions.c: "maximize" user command calls cmd_maximize + (initialize_default_keybindings): initializes prefix_key. + Added "escape" command. * manage.c (force_maximize): moved from actions.c (maximize): likewise diff --git a/src/actions.c b/src/actions.c index 681504e..15bbe3d 100644 --- a/src/actions.c +++ b/src/actions.c @@ -86,8 +86,11 @@ initialize_default_keybindings (void) 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"); + prefix_key.sym = KEY_PREFIX; + prefix_key.state = MODIFIER_PREFIX; + + add_keybinding (prefix_key.sym, prefix_key.state, "other"); + add_keybinding (prefix_key.sym, 0, "generate"); add_keybinding (XK_g, C, "abort"); add_keybinding (XK_0, 0, "select 0"); add_keybinding (XK_1, 0, "select 1"); @@ -151,6 +154,7 @@ user_command user_commands[] = {"version", cmd_version, arg_VOID}, {"bind", cmd_bind, arg_VOID}, {"source", cmd_source, arg_STRING}, + {"escape", cmd_escape, arg_STRING}, /* the following screen commands may or may not be able to be implemented. See the screen documentation for what should be @@ -181,11 +185,11 @@ user_command user_commands[] = {"startup_message", cmd_unimplemented, arg_VOID}, {0, 0, 0} }; -struct key* +struct rp_key* parse_keydesc (char *keydesc) { - static struct key key; - struct key *p = &key; + static struct rp_key key; + struct rp_key *p = &key; if (!keydesc) return NULL; @@ -231,14 +235,14 @@ cmd_bind (void *data) message (" FIXME: cmd_bind: need a command to bind to key "); else { - struct key *key = parse_keydesc (keydesc); + struct rp_key *key = parse_keydesc (keydesc); if (key) { rp_action *key_action; char foo[1000]; - sprintf (foo, " %ld %ld : '%s' ", key->state, key->sym, cmd); + sprintf (foo, " %d %ld : '%s' ", key->state, key->sym, cmd); message (foo); if ((key_action = find_keybinding (key->sym, key->state))) @@ -303,8 +307,8 @@ cmd_generate (void *data) /* ev1.xkey.x_root == */ /* ev1.xkey.y_root == */ - ev1.xkey.state = MODIFIER_PREFIX; - ev1.xkey.keycode = XKeysymToKeycode (dpy, KEY_PREFIX); + ev1.xkey.state = prefix_key.state; + ev1.xkey.keycode = XKeysymToKeycode (dpy, prefix_key.sym); XSendEvent (dpy, rp_current_window->w, False, KeyPressMask, &ev1); @@ -690,3 +694,48 @@ cmd_maximize (void *data) { force_maximize (rp_current_window); } + +/* Reassign the prefix key. */ +void +cmd_escape (void *data) +{ + rp_window *cur; + struct rp_key *key; + rp_action *action; + + key = parse_keydesc (data); + + if (key) + { + /* Update the "generate" keybinding */ + action = find_keybinding(prefix_key.sym, 0); + if (action != NULL) + { + action->key = key->sym; + action->state = 0; + } + + /* Remove the grab on the current prefix key */ + for (cur = rp_mapped_window_sentinel->next; + cur != rp_mapped_window_sentinel; + cur = cur->next) + { + ungrab_prefix_key (cur->w); + } + + prefix_key.sym = key->sym; + prefix_key.state = key->state; + + /* Add the grab for the new prefix key */ + for (cur = rp_mapped_window_sentinel->next; + cur != rp_mapped_window_sentinel; + cur = cur->next) + { + grab_prefix_key (cur->w); + } + } + else + { + message (" FIXME: cmd_bind: couldnt parse key "); + } +} diff --git a/src/actions.h b/src/actions.h index 7014fa8..b23fc59 100644 --- a/src/actions.h +++ b/src/actions.h @@ -61,16 +61,11 @@ void cmd_unimplemented (void *data); void cmd_bind (void* data); void cmd_source (void* data); void cmd_maximize (void *data); +void cmd_escape (void *data); /* void cmd_xterm (void *data); */ void initialize_default_keybindings (void); rp_action* find_keybinding (int keysym, int state); -struct key -{ - long sym; - long state; -}; - #endif /* ! _RATPOISON_ACTIONS_H */ @@ -25,10 +25,9 @@ #include "data.h" #include "actions.h" -#define KEY_PREFIX 't' +#define KEY_PREFIX XK_t #define MODIFIER_PREFIX ControlMask - /* Quit ratpoison when there are no more managed windows. */ //#define AUTO_CLOSE @@ -78,12 +78,21 @@ struct screen_info struct rp_action { - int key; - int state; + KeySym key; + unsigned int state; void *data; /* misc data to be passed to the function */ /* void (*func)(void *); */ }; +struct rp_key +{ + KeySym sym; + unsigned int state; +}; + +/* The prefix key also known as the command character under screen. */ +extern struct rp_key prefix_key; + /* These _sentinel pointers point to a special rp_window whose next pointer points to the head of the list and whose prev pointer points to the tail. This is done to simplify removing an element diff --git a/src/events.c b/src/events.c index 13cab22..ee468cb 100644 --- a/src/events.c +++ b/src/events.c @@ -358,7 +358,7 @@ key_press (XEvent *ev) if (!s) return; - if (ks == KEY_PREFIX && (modifier == MODIFIER_PREFIX)) + if (ks == prefix_key.sym && (modifier == prefix_key.state)) { handle_key (s); } @@ -63,6 +63,8 @@ char **myargv; XGCValues gv; +struct rp_key prefix_key; + /* Command line options */ static struct option ratpoison_longopts[] = { {"help", no_argument, 0, 'h'}, {"version", no_argument, 0, 'v'}, @@ -325,6 +327,7 @@ main (int argc, char *argv[]) init_numbers (); init_window_list (); + initialize_default_keybindings (); font = XLoadQueryFont (dpy, FONT); if (font == NULL) @@ -348,8 +351,6 @@ main (int argc, char *argv[]) init_screen (&screens[i], i); } - initialize_default_keybindings (); - read_startup_files (); /* Set an initial window as active. */ diff --git a/src/manage.c b/src/manage.c index aaed647..be2613e 100644 --- a/src/manage.c +++ b/src/manage.c @@ -41,15 +41,24 @@ const char *unmanaged_window_list[] = { extern Atom wm_state; -static void +void grab_prefix_key (Window w) { #ifdef HIDE_MOUSE XGrabKey(dpy, AnyKey, AnyModifier, w, True, GrabModeAsync, GrabModeAsync); #else - XGrabKey(dpy, XKeysymToKeycode (dpy, KEY_PREFIX ), MODIFIER_PREFIX, w, True, - GrabModeAsync, GrabModeAsync); + XGrabKey(dpy, XKeysymToKeycode (dpy, prefix_key.sym ), prefix_key.state, + w, True, GrabModeAsync, GrabModeAsync); +#endif +} + +void +ungrab_prefix_key (Window w) +{ +#ifdef HIDE_MOUSE +#else + XUngrabKey(dpy, XKeysymToKeycode (dpy, prefix_key.sym ), prefix_key.state, w); #endif } diff --git a/src/manage.h b/src/manage.h index 2d0eabc..35189f6 100644 --- a/src/manage.h +++ b/src/manage.h @@ -38,4 +38,7 @@ void set_state (rp_window *win, int state); void maximize (rp_window *win); void force_maximize (rp_window *win); +void grab_prefix_key (Window w); +void ungrab_prefix_key (Window w); + #endif /* ! _RATPOISION_MANAGE_H */ |