summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--calmwm.h2
-rw-r--r--client.c90
-rw-r--r--menu.c35
-rw-r--r--screen.c18
4 files changed, 52 insertions, 93 deletions
diff --git a/calmwm.h b/calmwm.h
index 9543341..7237e28 100644
--- a/calmwm.h
+++ b/calmwm.h
@@ -372,7 +372,7 @@ void			 search_match_text(struct menu_q *, struct menu_q *,
 			     char *);
 void			 search_print_client(struct menu *, int);
 
-XineramaScreenInfo	*screen_find_xinerama(struct screen_ctx *, int, int);
+struct geom		 screen_find_xinerama(struct screen_ctx *, int, int);
 struct screen_ctx	*screen_fromroot(Window);
 void			 screen_init(struct screen_ctx *, u_int);
 void			 screen_update_geometry(struct screen_ctx *);
diff --git a/client.c b/client.c
index fe35d94..c162dac 100644
--- a/client.c
+++ b/client.c
@@ -255,8 +255,7 @@ void
 client_maximize(struct client_ctx *cc)
 {
 	struct screen_ctx	*sc = cc->sc;
-	XineramaScreenInfo	*xine;
-	int			 x_org, y_org, xmax, ymax;
+	struct geom		 xine;
 
 	if (cc->flags & CLIENT_FREEZE)
 		return;
@@ -286,21 +285,11 @@ client_maximize(struct client_ctx *cc)
 	xine = screen_find_xinerama(sc,
 	    cc->geom.x + cc->geom.w / 2,
 	    cc->geom.y + cc->geom.h / 2);
-	if (xine) {
-		x_org = xine->x_org;
-		y_org = xine->y_org;
-		xmax = xine->width;
-		ymax = xine->height;
-	} else {
-		x_org = y_org = 0;
-		xmax = sc->view.w;
-		ymax = sc->view.h;
-	}
 
-	cc->geom.x = x_org + sc->gap.left;
-	cc->geom.y = y_org + sc->gap.top;
-	cc->geom.h = ymax - (sc->gap.top + sc->gap.bottom);
-	cc->geom.w = xmax - (sc->gap.left + sc->gap.right);
+	cc->geom.x = xine.x + sc->gap.left;
+	cc->geom.y = xine.y + sc->gap.top;
+	cc->geom.h = xine.h - (sc->gap.top + sc->gap.bottom);
+	cc->geom.w = xine.w - (sc->gap.left + sc->gap.right);
 	cc->bwidth = 0;
 	cc->flags |= CLIENT_MAXIMIZED;
 
@@ -312,8 +301,7 @@ void
 client_vertmaximize(struct client_ctx *cc)
 {
 	struct screen_ctx	*sc = cc->sc;
-	XineramaScreenInfo	*xine;
-	int			 y_org, ymax;
+	struct geom		 xine;
 
 	if (cc->flags & CLIENT_FREEZE)
 		return;
@@ -340,16 +328,9 @@ client_vertmaximize(struct client_ctx *cc)
 	xine = screen_find_xinerama(sc,
 	    cc->geom.x + cc->geom.w / 2,
 	    cc->geom.y + cc->geom.h / 2);
-	if (xine) {
-		y_org = xine->y_org;
-		ymax = xine->height;
-	} else {
-		y_org = 0;
-		ymax = sc->view.h;
-	}
 
-	cc->geom.y = y_org + sc->gap.top;
-	cc->geom.h = ymax - (cc->bwidth * 2) - (sc->gap.top +
+	cc->geom.y = xine.y + sc->gap.top;
+	cc->geom.h = xine.h - (cc->bwidth * 2) - (sc->gap.top +
 	    sc->gap.bottom);
 	cc->flags |= CLIENT_VMAXIMIZED;
 
@@ -361,8 +342,7 @@ void
 client_horizmaximize(struct client_ctx *cc)
 {
 	struct screen_ctx	*sc = cc->sc;
-	XineramaScreenInfo	*xine;
-	int			 x_org, xmax;
+	struct geom		 xine;
 
 	if (cc->flags & CLIENT_FREEZE)
 		return;
@@ -389,16 +369,9 @@ client_horizmaximize(struct client_ctx *cc)
 	xine = screen_find_xinerama(sc,
 	    cc->geom.x + cc->geom.w / 2,
 	    cc->geom.y + cc->geom.h / 2);
-	if (xine) {
-		x_org = xine->x_org;
-		xmax = xine->width;
-	} else {
-		x_org = 0;
-		xmax = sc->view.w;
-	}
 
-	cc->geom.x = x_org + sc->gap.left;
-	cc->geom.w = xmax - (cc->bwidth * 2) - (sc->gap.left +
+	cc->geom.x = xine.x + sc->gap.left;
+	cc->geom.w = xine.w - (cc->bwidth * 2) - (sc->gap.left +
 	    sc->gap.right);
 	cc->flags |= CLIENT_HMAXIMIZED;
 
@@ -682,48 +655,37 @@ client_placecalc(struct client_ctx *cc)
 		if (cc->size->y > 0)
 			cc->geom.y = MIN(cc->size->y, yslack);
 	} else {
-		XineramaScreenInfo	*xine;
-		int			 x_org, y_org, xmax, ymax;
+		struct geom		 xine;
 		int			 xmouse, ymouse;
 
 		xu_ptr_getpos(sc->rootwin, &xmouse, &ymouse);
 		xine = screen_find_xinerama(sc, xmouse, ymouse);
-		if (xine) {
-			x_org = xine->x_org;
-			y_org = xine->y_org;
-			xmax = xine->x_org + xine->width;
-			ymax = xine->y_org + xine->height;
-		} else {
-			x_org = y_org = 0;
-			xmax = sc->view.w;
-			ymax = sc->view.h;
-		}
-		xmouse = MAX(xmouse, x_org) - cc->geom.w / 2;
-		ymouse = MAX(ymouse, y_org) - cc->geom.h / 2;
+		xmouse = MAX(xmouse, xine.x) - cc->geom.w / 2;
+		ymouse = MAX(ymouse, xine.y) - cc->geom.h / 2;
 
-		xmouse = MAX(xmouse, x_org);
-		ymouse = MAX(ymouse, y_org);
+		xmouse = MAX(xmouse, xine.x);
+		ymouse = MAX(ymouse, xine.y);
 
-		xslack = xmax - cc->geom.w - cc->bwidth * 2;
-		yslack = ymax - cc->geom.h - cc->bwidth * 2;
+		xslack = xine.w - cc->geom.w - cc->bwidth * 2;
+		yslack = xine.h - cc->geom.h - cc->bwidth * 2;
 
-		if (xslack >= x_org) {
+		if (xslack >= xine.x) {
 			cc->geom.x = MAX(MIN(xmouse, xslack),
-			    x_org + sc->gap.left);
+			    xine.x + sc->gap.left);
 			if (cc->geom.x > (xslack - sc->gap.right))
 				cc->geom.x -= sc->gap.right;
 		} else {
-			cc->geom.x = x_org + sc->gap.left;
-			cc->geom.w = xmax - sc->gap.left;
+			cc->geom.x = xine.x + sc->gap.left;
+			cc->geom.w = xine.w - sc->gap.left;
 		}
-		if (yslack >= y_org) {
+		if (yslack >= xine.y) {
 			cc->geom.y = MAX(MIN(ymouse, yslack),
-			    y_org + sc->gap.top);
+			    xine.y + sc->gap.top);
 			if (cc->geom.y > (yslack - sc->gap.bottom))
 				cc->geom.y -= sc->gap.bottom;
 		} else {
-			cc->geom.y = y_org + sc->gap.top;
-			cc->geom.h = ymax - sc->gap.top;
+			cc->geom.y = xine.y + sc->gap.top;
+			cc->geom.h = xine.h - sc->gap.top;
 		}
 	}
 }
diff --git a/menu.c b/menu.c
index c5ceea9..f0d8f54 100644
--- a/menu.c
+++ b/menu.c
@@ -350,8 +350,7 @@ menu_draw(struct screen_ctx *sc, struct menu_ctx *mc, struct menu_q *menuq,
     struct menu_q *resultq)
 {
 	struct menu		*mi;
-	XineramaScreenInfo	*xine;
-	int			 x_org, y_org, xmax, ymax;
+	struct geom		 xine;
 	int			 n, xsave, ysave;
 
 	if (mc->list) {
@@ -395,32 +394,22 @@ menu_draw(struct screen_ctx *sc, struct menu_ctx *mc, struct menu_q *menuq,
 	}
 
 	xine = screen_find_xinerama(sc, mc->x, mc->y);
-	if (xine) {
-		x_org = xine->x_org;
-		y_org = xine->y_org;
-		xmax = xine->x_org + xine->width;
-		ymax = xine->y_org + xine->height;
-	} else {
-		x_org = y_org = 0;
-		xmax = sc->view.w;
-		ymax = sc->view.h;
-	}
 
 	xsave = mc->x;
 	ysave = mc->y;
 
 	/* Never hide the top, or left side, of the menu. */
-	if (mc->x + mc->width >= xmax)
-		mc->x = xmax - mc->width;
-	if (mc->x < x_org) {
-		mc->x = x_org;
-		mc->width = xmax - x_org;
+	if (mc->x + mc->width >= xine.w)
+		mc->x = xine.w - mc->width;
+	if (mc->x < xine.x) {
+		mc->x = xine.x;
+		mc->width = xine.w - xine.x;
 	}
-	if (mc->y + mc->height >= ymax)
-		mc->y = ymax - mc->height;
-	if (mc->y < y_org) {
-		mc->y = y_org;
-		mc->height = ymax - y_org;
+	if (mc->y + mc->height >= xine.h)
+		mc->y = xine.h - mc->height;
+	if (mc->y < xine.y) {
+		mc->y = xine.y;
+		mc->height = xine.h - xine.y;
 	}
 
 	if (mc->x != xsave || mc->y != ysave)
@@ -443,7 +432,7 @@ menu_draw(struct screen_ctx *sc, struct menu_ctx *mc, struct menu_q *menuq,
 		int y = n * font_height(sc) + font_ascent(sc) + 1;
 
 		/* Stop drawing when menu doesn't fit inside the screen. */
-		if (mc->y + y > ymax)
+		if (mc->y + y > xine.h)
 			break;
 
 		font_draw(sc, text, MIN(strlen(text), MENU_MAXENTRY),
diff --git a/screen.c b/screen.c
index 461d308..a8ed509 100644
--- a/screen.c
+++ b/screen.c
@@ -146,22 +146,30 @@ screen_init_xinerama(struct screen_ctx *sc)
 /*
  * Find which xinerama screen the coordinates (x,y) is on.
  */
-XineramaScreenInfo *
+struct geom
 screen_find_xinerama(struct screen_ctx *sc, int x, int y)
 {
 	XineramaScreenInfo	*info;
+	struct geom		 geom;
 	int			 i;
 
+	geom = sc->view;
+
 	if (sc->xinerama == NULL)
-		return (NULL);
+		return (geom);
 
 	for (i = 0; i < sc->xinerama_no; i++) {
 		info = &sc->xinerama[i];
 		if (x >= info->x_org && x < info->x_org + info->width &&
-		    y >= info->y_org && y < info->y_org + info->height)
-			return (info);
+		    y >= info->y_org && y < info->y_org + info->height) {
+			geom.x = info->x_org;
+			geom.y = info->y_org;
+			geom.w = info->width;
+			geom.h = info->height;
+			break;
+		}
 	}
-	return (NULL);
+	return (geom);
 }
 
 void