dwm.c
changeset 1086 dadc0b94f695
parent 1085 9c4355f988f2
child 1087 197bfedb953c
equal deleted inserted replaced
1085:9c4355f988f2 1086:dadc0b94f695
   162 Bool gettextprop(Window w, Atom atom, char *text, unsigned int size);
   162 Bool gettextprop(Window w, Atom atom, char *text, unsigned int size);
   163 void grabbuttons(Client *c, Bool focused);
   163 void grabbuttons(Client *c, Bool focused);
   164 void grabkeys(void);
   164 void grabkeys(void);
   165 unsigned int idxoftag(const char *tag);
   165 unsigned int idxoftag(const char *tag);
   166 void initfont(Monitor*, const char *fontstr);
   166 void initfont(Monitor*, const char *fontstr);
   167 Bool isoccupied(Monitor *m, unsigned int t);
   167 Bool isoccupied(unsigned int monitor, unsigned int t);
   168 Bool isprotodel(Client *c);
   168 Bool isprotodel(Client *c);
   169 Bool isurgent(int monitor, unsigned int t);
   169 Bool isurgent(unsigned int monitor, unsigned int t);
   170 Bool isvisible(Client *c, int monitor);
   170 Bool isvisible(Client *c, int monitor);
   171 void keypress(XEvent *e);
   171 void keypress(XEvent *e);
   172 void killclient(const char *arg);
   172 void killclient(const char *arg);
   173 void manage(Window w, XWindowAttributes *wa);
   173 void manage(Window w, XWindowAttributes *wa);
   174 void mappingnotify(XEvent *e);
   174 void mappingnotify(XEvent *e);
   560 }
   560 }
   561 
   561 
   562 void
   562 void
   563 drawbar(void) {
   563 drawbar(void) {
   564 	int i, j, x;
   564 	int i, j, x;
       
   565 	Client *c;
   565 
   566 
   566 	for(i = 0; i < mcount; i++) {
   567 	for(i = 0; i < mcount; i++) {
   567 		Monitor *m = &monitors[i];
   568 		Monitor *m = &monitors[i];
   568 		m->dc.x = 0;
   569 		m->dc.x = 0;
       
   570 		for(c = stack; c && !isvisible(c, i); c = c->snext);
       
   571 		fprintf(stderr, "m%d %s\n", i, c ? c->name : "NIL");
   569 		for(j = 0; j < LENGTH(tags); j++) {
   572 		for(j = 0; j < LENGTH(tags); j++) {
   570 			m->dc.w = textw(m, tags[j]);
   573 			m->dc.w = textw(m, tags[j]);
   571 			if(m->seltags[j]) {
   574 			if(m->seltags[j]) {
   572 				drawtext(m, tags[j], m->dc.sel, isurgent(i, j));
   575 				drawtext(m, tags[j], m->dc.sel, isurgent(i, j));
   573 				drawsquare(m, sel && sel->tags[j] && sel->monitor == selmonitor,
   576 				drawsquare(m, c && c->tags[j] && c->monitor == i,
   574 						isoccupied(m, j), isurgent(i, j), m->dc.sel);
   577 						isoccupied(i, j), isurgent(i, j), m->dc.sel);
   575 			}
   578 			}
   576 			else {
   579 			else {
   577 				drawtext(m, tags[j], m->dc.norm, isurgent(i, j));
   580 				drawtext(m, tags[j], m->dc.norm, isurgent(i, j));
   578 				drawsquare(m, sel && sel->tags[j] && sel->monitor == selmonitor,
   581 				drawsquare(m, c && c->tags[j] && c->monitor == i,
   579 						isoccupied(m, j), isurgent(i, j), m->dc.norm);
   582 						isoccupied(i, j), isurgent(i, j), m->dc.norm);
   580 			}
   583 			}
   581 			m->dc.x += m->dc.w;
   584 			m->dc.x += m->dc.w;
   582 		}
   585 		}
   583 		m->dc.w = blw;
   586 		m->dc.w = blw;
   584 		drawtext(m, m->layout->symbol, m->dc.norm, False);
   587 		drawtext(m, m->layout->symbol, m->dc.norm, False);
   585 		x = m->dc.x + m->dc.w;
   588 		x = m->dc.x + m->dc.w;
   586 		m->dc.w = textw(m, stext);
   589 		if(i == selmonitor) {
   587 		m->dc.x = m->sw - m->dc.w;
   590 			m->dc.w = textw(m, stext);
   588 		if(m->dc.x < x) {
   591 			m->dc.x = m->sw - m->dc.w;
   589 			m->dc.x = x;
   592 			if(m->dc.x < x) {
   590 			m->dc.w = m->sw - x;
   593 				m->dc.x = x;
   591 		}
   594 				m->dc.w = m->sw - x;
   592 		drawtext(m, stext, m->dc.norm, False);
   595 			}
       
   596 			drawtext(m, stext, m->dc.norm, False);
       
   597 		}
       
   598 		else
       
   599 			m->dc.x = m->sw;
   593 		if((m->dc.w = m->dc.x - x) > bh) {
   600 		if((m->dc.w = m->dc.x - x) > bh) {
   594 			m->dc.x = x;
   601 			m->dc.x = x;
   595 			if(sel && sel->monitor == selmonitor) {
   602 			if(c) {
   596 				drawtext(m, sel->name, m->dc.sel, False);
   603 				drawtext(m, c->name, m->dc.sel, False);
   597 				drawsquare(m, False, sel->isfloating, False, m->dc.sel);
   604 				drawsquare(m, False, c->isfloating, False, m->dc.sel);
   598 			}
   605 			}
   599 			else
   606 			else
   600 				drawtext(m, NULL, m->dc.norm, False);
   607 				drawtext(m, NULL, m->dc.norm, False);
   601 		}
   608 		}
   602 		XCopyArea(dpy, m->dc.drawable, m->barwin, m->dc.gc, 0, 0, m->sw, bh, 0, 0);
   609 		XCopyArea(dpy, m->dc.drawable, m->barwin, m->dc.gc, 0, 0, m->sw, bh, 0, 0);
   677 void
   684 void
   678 enternotify(XEvent *e) {
   685 enternotify(XEvent *e) {
   679 	Client *c;
   686 	Client *c;
   680 	XCrossingEvent *ev = &e->xcrossing;
   687 	XCrossingEvent *ev = &e->xcrossing;
   681 
   688 
   682 	if(ev->mode != NotifyNormal || ev->detail == NotifyInferior);
   689 	if(ev->mode != NotifyNormal || ev->detail == NotifyInferior) {
   683 		//return;
   690 		if(!isxinerama || ev->window != monitors[selmonitor].root)
       
   691 			return;
       
   692 	}
   684 	if((c = getclient(ev->window)))
   693 	if((c = getclient(ev->window)))
   685 		focus(c);
   694 		focus(c);
   686 	else {
   695 	else {
   687 		selmonitor = monitorat();
   696 		selmonitor = monitorat();
   688 		fprintf(stderr, "updating selmonitor %d\n", selmonitor);
   697 		fprintf(stderr, "updating selmonitor %d\n", selmonitor);
   745 		XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime);
   754 		XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime);
   746 		selmonitor = c->monitor;
   755 		selmonitor = c->monitor;
   747 	}
   756 	}
   748 	else {
   757 	else {
   749 		XSetInputFocus(dpy, m->root, RevertToPointerRoot, CurrentTime);
   758 		XSetInputFocus(dpy, m->root, RevertToPointerRoot, CurrentTime);
       
   759 		drawbar();
   750 	}
   760 	}
   751 }
   761 }
   752 
   762 
   753 void
   763 void
   754 focusin(XEvent *e) { /* there are some broken focus acquiring clients */
   764 focusin(XEvent *e) { /* there are some broken focus acquiring clients */
   970 	}
   980 	}
   971 	m->dc.font.height = m->dc.font.ascent + m->dc.font.descent;
   981 	m->dc.font.height = m->dc.font.ascent + m->dc.font.descent;
   972 }
   982 }
   973 
   983 
   974 Bool
   984 Bool
   975 isoccupied(Monitor *m, unsigned int t) {
   985 isoccupied(unsigned int monitor, unsigned int t) {
   976 	Client *c;
   986 	Client *c;
   977 
   987 
   978 	for(c = clients; c; c = c->next)
   988 	for(c = clients; c; c = c->next)
   979 		if(c->tags[t] && c->monitor == selmonitor)
   989 		if(c->tags[t] && c->monitor == monitor)
   980 			return True;
   990 			return True;
   981 	return False;
   991 	return False;
   982 }
   992 }
   983 
   993 
   984 Bool
   994 Bool
   995 	}
  1005 	}
   996 	return ret;
  1006 	return ret;
   997 }
  1007 }
   998 
  1008 
   999 Bool
  1009 Bool
  1000 isurgent(int monitor, unsigned int t) {
  1010 isurgent(unsigned int monitor, unsigned int t) {
  1001 	Client *c;
  1011 	Client *c;
  1002 
  1012 
  1003 	for(c = clients; c; c = c->next)
  1013 	for(c = clients; c; c = c->next)
  1004 		if(c->monitor == monitor && c->isurgent && c->tags[t])
  1014 		if(c->monitor == monitor && c->isurgent && c->tags[t])
  1005 			return True;
  1015 			return True;
  1008 
  1018 
  1009 Bool
  1019 Bool
  1010 isvisible(Client *c, int monitor) {
  1020 isvisible(Client *c, int monitor) {
  1011 	unsigned int i;
  1021 	unsigned int i;
  1012 
  1022 
       
  1023 	if(c->monitor != monitor)
       
  1024 		return False;
  1013 	for(i = 0; i < LENGTH(tags); i++)
  1025 	for(i = 0; i < LENGTH(tags); i++)
  1014 		if(c->tags[i] && monitors[c->monitor].seltags[i] && c->monitor == monitor)
  1026 		if(c->tags[i] && monitors[c->monitor].seltags[i])
  1015 			return True;
  1027 			return True;
  1016 	return False;
  1028 	return False;
  1017 }
  1029 }
  1018 
  1030 
  1019 void
  1031 void