dwm.c
changeset 1339 fdf4b9511575
parent 1338 04c5619da581
child 1340 15d159526e5e
equal deleted inserted replaced
1338:04c5619da581 1339:fdf4b9511575
   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);
   161 static Bool isprotodel(Client *c);
   162 static Bool isprotodel(Client *c);
   162 static void keypress(XEvent *e);
   163 static void keypress(XEvent *e);
   163 static void killclient(const Arg *arg);
   164 static void killclient(const Arg *arg);
   164 static void manage(Window w, XWindowAttributes *wa);
   165 static void manage(Window w, XWindowAttributes *wa);
   165 static void mappingnotify(XEvent *e);
   166 static void mappingnotify(XEvent *e);
   751 void
   752 void
   752 grabkeys(void) {
   753 grabkeys(void) {
   753 	unsigned int i, j;
   754 	unsigned int i, j;
   754 	unsigned int modifiers[] = { 0, LockMask, numlockmask, numlockmask|LockMask };
   755 	unsigned int modifiers[] = { 0, LockMask, numlockmask, numlockmask|LockMask };
   755 	KeyCode code;
   756 	KeyCode code;
   756 	XModifierKeymap *modmap;
       
   757 
       
   758 	/* init modifier map */
       
   759 	modmap = XGetModifierMapping(dpy);
       
   760 	for(i = 0; i < 8; i++)
       
   761 		for(j = 0; j < modmap->max_keypermod; j++) {
       
   762 			if(modmap->modifiermap[i * modmap->max_keypermod + j] == XKeysymToKeycode(dpy, XK_Num_Lock))
       
   763 				numlockmask = (1 << i);
       
   764 		}
       
   765 	XFreeModifiermap(modmap);
       
   766 
   757 
   767 	XUngrabKey(dpy, AnyKey, AnyModifier, root);
   758 	XUngrabKey(dpy, AnyKey, AnyModifier, root);
   768 	for(i = 0; i < LENGTH(keys); i++) {
   759 	for(i = 0; i < LENGTH(keys); i++) {
   769 		code = XKeysymToKeycode(dpy, keys[i].keysym);
   760 		code = XKeysymToKeycode(dpy, keys[i].keysym);
   770 		for(j = 0; j < LENGTH(modifiers); j++)
   761 		for(j = 0; j < LENGTH(modifiers); j++)
   809 			die("error, cannot load font: '%s'\n", fontstr);
   800 			die("error, cannot load font: '%s'\n", fontstr);
   810 		dc.font.ascent = dc.font.xfont->ascent;
   801 		dc.font.ascent = dc.font.xfont->ascent;
   811 		dc.font.descent = dc.font.xfont->descent;
   802 		dc.font.descent = dc.font.xfont->descent;
   812 	}
   803 	}
   813 	dc.font.height = dc.font.ascent + dc.font.descent;
   804 	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);
   814 }
   818 }
   815 
   819 
   816 Bool
   820 Bool
   817 isprotodel(Client *c) {
   821 isprotodel(Client *c) {
   818 	int i, n;
   822 	int i, n;
   923 void
   927 void
   924 mappingnotify(XEvent *e) {
   928 mappingnotify(XEvent *e) {
   925 	XMappingEvent *ev = &e->xmapping;
   929 	XMappingEvent *ev = &e->xmapping;
   926 
   930 
   927 	XRefreshKeyboardMapping(ev);
   931 	XRefreshKeyboardMapping(ev);
   928 	if(ev->request == MappingKeyboard)
   932 	if(ev->request == MappingKeyboard) {
       
   933 		initmodmap();
   929 		grabkeys();
   934 		grabkeys();
       
   935 	}
   930 }
   936 }
   931 
   937 
   932 void
   938 void
   933 maprequest(XEvent *e) {
   939 maprequest(XEvent *e) {
   934 	static XWindowAttributes wa;
   940 	static XWindowAttributes wa;
  1371 	wa.event_mask = SubstructureRedirectMask|SubstructureNotifyMask|ButtonPressMask
  1377 	wa.event_mask = SubstructureRedirectMask|SubstructureNotifyMask|ButtonPressMask
  1372 			|EnterWindowMask|LeaveWindowMask|StructureNotifyMask;
  1378 			|EnterWindowMask|LeaveWindowMask|StructureNotifyMask;
  1373 	XChangeWindowAttributes(dpy, root, CWEventMask|CWCursor, &wa);
  1379 	XChangeWindowAttributes(dpy, root, CWEventMask|CWCursor, &wa);
  1374 	XSelectInput(dpy, root, wa.event_mask);
  1380 	XSelectInput(dpy, root, wa.event_mask);
  1375 
  1381 
  1376 
  1382 	initmodmap();
  1377 	/* grab keys */
       
  1378 	grabkeys();
  1383 	grabkeys();
  1379 }
  1384 }
  1380 
  1385 
  1381 void
  1386 void
  1382 spawn(const Arg *arg) {
  1387 spawn(const Arg *arg) {