From 8f040ed7a413cc9bd3a2f8b708ffda34027c1092 Mon Sep 17 00:00:00 2001 From: Martin Duquesnoy Date: Thu, 4 Aug 2011 09:53:58 +0200 Subject: [PATCH] Wmfs: Add INAREA macro to replace ugly ifs --- src/client.c | 3 +-- src/event.c | 6 ++---- src/screen.c | 11 ++++------- src/wmfs.h | 1 + wmfsrc | 2 +- 5 files changed, 9 insertions(+), 14 deletions(-) diff --git a/src/client.c b/src/client.c index be4847f..161f22d 100644 --- a/src/client.c +++ b/src/client.c @@ -424,8 +424,7 @@ client_urgent(Client *c, bool u) SLIST_FOREACH(cc, &clients, next) if(cc != c && cc->screen == c->screen && cc->tag == c->tag && (cc->flags & TileFlag)) - if(cc->frame_geo.x < x && cc->frame_geo.x + cc->frame_geo.width > x - && cc->frame_geo.y < y && cc->frame_geo.y + cc->frame_geo.height > y) + if(INAREA(x, y, cc->frame_geo)) return cc; return c; diff --git a/src/event.c b/src/event.c index b9ed1ab..4c98e6b 100644 --- a/src/event.c +++ b/src/event.c @@ -114,8 +114,7 @@ buttonpress(XEvent *e) if(conf.selbar.mouse[i].tag == seltag[conf.selbar.mouse[i].screen] || conf.selbar.mouse[i].tag < 0) if(ev->button == conf.selbar.mouse[i].button) - if(ev->x >= ib->selbar_geo.x && ev->x <= ib->selbar_geo.x + ib->selbar_geo.width - && ev->y >= ib->selbar_geo.y && ev->y <= ib->selbar_geo.y + ib->selbar_geo.height) + if(INAREA(ev->x, ev->y, ib->selbar_geo)) if(conf.selbar.mouse[i].func) conf.selbar.mouse[i].func(conf.selbar.mouse[i].cmd); @@ -167,8 +166,7 @@ buttonpress(XEvent *e) /* Status mouse bindings */ SLIST_FOREACH(sm, &smhead, next) if(sm->infobar->bar->win == ev->window && ev->button == sm->button) - if(ev->x >= sm->area.x && ev->x <= sm->area.x + sm->area.width - && ev->y >= sm->area.y && ev->y <= sm->area.y + sm->area.height) + if(INAREA(ev->x, ev->y, sm->area)) if(sm->func) sm->func(sm->cmd); diff --git a/src/screen.c b/src/screen.c index c3e7c53..67757af 100644 --- a/src/screen.c +++ b/src/screen.c @@ -38,9 +38,7 @@ int screen_count(void) { - int n = 0; - - n = ScreenCount(dpy); + int n = ScreenCount(dpy); #ifdef HAVE_XINERAMA if(XineramaIsActive(dpy)) @@ -106,11 +104,10 @@ screen_get_geo(int s) int screen_get_with_geo(int x, int y) { - int i; + int i = 0; - for(i = 0; i < screen_count(); ++i) - if((x >= spgeo[i].x && x < spgeo[i].x + spgeo[i].width) - && y >= spgeo[i].y && y < spgeo[i].y + spgeo[i].height) + for(; i < screen_count(); ++i) + if(INAREA(x, y, spgeo[i])) return i; return 0; diff --git a/src/wmfs.h b/src/wmfs.h index a27da4d..72854bc 100644 --- a/src/wmfs.h +++ b/src/wmfs.h @@ -119,6 +119,7 @@ #define RPOS(x) (x & 1 ? x - 1 : x + 1) #define LDIR(x) (x < Top) #define FLAGAPPLY(v, b, f) ((b) ? (v |= (f)) : (v &= ~(f))) +#define INAREA(i, j, a) ((i) >= (a).x && (i) <= (a).x + (a).width && (j) >= (a).y && (j) <= (a).y + (a).height) /* Cfactor define */ #define CFACTOR_CHECK2(g1, g2, p) (LDIR(p) ? (g1.height == g2.height) : (g1.width == g2.width)) diff --git a/wmfsrc b/wmfsrc index 97f224f..3534a52 100644 --- a/wmfsrc +++ b/wmfsrc @@ -11,7 +11,7 @@ font = "dejavu-10" raisefocus = true focus_follow_mouse = true - focus_follow_movement = false + focus_follow_movement = true opacity = 255 # focus_pointer_click: click on unfocused client area: