diff options
author | okan | 2013-01-02 16:26:34 +0000 |
---|---|---|
committer | okan | 2013-01-02 16:26:34 +0000 |
commit | 0907a6cfbcbe286154c23e20ab13a1599851c144 (patch) | |
tree | f141b7dee22ee3b2d9c63fe9ffb2f9c753f0cd5c | |
parent | bc9a040b94798d093048c2152dd03804c41e6268 (diff) | |
download | cwm-0907a6cfbcbe286154c23e20ab13a1599851c144.tar.gz |
have screen_find_xinerama() return struct geom *reliably* instead of
XineramaScreenInfo; simplifies goop around the callers.
-rw-r--r-- | calmwm.h | 4 | ||||
-rw-r--r-- | client.c | 92 | ||||
-rw-r--r-- | menu.c | 37 | ||||
-rw-r--r-- | screen.c | 20 |
4 files changed, 56 insertions, 97 deletions
@@ -15,7 +15,7 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * - * $OpenBSD: calmwm.h,v 1.181 2013/01/01 14:33:52 okan Exp $ + * $OpenBSD: calmwm.h,v 1.182 2013/01/02 16:26:34 okan Exp $ */ #ifndef _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 *); @@ -15,7 +15,7 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * - * $OpenBSD: client.c,v 1.111 2013/01/02 02:19:20 okan Exp $ + * $OpenBSD: client.c,v 1.112 2013/01/02 16:26:34 okan Exp $ */ #include <sys/param.h> @@ -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; } } } @@ -16,7 +16,7 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * - * $OpenBSD: menu.c,v 1.49 2013/01/02 02:19:20 okan Exp $ + * $OpenBSD: menu.c,v 1.50 2013/01/02 16:26:34 okan Exp $ */ #include <sys/param.h> @@ -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), @@ -15,7 +15,7 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * - * $OpenBSD: screen.c,v 1.40 2012/12/18 18:39:55 okan Exp $ + * $OpenBSD: screen.c,v 1.41 2013/01/02 16:26:34 okan Exp $ */ #include <sys/param.h> @@ -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 |