dwm.c
changeset 1426 f8ee1d055e66
parent 1425 120ed5f8018b
child 1427 f8ea02f86861
equal deleted inserted replaced
1425:120ed5f8018b 1426:f8ee1d055e66
   174 static void focus(Client *c);
   174 static void focus(Client *c);
   175 static void focusin(XEvent *e);
   175 static void focusin(XEvent *e);
   176 static void focusstack(const Arg *arg);
   176 static void focusstack(const Arg *arg);
   177 static Client *getclient(Window w);
   177 static Client *getclient(Window w);
   178 static unsigned long getcolor(const char *colstr);
   178 static unsigned long getcolor(const char *colstr);
   179 static Monitor *getmonitor(Window w);
   179 static Monitor *getmon(Window w);
   180 static Monitor *getmonitorxy(int x, int y);
   180 static Monitor *getmonxy(int x, int y);
   181 static Bool getrootpointer(int *x, int *y);
   181 static Bool getrootpointer(int *x, int *y);
   182 static long getstate(Window w);
   182 static long getstate(Window w);
   183 static Bool gettextprop(Window w, Atom atom, char *text, unsigned int size);
   183 static Bool gettextprop(Window w, Atom atom, char *text, unsigned int size);
   184 static void grabbuttons(Client *c, Bool focused);
   184 static void grabbuttons(Client *c, Bool focused);
   185 static void grabkeys(void);
   185 static void grabkeys(void);
   399 	Monitor *m;
   399 	Monitor *m;
   400 	XButtonPressedEvent *ev = &e->xbutton;
   400 	XButtonPressedEvent *ev = &e->xbutton;
   401 
   401 
   402 	click = ClkRootWin;
   402 	click = ClkRootWin;
   403 	/* focus monitor if necessary */
   403 	/* focus monitor if necessary */
   404 	if((m = getmonitor(ev->window)) && m != selmon) {
   404 	if((m = getmon(ev->window)) && m != selmon) {
   405 		unfocus(selmon->sel);
   405 		unfocus(selmon->sel);
   406 		selmon = m;
   406 		selmon = m;
   407 		focus(NULL);
   407 		focus(NULL);
   408 	}
   408 	}
   409 	if(ev->window == selmon->barwin && ev->x >= selmon->btx) {
   409 	if(ev->window == selmon->barwin && ev->x >= selmon->btx) {
   745 	Monitor *m;
   745 	Monitor *m;
   746 	XCrossingEvent *ev = &e->xcrossing;
   746 	XCrossingEvent *ev = &e->xcrossing;
   747 
   747 
   748 	if((ev->mode != NotifyNormal || ev->detail == NotifyInferior) && ev->window != root)
   748 	if((ev->mode != NotifyNormal || ev->detail == NotifyInferior) && ev->window != root)
   749 		return;
   749 		return;
   750 	if((m = getmonitor(ev->window)) && m != selmon) {
   750 	if((m = getmon(ev->window)) && m != selmon) {
   751 		unfocus(selmon->sel);
   751 		unfocus(selmon->sel);
   752 		selmon = m;
   752 		selmon = m;
   753 	}
   753 	}
   754 	if((c = getclient(ev->window)))
   754 	if((c = getclient(ev->window)))
   755 		focus(c);
   755 		focus(c);
   760 void
   760 void
   761 expose(XEvent *e) {
   761 expose(XEvent *e) {
   762 	Monitor *m;
   762 	Monitor *m;
   763 	XExposeEvent *ev = &e->xexpose;
   763 	XExposeEvent *ev = &e->xexpose;
   764 
   764 
   765 	if(ev->count == 0 && (m = getmonitor(ev->window)))
   765 	if(ev->count == 0 && (m = getmon(ev->window)))
   766 		drawbar(m);
   766 		drawbar(m);
   767 }
   767 }
   768 
   768 
   769 void
   769 void
   770 focus(Client *c) {
   770 focus(Client *c) {
   862 		die("error, cannot allocate color '%s'\n", colstr);
   862 		die("error, cannot allocate color '%s'\n", colstr);
   863 	return color.pixel;
   863 	return color.pixel;
   864 }
   864 }
   865 
   865 
   866 Monitor *
   866 Monitor *
   867 getmonitor(Window w) {
   867 getmon(Window w) {
   868 	int x, y;
   868 	int x, y;
   869 	Client *c;
   869 	Client *c;
   870 	Monitor *m;
   870 	Monitor *m;
   871 
   871 
   872 	if(w == root && getrootpointer(&x, &y))
   872 	if(w == root && getrootpointer(&x, &y))
   873 		return getmonitorxy(x, y);
   873 		return getmonxy(x, y);
   874 	for(m = mons; m; m = m->next)
   874 	for(m = mons; m; m = m->next)
   875 		if(w == m->barwin)
   875 		if(w == m->barwin)
   876 			return m;
   876 			return m;
   877 	if((c = getclient(w)))
   877 	if((c = getclient(w)))
   878 		return c->mon;
   878 		return c->mon;
   879 	return NULL;
   879 	return NULL;
   880 }
   880 }
   881 
   881 
   882 Monitor *
   882 Monitor *
   883 getmonitorxy(int x, int y) {
   883 getmonxy(int x, int y) {
   884 	Monitor *m;
   884 	Monitor *m;
   885 
   885 
   886 	for(m = mons; m; m = m->next)
   886 	for(m = mons; m; m = m->next)
   887 		if(INRECT(x, y, m->wx, m->wy, m->ww, m->wh))
   887 		if(INRECT(x, y, m->wx, m->wy, m->ww, m->wh))
   888 			return m;
   888 			return m;
  1203 			break;
  1203 			break;
  1204 		}
  1204 		}
  1205 	}
  1205 	}
  1206 	while(ev.type != ButtonRelease);
  1206 	while(ev.type != ButtonRelease);
  1207 	XUngrabPointer(dpy, CurrentTime);
  1207 	XUngrabPointer(dpy, CurrentTime);
  1208 	if((m = getmonitorxy(c->x + c->w / 2, c->y + c->h / 2)) != selmon)
  1208 	if((m = getmonxy(c->x + c->w / 2, c->y + c->h / 2)) != selmon)
  1209 		sendmon(c, m);
  1209 		sendmon(c, m);
  1210 }
  1210 }
  1211 
  1211 
  1212 Client *
  1212 Client *
  1213 nexttiled(Client *c) {
  1213 nexttiled(Client *c) {
  1312 	}
  1312 	}
  1313 	while(ev.type != ButtonRelease);
  1313 	while(ev.type != ButtonRelease);
  1314 	XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w + c->bw - 1, c->h + c->bw - 1);
  1314 	XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w + c->bw - 1, c->h + c->bw - 1);
  1315 	XUngrabPointer(dpy, CurrentTime);
  1315 	XUngrabPointer(dpy, CurrentTime);
  1316 	while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
  1316 	while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
  1317 	if((m = getmonitorxy(c->x + c->w / 2, c->y + c->h / 2)) != selmon)
  1317 	if((m = getmonxy(c->x + c->w / 2, c->y + c->h / 2)) != selmon)
  1318 		sendmon(c, m);
  1318 		sendmon(c, m);
  1319 }
  1319 }
  1320 
  1320 
  1321 void
  1321 void
  1322 restack(Monitor *m) {
  1322 restack(Monitor *m) {
  1807 		}
  1807 		}
  1808 
  1808 
  1809 	/* select focused monitor */
  1809 	/* select focused monitor */
  1810 	cleanupmons();
  1810 	cleanupmons();
  1811 	mons = newmons;
  1811 	mons = newmons;
  1812 	selmon = getmonitor(root);
  1812 	selmon = getmon(root);
  1813 }
  1813 }
  1814 
  1814 
  1815 void
  1815 void
  1816 updatenumlockmask(void) {
  1816 updatenumlockmask(void) {
  1817 	unsigned int i, j;
  1817 	unsigned int i, j;