X-Git-Url: https://jasonwoof.com/gitweb/?p=dwm.git;a=blobdiff_plain;f=dwm.c;h=04fcc907cdeacfbbb6184cf3cc6eb08e77118344;hp=9779654881e815bc7493d9f70b79f3755e22d18e;hb=029655bb2271a18d3a191f22502cbd9b713a9189;hpb=176408afa895adf133a437038466ddc74e326a0c diff --git a/dwm.c b/dwm.c index 9779654..04fcc90 100644 --- a/dwm.c +++ b/dwm.c @@ -176,8 +176,9 @@ static void focusin(XEvent *e); static void focusstack(const Arg *arg); static Client *getclient(Window w); static unsigned long getcolor(const char *colstr); -static Monitor *getmonitor(Window w); -static Monitor *getmonitorxy(int x, int y); +static Monitor *getmon(Window w); +static Monitor *getmonn(unsigned int n); +static Monitor *getmonxy(int x, int y); static Bool getrootpointer(int *x, int *y); static long getstate(Window w); static Bool gettextprop(Window w, Atom atom, char *text, unsigned int size); @@ -401,7 +402,7 @@ buttonpress(XEvent *e) { click = ClkRootWin; /* focus monitor if necessary */ - if((m = getmonitor(ev->window)) && m != selmon) { + if((m = getmon(ev->window)) && m != selmon) { unfocus(selmon->sel); selmon = m; focus(NULL); @@ -747,7 +748,7 @@ enternotify(XEvent *e) { if((ev->mode != NotifyNormal || ev->detail == NotifyInferior) && ev->window != root) return; - if((m = getmonitor(ev->window)) && m != selmon) { + if((m = getmon(ev->window)) && m != selmon) { unfocus(selmon->sel); selmon = m; } @@ -762,7 +763,7 @@ expose(XEvent *e) { Monitor *m; XExposeEvent *ev = &e->xexpose; - if(ev->count == 0 && (m = getmonitor(ev->window))) + if(ev->count == 0 && (m = getmon(ev->window))) drawbar(m); } @@ -800,18 +801,13 @@ focusin(XEvent *e) { /* there are some broken focus acquiring clients */ #ifdef XINERAMA void focusmon(const Arg *arg) { - unsigned int i; - Monitor *m; - - for(i = 0, m = mons; m; m = m->next, i++) - if(i == arg->ui) { - if(m == selmon) - return; - unfocus(selmon->sel); - selmon = m; - focus(NULL); - break; - } + Monitor *m; + + if(!(m = getmonn(arg->ui)) || m == selmon) + return; + unfocus(selmon->sel); + selmon = m; + focus(NULL); } #endif /* XINERAMA */ @@ -864,13 +860,13 @@ getcolor(const char *colstr) { } Monitor * -getmonitor(Window w) { +getmon(Window w) { int x, y; Client *c; Monitor *m; if(w == root && getrootpointer(&x, &y)) - return getmonitorxy(x, y); + return getmonxy(x, y); for(m = mons; m; m = m->next) if(w == m->barwin) return m; @@ -880,7 +876,16 @@ getmonitor(Window w) { } Monitor * -getmonitorxy(int x, int y) { +getmonn(unsigned int n) { + unsigned int i; + Monitor *m; + + for(m = mons, i = 0; m && i != n; m = m->next, i++); + return m; +} + +Monitor * +getmonxy(int x, int y) { Monitor *m; for(m = mons; m; m = m->next) @@ -1205,7 +1210,7 @@ movemouse(const Arg *arg) { } while(ev.type != ButtonRelease); XUngrabPointer(dpy, CurrentTime); - if((m = getmonitorxy(c->x + c->w / 2, c->y + c->h / 2)) != selmon) + if((m = getmonxy(c->x + c->w / 2, c->y + c->h / 2)) != selmon) sendmon(c, m); } @@ -1314,7 +1319,7 @@ resizemouse(const Arg *arg) { XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w + c->bw - 1, c->h + c->bw - 1); XUngrabPointer(dpy, CurrentTime); while(XCheckMaskEvent(dpy, EnterWindowMask, &ev)); - if((m = getmonitorxy(c->x + c->w / 2, c->y + c->h / 2)) != selmon) + if((m = getmonxy(c->x + c->w / 2, c->y + c->h / 2)) != selmon) sendmon(c, m); } @@ -1542,17 +1547,11 @@ tag(const Arg *arg) { #ifdef XINERAMA void tagmon(const Arg *arg) { - unsigned int i; - Client *c; Monitor *m; - if(!(c = selmon->sel)) + if(!selmon->sel || !(m = getmonn(arg->ui))) return; - for(i = 0, m = mons; m; m = m->next, i++) - if(i == arg->ui) { - sendmon(c, m); - break; - } + sendmon(selmon->sel, m); } #endif /* XINERAMA */ @@ -1809,7 +1808,7 @@ updategeom(void) { /* select focused monitor */ cleanupmons(); mons = newmons; - selmon = getmonitor(root); + selmon = getmon(root); } void