dwm.c
changeset 1318 65c37b4be9cb
parent 1317 40cd44593977
child 1319 fb29ceb5932a
equal deleted inserted replaced
1317:40cd44593977 1318:65c37b4be9cb
   157 static long getstate(Window w);
   157 static long getstate(Window w);
   158 static Bool gettextprop(Window w, Atom atom, char *text, unsigned int size);
   158 static Bool gettextprop(Window w, Atom atom, char *text, unsigned int size);
   159 static void grabbuttons(Client *c, Bool focused);
   159 static void grabbuttons(Client *c, Bool focused);
   160 static void grabkeys(void);
   160 static void grabkeys(void);
   161 static void initfont(const char *fontstr);
   161 static void initfont(const char *fontstr);
   162 static Bool isoccupied(unsigned int t);
       
   163 static Bool isprotodel(Client *c);
   162 static Bool isprotodel(Client *c);
   164 static Bool isurgent(unsigned int t);
       
   165 static void keypress(XEvent *e);
   163 static void keypress(XEvent *e);
   166 static void killclient(const Arg *arg);
   164 static void killclient(const Arg *arg);
   167 static void manage(Window w, XWindowAttributes *wa);
   165 static void manage(Window w, XWindowAttributes *wa);
   168 static void mappingnotify(XEvent *e);
   166 static void mappingnotify(XEvent *e);
   169 static void maprequest(XEvent *e);
   167 static void maprequest(XEvent *e);
   498 	exit(EXIT_FAILURE);
   496 	exit(EXIT_FAILURE);
   499 }
   497 }
   500 
   498 
   501 void
   499 void
   502 drawbar(void) {
   500 drawbar(void) {
   503 	int i, x;
   501 	int x;
       
   502 	unsigned int i, occ = 0, urg = 0;
       
   503 	unsigned long *col;
       
   504 	Client *c;
       
   505 
       
   506 	for(c = clients; c; c = c->next) {
       
   507 		occ |= c->tags;
       
   508 		if(c->isurgent)
       
   509 			urg |= c->tags;
       
   510 	}
   504 
   511 
   505 	dc.x = 0;
   512 	dc.x = 0;
   506 	for(i = 0; i < LENGTH(tags); i++) {
   513 	for(i = 0; i < LENGTH(tags); i++) {
   507 		dc.w = TEXTW(tags[i]);
   514 		dc.w = TEXTW(tags[i]);
   508 		if(tagset[seltags] & 1 << i) {
   515 		col = tagset[seltags] & 1 << i ? dc.sel : dc.norm;
   509 			drawtext(tags[i], dc.sel, isurgent(i));
   516 		drawtext(tags[i], col, urg & 1 << i);
   510 			drawsquare(sel && sel->tags & 1 << i, isoccupied(i), isurgent(i), dc.sel);
   517 		drawsquare(sel && sel->tags & 1 << i, occ & 1 << i, urg & 1 << i, col);
   511 		}
       
   512 		else {
       
   513 			drawtext(tags[i], dc.norm, isurgent(i));
       
   514 			drawsquare(sel && sel->tags & 1 << i, isoccupied(i), isurgent(i), dc.norm);
       
   515 		}
       
   516 		dc.x += dc.w;
   518 		dc.x += dc.w;
   517 	}
   519 	}
   518 	if(blw > 0) {
   520 	if(blw > 0) {
   519 		dc.w = blw;
   521 		dc.w = blw;
   520 		drawtext(lt[sellt]->symbol, dc.norm, False);
   522 		drawtext(lt[sellt]->symbol, dc.norm, False);
   739 	if(focused) {
   741 	if(focused) {
   740 		for(i = 0; i < LENGTH(buttons); i++)
   742 		for(i = 0; i < LENGTH(buttons); i++)
   741 			if(buttons[i].click == ClkClientWin)
   743 			if(buttons[i].click == ClkClientWin)
   742 				for(j = 0; j < LENGTH(modifiers); j++)
   744 				for(j = 0; j < LENGTH(modifiers); j++)
   743 					XGrabButton(dpy, buttons[i].button, buttons[i].mask | modifiers[j], c->win, False, BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
   745 					XGrabButton(dpy, buttons[i].button, buttons[i].mask | modifiers[j], c->win, False, BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
   744         } else
   746 	} else
   745 		XGrabButton(dpy, AnyButton, AnyModifier, c->win, False,
   747 		XGrabButton(dpy, AnyButton, AnyModifier, c->win, False,
   746 		            BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
   748 		            BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
   747 }
   749 }
   748 
   750 
   749 void
   751 void
   750 grabkeys(void) {
   752 grabkeys(void) {
   751 	unsigned int i, j;
   753 	unsigned int i, j;
       
   754 	unsigned int modifiers[] = { 0, LockMask, numlockmask, numlockmask|LockMask };
   752 	KeyCode code;
   755 	KeyCode code;
   753 	XModifierKeymap *modmap;
   756 	XModifierKeymap *modmap;
   754 
   757 
   755 	/* init modifier map */
   758 	/* init modifier map */
   756 	modmap = XGetModifierMapping(dpy);
   759 	modmap = XGetModifierMapping(dpy);
   762 	XFreeModifiermap(modmap);
   765 	XFreeModifiermap(modmap);
   763 
   766 
   764 	XUngrabKey(dpy, AnyKey, AnyModifier, root);
   767 	XUngrabKey(dpy, AnyKey, AnyModifier, root);
   765 	for(i = 0; i < LENGTH(keys); i++) {
   768 	for(i = 0; i < LENGTH(keys); i++) {
   766 		code = XKeysymToKeycode(dpy, keys[i].keysym);
   769 		code = XKeysymToKeycode(dpy, keys[i].keysym);
   767 		XGrabKey(dpy, code, keys[i].mod, root, True,
   770 		for(j = 0; j < LENGTH(modifiers); j++)
   768 				GrabModeAsync, GrabModeAsync);
   771 			XGrabKey(dpy, code, keys[i].mod | modifiers[j], root, True,
   769 		XGrabKey(dpy, code, keys[i].mod|LockMask, root, True,
   772 			         GrabModeAsync, GrabModeAsync);
   770 				GrabModeAsync, GrabModeAsync);
       
   771 		XGrabKey(dpy, code, keys[i].mod|numlockmask, root, True,
       
   772 				GrabModeAsync, GrabModeAsync);
       
   773 		XGrabKey(dpy, code, keys[i].mod|numlockmask|LockMask, root, True,
       
   774 				GrabModeAsync, GrabModeAsync);
       
   775 	}
   773 	}
   776 }
   774 }
   777 
   775 
   778 void
   776 void
   779 initfont(const char *fontstr) {
   777 initfont(const char *fontstr) {
   814 	}
   812 	}
   815 	dc.font.height = dc.font.ascent + dc.font.descent;
   813 	dc.font.height = dc.font.ascent + dc.font.descent;
   816 }
   814 }
   817 
   815 
   818 Bool
   816 Bool
   819 isoccupied(unsigned int t) {
       
   820 	Client *c;
       
   821 
       
   822 	for(c = clients; c; c = c->next)
       
   823 		if(c->tags & 1 << t)
       
   824 			return True;
       
   825 	return False;
       
   826 }
       
   827 
       
   828 Bool
       
   829 isprotodel(Client *c) {
   817 isprotodel(Client *c) {
   830 	int i, n;
   818 	int i, n;
   831 	Atom *protocols;
   819 	Atom *protocols;
   832 	Bool ret = False;
   820 	Bool ret = False;
   833 
   821 
   836 			if(protocols[i] == wmatom[WMDelete])
   824 			if(protocols[i] == wmatom[WMDelete])
   837 				ret = True;
   825 				ret = True;
   838 		XFree(protocols);
   826 		XFree(protocols);
   839 	}
   827 	}
   840 	return ret;
   828 	return ret;
   841 }
       
   842 
       
   843 Bool
       
   844 isurgent(unsigned int t) {
       
   845 	Client *c;
       
   846 
       
   847 	for(c = clients; c; c = c->next)
       
   848 		if(c->isurgent && c->tags & 1 << t)
       
   849 			return True;
       
   850 	return False;
       
   851 }
   829 }
   852 
   830 
   853 void
   831 void
   854 keypress(XEvent *e) {
   832 keypress(XEvent *e) {
   855 	unsigned int i;
   833 	unsigned int i;