dwm.c
changeset 1450 b2d18a052137
parent 1449 8fcc541b5238
child 1451 b563268bd78a
equal deleted inserted replaced
1449:8fcc541b5238 1450:b2d18a052137
   175 static void focus(Client *c);
   175 static void focus(Client *c);
   176 static void focusin(XEvent *e);
   176 static void focusin(XEvent *e);
   177 static void focusmon(const Arg *arg);
   177 static void focusmon(const Arg *arg);
   178 static void focusstack(const Arg *arg);
   178 static void focusstack(const Arg *arg);
   179 static unsigned long getcolor(const char *colstr);
   179 static unsigned long getcolor(const char *colstr);
   180 static Bool getrootpointer(int *x, int *y);
   180 static Bool getrootptr(int *x, int *y);
   181 static long getstate(Window w);
   181 static long getstate(Window w);
   182 static Bool gettextprop(Window w, Atom atom, char *text, unsigned int size);
   182 static Bool gettextprop(Window w, Atom atom, char *text, unsigned int size);
   183 static void grabbuttons(Client *c, Bool focused);
   183 static void grabbuttons(Client *c, Bool focused);
   184 static void grabkeys(void);
   184 static void grabkeys(void);
   185 static void initfont(const char *fontstr);
   185 static void initfont(const char *fontstr);
   190 static void mappingnotify(XEvent *e);
   190 static void mappingnotify(XEvent *e);
   191 static void maprequest(XEvent *e);
   191 static void maprequest(XEvent *e);
   192 static void monocle(Monitor *m);
   192 static void monocle(Monitor *m);
   193 static void movemouse(const Arg *arg);
   193 static void movemouse(const Arg *arg);
   194 static Client *nexttiled(Client *c);
   194 static Client *nexttiled(Client *c);
   195 static Monitor *pointertomon(int x, int y);
   195 static Monitor *ptrtomon(int x, int y);
   196 static void propertynotify(XEvent *e);
   196 static void propertynotify(XEvent *e);
   197 static void quit(const Arg *arg);
   197 static void quit(const Arg *arg);
   198 static void resize(Client *c, int x, int y, int w, int h, Bool interact);
   198 static void resize(Client *c, int x, int y, int w, int h, Bool interact);
   199 static void resizemouse(const Arg *arg);
   199 static void resizemouse(const Arg *arg);
   200 static void restack(Monitor *m);
   200 static void restack(Monitor *m);
   860 		die("error, cannot allocate color '%s'\n", colstr);
   860 		die("error, cannot allocate color '%s'\n", colstr);
   861 	return color.pixel;
   861 	return color.pixel;
   862 }
   862 }
   863 
   863 
   864 Bool
   864 Bool
   865 getrootpointer(int *x, int *y) {
   865 getrootptr(int *x, int *y) {
   866 	int di;
   866 	int di;
   867 	unsigned int dui;
   867 	unsigned int dui;
   868 	Window dummy;
   868 	Window dummy;
   869 
   869 
   870 	return XQueryPointer(dpy, root, &dummy, &dummy, x, y, &di, &di, &dui);
   870 	return XQueryPointer(dpy, root, &dummy, &dummy, x, y, &di, &di, &dui);
  1145 	ocx = c->x;
  1145 	ocx = c->x;
  1146 	ocy = c->y;
  1146 	ocy = c->y;
  1147 	if(XGrabPointer(dpy, root, False, MOUSEMASK, GrabModeAsync, GrabModeAsync,
  1147 	if(XGrabPointer(dpy, root, False, MOUSEMASK, GrabModeAsync, GrabModeAsync,
  1148 	None, cursor[CurMove], CurrentTime) != GrabSuccess)
  1148 	None, cursor[CurMove], CurrentTime) != GrabSuccess)
  1149 		return;
  1149 		return;
  1150 	if(!getrootpointer(&x, &y))
  1150 	if(!getrootptr(&x, &y))
  1151 		return;
  1151 		return;
  1152 	do {
  1152 	do {
  1153 		XMaskEvent(dpy, MOUSEMASK|ExposureMask|SubstructureRedirectMask, &ev);
  1153 		XMaskEvent(dpy, MOUSEMASK|ExposureMask|SubstructureRedirectMask, &ev);
  1154 		switch (ev.type) {
  1154 		switch (ev.type) {
  1155 		case ConfigureRequest:
  1155 		case ConfigureRequest:
  1179 			break;
  1179 			break;
  1180 		}
  1180 		}
  1181 	}
  1181 	}
  1182 	while(ev.type != ButtonRelease);
  1182 	while(ev.type != ButtonRelease);
  1183 	XUngrabPointer(dpy, CurrentTime);
  1183 	XUngrabPointer(dpy, CurrentTime);
  1184 	if((m = pointertomon(c->x + c->w / 2, c->y + c->h / 2)) != selmon) {
  1184 	if((m = ptrtomon(c->x + c->w / 2, c->y + c->h / 2)) != selmon) {
  1185 		sendmon(c, m);
  1185 		sendmon(c, m);
  1186 		selmon = m;
  1186 		selmon = m;
  1187 		focus(NULL);
  1187 		focus(NULL);
  1188 	}
  1188 	}
  1189 }
  1189 }
  1193 	for(; c && (c->isfloating || !ISVISIBLE(c)); c = c->next);
  1193 	for(; c && (c->isfloating || !ISVISIBLE(c)); c = c->next);
  1194 	return c;
  1194 	return c;
  1195 }
  1195 }
  1196 
  1196 
  1197 Monitor *
  1197 Monitor *
  1198 pointertomon(int x, int y) {
  1198 ptrtomon(int x, int y) {
  1199 	Monitor *m;
  1199 	Monitor *m;
  1200 
  1200 
  1201 	for(m = mons; m; m = m->next)
  1201 	for(m = mons; m; m = m->next)
  1202 		if(INRECT(x, y, m->wx, m->wy, m->ww, m->wh))
  1202 		if(INRECT(x, y, m->wx, m->wy, m->ww, m->wh))
  1203 			return m;
  1203 			return m;
  1300 	}
  1300 	}
  1301 	while(ev.type != ButtonRelease);
  1301 	while(ev.type != ButtonRelease);
  1302 	XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w + c->bw - 1, c->h + c->bw - 1);
  1302 	XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w + c->bw - 1, c->h + c->bw - 1);
  1303 	XUngrabPointer(dpy, CurrentTime);
  1303 	XUngrabPointer(dpy, CurrentTime);
  1304 	while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
  1304 	while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
  1305 	if((m = pointertomon(c->x + c->w / 2, c->y + c->h / 2)) != selmon) {
  1305 	if((m = ptrtomon(c->x + c->w / 2, c->y + c->h / 2)) != selmon) {
  1306 		sendmon(c, m);
  1306 		sendmon(c, m);
  1307 		selmon = m;
  1307 		selmon = m;
  1308 		focus(NULL);
  1308 		focus(NULL);
  1309 	}
  1309 	}
  1310 }
  1310 }
  1327 			if(!c->isfloating && ISVISIBLE(c)) {
  1327 			if(!c->isfloating && ISVISIBLE(c)) {
  1328 				XConfigureWindow(dpy, c->win, CWSibling|CWStackMode, &wc);
  1328 				XConfigureWindow(dpy, c->win, CWSibling|CWStackMode, &wc);
  1329 				wc.sibling = c->win;
  1329 				wc.sibling = c->win;
  1330 			}
  1330 			}
  1331 	}
  1331 	}
       
  1332 	XLowerWindow(dpy, m->barwin);
  1332 	XSync(dpy, False);
  1333 	XSync(dpy, False);
  1333 	while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
  1334 	while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
  1334 }
  1335 }
  1335 
  1336 
  1336 void
  1337 void
  1337 run(void) {
  1338 run(void) {
  1338 	XEvent ev;
  1339 	XEvent ev;
  1339 
  1340 
  1340 	/* main event loop */
  1341 	/* main event loop */
  1341 	XSync(dpy, False);
  1342 	XSync(dpy, False);
  1342 	while(running && !XNextEvent(dpy, &ev)) {
  1343 	while(running && !XNextEvent(dpy, &ev))
  1343 		if(handler[ev.type])
  1344 		if(handler[ev.type])
  1344 			(handler[ev.type])(&ev); /* call handler */
  1345 			(handler[ev.type])(&ev); /* call handler */
  1345 	}
       
  1346 }
  1346 }
  1347 
  1347 
  1348 void
  1348 void
  1349 scan(void) {
  1349 scan(void) {
  1350 	unsigned int i, num;
  1350 	unsigned int i, num;
  1868 wintomon(Window w) {
  1868 wintomon(Window w) {
  1869 	int x, y;
  1869 	int x, y;
  1870 	Client *c;
  1870 	Client *c;
  1871 	Monitor *m;
  1871 	Monitor *m;
  1872 
  1872 
  1873 	if(w == root && getrootpointer(&x, &y))
  1873 	if(w == root && getrootptr(&x, &y))
  1874 		return pointertomon(x, y);
  1874 		return ptrtomon(x, y);
  1875 	for(m = mons; m; m = m->next)
  1875 	for(m = mons; m; m = m->next)
  1876 		if(w == m->barwin)
  1876 		if(w == m->barwin)
  1877 			return m;
  1877 			return m;
  1878 	if((c = wintoclient(w)))
  1878 	if((c = wintoclient(w)))
  1879 		return c->mon;
  1879 		return c->mon;