dwm.c
changeset 1340 15d159526e5e
parent 1339 fdf4b9511575
child 1341 8aa84340b558
equal deleted inserted replaced
1339:fdf4b9511575 1340:15d159526e5e
   156 static long getstate(Window w);
   156 static long getstate(Window w);
   157 static Bool gettextprop(Window w, Atom atom, char *text, unsigned int size);
   157 static Bool gettextprop(Window w, Atom atom, char *text, unsigned int size);
   158 static void grabbuttons(Client *c, Bool focused);
   158 static void grabbuttons(Client *c, Bool focused);
   159 static void grabkeys(void);
   159 static void grabkeys(void);
   160 static void initfont(const char *fontstr);
   160 static void initfont(const char *fontstr);
   161 static void initmodmap(void);
       
   162 static Bool isprotodel(Client *c);
   161 static Bool isprotodel(Client *c);
   163 static void keypress(XEvent *e);
   162 static void keypress(XEvent *e);
   164 static void killclient(const Arg *arg);
   163 static void killclient(const Arg *arg);
   165 static void manage(Window w, XWindowAttributes *wa);
   164 static void manage(Window w, XWindowAttributes *wa);
   166 static void mappingnotify(XEvent *e);
   165 static void mappingnotify(XEvent *e);
   750 }
   749 }
   751 
   750 
   752 void
   751 void
   753 grabkeys(void) {
   752 grabkeys(void) {
   754 	unsigned int i, j;
   753 	unsigned int i, j;
   755 	unsigned int modifiers[] = { 0, LockMask, numlockmask, numlockmask|LockMask };
   754 	XModifierKeymap *modmap;
   756 	KeyCode code;
   755 
   757 
   756 	/* update modifier map */
   758 	XUngrabKey(dpy, AnyKey, AnyModifier, root);
   757 	modmap = XGetModifierMapping(dpy);
   759 	for(i = 0; i < LENGTH(keys); i++) {
   758 	for(i = 0; i < 8; i++)
   760 		code = XKeysymToKeycode(dpy, keys[i].keysym);
   759 		for(j = 0; j < modmap->max_keypermod; j++)
   761 		for(j = 0; j < LENGTH(modifiers); j++)
   760 			if(modmap->modifiermap[i * modmap->max_keypermod + j] == XKeysymToKeycode(dpy, XK_Num_Lock))
   762 			XGrabKey(dpy, code, keys[i].mod | modifiers[j], root, True,
   761 				numlockmask = (1 << i);
   763 			         GrabModeAsync, GrabModeAsync);
   762 	XFreeModifiermap(modmap);
       
   763 
       
   764 	{ /* grab keys */
       
   765 		unsigned int modifiers[] = { 0, LockMask, numlockmask, numlockmask|LockMask };
       
   766 		KeyCode code;
       
   767 
       
   768 		XUngrabKey(dpy, AnyKey, AnyModifier, root);
       
   769 		for(i = 0; i < LENGTH(keys); i++) {
       
   770 			code = XKeysymToKeycode(dpy, keys[i].keysym);
       
   771 			for(j = 0; j < LENGTH(modifiers); j++)
       
   772 				XGrabKey(dpy, code, keys[i].mod | modifiers[j], root, True,
       
   773 					 GrabModeAsync, GrabModeAsync);
       
   774 		}
   764 	}
   775 	}
   765 }
   776 }
   766 
   777 
   767 void
   778 void
   768 initfont(const char *fontstr) {
   779 initfont(const char *fontstr) {
   800 			die("error, cannot load font: '%s'\n", fontstr);
   811 			die("error, cannot load font: '%s'\n", fontstr);
   801 		dc.font.ascent = dc.font.xfont->ascent;
   812 		dc.font.ascent = dc.font.xfont->ascent;
   802 		dc.font.descent = dc.font.xfont->descent;
   813 		dc.font.descent = dc.font.xfont->descent;
   803 	}
   814 	}
   804 	dc.font.height = dc.font.ascent + dc.font.descent;
   815 	dc.font.height = dc.font.ascent + dc.font.descent;
   805 }
       
   806 
       
   807 void
       
   808 initmodmap(void) {
       
   809 	unsigned int i, j;
       
   810 	XModifierKeymap *modmap;
       
   811 
       
   812 	modmap = XGetModifierMapping(dpy);
       
   813 	for(i = 0; i < 8; i++)
       
   814 		for(j = 0; j < modmap->max_keypermod; j++)
       
   815 			if(modmap->modifiermap[i * modmap->max_keypermod + j] == XKeysymToKeycode(dpy, XK_Num_Lock))
       
   816 				numlockmask = (1 << i);
       
   817 	XFreeModifiermap(modmap);
       
   818 }
   816 }
   819 
   817 
   820 Bool
   818 Bool
   821 isprotodel(Client *c) {
   819 isprotodel(Client *c) {
   822 	int i, n;
   820 	int i, n;
   927 void
   925 void
   928 mappingnotify(XEvent *e) {
   926 mappingnotify(XEvent *e) {
   929 	XMappingEvent *ev = &e->xmapping;
   927 	XMappingEvent *ev = &e->xmapping;
   930 
   928 
   931 	XRefreshKeyboardMapping(ev);
   929 	XRefreshKeyboardMapping(ev);
   932 	if(ev->request == MappingKeyboard) {
   930 	if(ev->request == MappingKeyboard)
   933 		initmodmap();
       
   934 		grabkeys();
   931 		grabkeys();
   935 	}
       
   936 }
   932 }
   937 
   933 
   938 void
   934 void
   939 maprequest(XEvent *e) {
   935 maprequest(XEvent *e) {
   940 	static XWindowAttributes wa;
   936 	static XWindowAttributes wa;
  1377 	wa.event_mask = SubstructureRedirectMask|SubstructureNotifyMask|ButtonPressMask
  1373 	wa.event_mask = SubstructureRedirectMask|SubstructureNotifyMask|ButtonPressMask
  1378 			|EnterWindowMask|LeaveWindowMask|StructureNotifyMask;
  1374 			|EnterWindowMask|LeaveWindowMask|StructureNotifyMask;
  1379 	XChangeWindowAttributes(dpy, root, CWEventMask|CWCursor, &wa);
  1375 	XChangeWindowAttributes(dpy, root, CWEventMask|CWCursor, &wa);
  1380 	XSelectInput(dpy, root, wa.event_mask);
  1376 	XSelectInput(dpy, root, wa.event_mask);
  1381 
  1377 
  1382 	initmodmap();
       
  1383 	grabkeys();
  1378 	grabkeys();
  1384 }
  1379 }
  1385 
  1380 
  1386 void
  1381 void
  1387 spawn(const Arg *arg) {
  1382 spawn(const Arg *arg) {