summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorsabetts <sabetts>2001-09-06 09:01:28 +0000
committersabetts <sabetts>2001-09-06 09:01:28 +0000
commit4fdb7304932cab5d4c5d83b2a9468c9c2dc0f6aa (patch)
tree328a786c9ec4514dbc0e59a0eb9690c1d2b636ab /src
parentfdf305b75123f1ca5b7e08e951760a93a2c106fd (diff)
downloadratpoison-4fdb7304932cab5d4c5d83b2a9468c9c2dc0f6aa.zip
numlock, caps lock, and scroll lock are ignored for the prefix key.
Diffstat (limited to 'src')
-rw-r--r--src/data.h5
-rw-r--r--src/events.c2
-rw-r--r--src/input.c117
-rw-r--r--src/input.h3
-rw-r--r--src/manage.c5
5 files changed, 89 insertions, 43 deletions
diff --git a/src/data.h b/src/data.h
index 7bad7f1..6ed2d44 100644
--- a/src/data.h
+++ b/src/data.h
@@ -172,6 +172,11 @@ struct modifier_info
unsigned int alt_mod_mask;
unsigned int super_mod_mask;
unsigned int hyper_mod_mask;
+
+ /* Keep track of these because they mess up the grab and should be
+ ignored. */
+ unsigned int num_lock_mask;
+ unsigned int scroll_lock_mask;
};
/* Keeps track of which mod mask each modifier is under. */
diff --git a/src/events.c b/src/events.c
index 9fe9c24..98ffa11 100644
--- a/src/events.c
+++ b/src/events.c
@@ -458,7 +458,7 @@ key_press (XEvent *ev)
if (!s) return;
modifier = ev->xkey.state;
- cook_keycode ( &ev->xkey, &ks, &modifier, NULL, 0);
+ cook_keycode ( &ev->xkey, &ks, &modifier, NULL, 0, 1);
if (ks == prefix_key.sym && (modifier == prefix_key.state))
{
diff --git a/src/input.c b/src/input.c
index a0523eb..afb3c71 100644
--- a/src/input.c
+++ b/src/input.c
@@ -37,11 +37,12 @@ update_modifier_map ()
int row, col; /* The row and column in the modifier table. */
XModifierKeymap *mods;
-/* rp_modifier_info.mode_switch_mask = 0; */
rp_modifier_info.meta_mod_mask = 0;
rp_modifier_info.alt_mod_mask = 0;
rp_modifier_info.super_mod_mask = 0;
rp_modifier_info.hyper_mod_mask = 0;
+ rp_modifier_info.num_lock_mask = 0;
+ rp_modifier_info.scroll_lock_mask = 0;
mods = XGetModifierMapping (dpy);
@@ -54,40 +55,45 @@ update_modifier_map ()
switch (XKeycodeToKeysym(dpy, code, 0))
{
- case XK_Meta_L:
- case XK_Meta_R:
- rp_modifier_info.meta_mod_mask |= modmasks[row - 3];
- PRINT_DEBUG ("Found Meta on %d\n",
- rp_modifier_info.meta_mod_mask);
- break;
-
- case XK_Alt_L:
- case XK_Alt_R:
- rp_modifier_info.alt_mod_mask |= modmasks[row - 3];
- PRINT_DEBUG ("Found Alt on %d\n",
- rp_modifier_info.alt_mod_mask);
- break;
-
- case XK_Super_L:
- case XK_Super_R:
- rp_modifier_info.super_mod_mask |= modmasks[row - 3];
- PRINT_DEBUG ("Found Super on %d\n",
- rp_modifier_info.super_mod_mask);
- break;
-
- case XK_Hyper_L:
- case XK_Hyper_R:
- rp_modifier_info.hyper_mod_mask |= modmasks[row - 3];
- PRINT_DEBUG ("Found Hyper on %d\n",
- rp_modifier_info.hyper_mod_mask);
- break;
-
-/* case XK_Mode_switch: */
-/* rp_modifier_info.mode_switch_mask |= modmasks[row - 3]; */
-/* PRINT_DEBUG ("Found Mode_switch on %d\n", */
-/* rp_modifier_info.mode_switch_mask); */
-/* break; */
+ case XK_Meta_L:
+ case XK_Meta_R:
+ rp_modifier_info.meta_mod_mask |= modmasks[row - 3];
+ PRINT_DEBUG ("Found Meta on %d\n",
+ rp_modifier_info.meta_mod_mask);
+ break;
+
+ case XK_Alt_L:
+ case XK_Alt_R:
+ rp_modifier_info.alt_mod_mask |= modmasks[row - 3];
+ PRINT_DEBUG ("Found Alt on %d\n",
+ rp_modifier_info.alt_mod_mask);
+ break;
+
+ case XK_Super_L:
+ case XK_Super_R:
+ rp_modifier_info.super_mod_mask |= modmasks[row - 3];
+ PRINT_DEBUG ("Found Super on %d\n",
+ rp_modifier_info.super_mod_mask);
+ break;
+ case XK_Hyper_L:
+ case XK_Hyper_R:
+ rp_modifier_info.hyper_mod_mask |= modmasks[row - 3];
+ PRINT_DEBUG ("Found Hyper on %d\n",
+ rp_modifier_info.hyper_mod_mask);
+ break;
+
+ case XK_Num_Lock:
+ rp_modifier_info.num_lock_mask |= modmasks[row - 3];
+ PRINT_DEBUG ("Found NumLock on %d\n",
+ rp_modifier_info.num_lock_mask);
+ break;
+
+ case XK_Scroll_Lock:
+ rp_modifier_info.scroll_lock_mask |= modmasks[row - 3];
+ PRINT_DEBUG ("Found ScrollLock on %d\n",
+ rp_modifier_info.scroll_lock_mask);
+ break;
default:
break;
}
@@ -111,6 +117,34 @@ update_modifier_map ()
XFreeModifiermap (mods);
}
+/* Grab the key while ignoring annoying modifier keys including
+ caps lock, num lock, and scroll lock. */
+void
+grab_key (int keycode, unsigned int modifiers, Window grab_window)
+{
+ unsigned int mod_list[8];
+ int i;
+
+ /* Create a list of all possible combinations of ignored
+ modifiers. Assumes there are only 3 ignored modifiers. */
+ mod_list[0] = 0;
+ mod_list[1] = LockMask;
+ mod_list[2] = rp_modifier_info.num_lock_mask;
+ mod_list[3] = mod_list[1] | mod_list[2];
+ mod_list[4] = rp_modifier_info.scroll_lock_mask;
+ mod_list[5] = mod_list[1] | mod_list[4];
+ mod_list[6] = mod_list[2] | mod_list[4];
+ mod_list[7] = mod_list[1] | mod_list[2] | mod_list[4];
+
+ /* Grab every combination of ignored modifiers. */
+ for (i=0; i<8; i++)
+ {
+ XGrabKey(dpy, keycode, modifiers | mod_list[i],
+ grab_window, True, GrabModeAsync, GrabModeAsync);
+ }
+}
+
+
/* Return the name of the keysym. caller must free returned pointer */
char *
keysym_to_string (KeySym keysym, unsigned int modifier)
@@ -143,11 +177,18 @@ keysym_to_string (KeySym keysym, unsigned int modifier)
interested in the keysym name pass in NULL for keysym_name and 0
for len. */
int
-cook_keycode (XKeyEvent *ev, KeySym *keysym, unsigned int *mod, char *keysym_name, int len)
+cook_keycode (XKeyEvent *ev, KeySym *keysym, unsigned int *mod, char *keysym_name, int len, int ignore_bad_mods)
{
-int nbytes;
+ int nbytes;
+
+ if (ignore_bad_mods)
+ {
+ ev->state &= ~(LockMask
+ | rp_modifier_info.num_lock_mask
+ | rp_modifier_info.scroll_lock_mask);
+ }
- nbytes = XLookupString (ev, keysym_name, len, keysym, NULL);
+ nbytes = XLookupString (ev, keysym_name, len, keysym, NULL);
*mod = ev->state;
*mod &= (rp_modifier_info.meta_mod_mask
@@ -234,7 +275,7 @@ read_key (KeySym *keysym, unsigned int *modifiers, char *keysym_name, int len)
{
XMaskEvent (dpy, KeyPressMask, &ev);
*modifiers = ev.xkey.state;
- nbytes = cook_keycode (&ev.xkey, keysym, modifiers, keysym_name, len);
+ nbytes = cook_keycode (&ev.xkey, keysym, modifiers, keysym_name, len, 0);
} while (IsModifierKey (*keysym));
return nbytes;
diff --git a/src/input.h b/src/input.h
index 4a74ac3..44f009d 100644
--- a/src/input.h
+++ b/src/input.h
@@ -23,10 +23,11 @@
#define _RATPOISON_INPUT_H 1
char *keysym_to_string (KeySym keysym, unsigned int modifier);
-int cook_keycode (XKeyEvent *ev, KeySym *keysym, unsigned int *mod, char *keysym_name, int len);
+int cook_keycode (XKeyEvent *ev, KeySym *keysym, unsigned int *mod, char *keysym_name, int len, int ignore_bad_mods);
char *get_input (char *prompt);
char *get_more_input (char *prompt, char *preinput);
int read_key (KeySym *keysym, unsigned int *modifiers, char *keysym_name, int len);
void update_modifier_map ();
+void grab_key (int keycode, unsigned int modifiers, Window grab_window);
#endif /* ! _RATPOISON_INPUT_H */
diff --git a/src/manage.c b/src/manage.c
index 6f2357d..47e5574 100644
--- a/src/manage.c
+++ b/src/manage.c
@@ -48,8 +48,7 @@ grab_prefix_key (Window w)
XGrabKey(dpy, AnyKey, AnyModifier, w, True,
GrabModeAsync, GrabModeAsync);
#else
- XGrabKey(dpy, XKeysymToKeycode (dpy, prefix_key.sym ), prefix_key.state,
- w, True, GrabModeAsync, GrabModeAsync);
+ grab_key (XKeysymToKeycode (dpy, prefix_key.sym), prefix_key.state, w);
#endif
}
@@ -58,7 +57,7 @@ ungrab_prefix_key (Window w)
{
#ifdef HIDE_MOUSE
#else
- XUngrabKey(dpy, XKeysymToKeycode (dpy, prefix_key.sym ), prefix_key.state, w);
+ XUngrabKey(dpy, XKeysymToKeycode (dpy, prefix_key.sym), AnyModifier, w);
#endif
}