[hackers] [dwm] changed grabkeys, removed initmodmap || Anselm R Garbe

From: <hg_AT_suckless.org>
Date: Sat, 23 Aug 2008 08:31:33 +0000 (UTC)

changeset: 1340:15d159526e5e
tag: tip
user: Anselm R Garbe <garbeam_AT_gmail.com>
date: Sat Aug 23 09:31:28 2008 +0100
files: dwm.c
description:
changed grabkeys, removed initmodmap

diff -r fdf4b9511575 -r 15d159526e5e dwm.c
--- a/dwm.c Sat Aug 23 09:26:11 2008 +0100
+++ b/dwm.c Sat Aug 23 09:31:28 2008 +0100
@@ -158,7 +158,6 @@
 static void grabbuttons(Client *c, Bool focused);
 static void grabkeys(void);
 static void initfont(const char *fontstr);
-static void initmodmap(void);
 static Bool isprotodel(Client *c);
 static void keypress(XEvent *e);
 static void killclient(const Arg *arg);
@@ -752,15 +751,27 @@
 void
 grabkeys(void) {
         unsigned int i, j;
- unsigned int modifiers[] = { 0, LockMask, numlockmask, numlockmask|LockMask };
- KeyCode code;
+ XModifierKeymap *modmap;
 
- XUngrabKey(dpy, AnyKey, AnyModifier, root);
- for(i = 0; i < LENGTH(keys); i++) {
- code = XKeysymToKeycode(dpy, keys[i].keysym);
- for(j = 0; j < LENGTH(modifiers); j++)
- XGrabKey(dpy, code, keys[i].mod | modifiers[j], root, True,
- GrabModeAsync, GrabModeAsync);
+ /* update modifier map */
+ modmap = XGetModifierMapping(dpy);
+ for(i = 0; i < 8; i++)
+ for(j = 0; j < modmap->max_keypermod; j++)
+ if(modmap->modifiermap[i * modmap->max_keypermod + j] == XKeysymToKeycode(dpy, XK_Num_Lock))
+ numlockmask = (1 << i);
+ XFreeModifiermap(modmap);
+
+ { /* grab keys */
+ unsigned int modifiers[] = { 0, LockMask, numlockmask, numlockmask|LockMask };
+ KeyCode code;
+
+ XUngrabKey(dpy, AnyKey, AnyModifier, root);
+ for(i = 0; i < LENGTH(keys); i++) {
+ code = XKeysymToKeycode(dpy, keys[i].keysym);
+ for(j = 0; j < LENGTH(modifiers); j++)
+ XGrabKey(dpy, code, keys[i].mod | modifiers[j], root, True,
+ GrabModeAsync, GrabModeAsync);
+ }
         }
 }
 
@@ -802,19 +813,6 @@
                 dc.font.descent = dc.font.xfont->descent;
         }
         dc.font.height = dc.font.ascent + dc.font.descent;
-}
-
-void
-initmodmap(void) {
- unsigned int i, j;
- XModifierKeymap *modmap;
-
- modmap = XGetModifierMapping(dpy);
- for(i = 0; i < 8; i++)
- for(j = 0; j < modmap->max_keypermod; j++)
- if(modmap->modifiermap[i * modmap->max_keypermod + j] == XKeysymToKeycode(dpy, XK_Num_Lock))
- numlockmask = (1 << i);
- XFreeModifiermap(modmap);
 }
 
 Bool
@@ -929,10 +927,8 @@
         XMappingEvent *ev = &e->xmapping;
 
         XRefreshKeyboardMapping(ev);
- if(ev->request == MappingKeyboard) {
- initmodmap();
+ if(ev->request == MappingKeyboard)
                 grabkeys();
- }
 }
 
 void
@@ -1379,7 +1375,6 @@
         XChangeWindowAttributes(dpy, root, CWEventMask|CWCursor, &wa);
         XSelectInput(dpy, root, wa.event_mask);
 
- initmodmap();
         grabkeys();
 }
 
Received on Sat Aug 23 2008 - 08:31:33 UTC

This archive was generated by hypermail 2.2.0 : Sat Aug 23 2008 - 08:36:08 UTC