[hackers] [dwm] some cleanup handling for index based mon search || Anselm R Garbe

From: <hg_AT_suckless.org>
Date: Sat, 27 Jun 2009 17:50:55 +0000 (UTC)

changeset: 1427:f8ea02f86861
tag: tip
user: Anselm R Garbe <anselm_AT_garbe.us>
date: Sat Jun 27 18:50:50 2009 +0100
files: dwm.c
description:
some cleanup handling for index based mon search

diff -r f8ee1d055e66 -r f8ea02f86861 dwm.c
--- a/dwm.c Sat Jun 27 18:42:10 2009 +0100
+++ b/dwm.c Sat Jun 27 18:50:50 2009 +0100
@@ -177,6 +177,7 @@
 static Client *getclient(Window w);
 static unsigned long getcolor(const char *colstr);
 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);
@@ -800,18 +801,13 @@
 #ifdef XINERAMA
 void
 focusmon(const Arg *arg) {
- unsigned int i;
- Monitor *m;
+ 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;
- }
+ if(!(m = getmonn(arg->ui)) || m == selmon)
+ return;
+ unfocus(selmon->sel);
+ selmon = m;
+ focus(NULL);
 }
 #endif /* XINERAMA */
 
@@ -877,6 +873,15 @@
         if((c = getclient(w)))
                 return c->mon;
         return NULL;
+}
+
+Monitor *
+getmonn(unsigned int n) {
+ unsigned int i;
+ Monitor *m;
+
+ for(m = mons, i = 0; m && i != n; m = m->next, i++);
+ return m;
 }
 
 Monitor *
@@ -1542,17 +1547,11 @@
 #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 */
 
Received on Sat Jun 27 2009 - 17:50:55 UTC

This archive was generated by hypermail 2.2.0 : Sat Jun 27 2009 - 18:00:05 UTC