wmutils

X windows manipulation utilities
git clone git://z3bra.org/wmutils
Log | Files | Refs | LICENSE

commit ef360bdd5009e0dab8da2e6c7c4df47b50f18ff8
parent 3eb29b06a2e57b17ad8f53784ab4e61cbb1d1498
Author: z3bra <willy@mailoo.org>
Date:   Mon Dec  1 13:59:30 2014

wrs: limit resize to screen size

Diffstat:
 wrs.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+), 0 deletions(-)

diff --git a/wrs.c b/wrs.c @@ -19,6 +19,7 @@ #include <err.h> static xcb_connection_t *conn; +static xcb_screen_t *scrn; static void cleanup(void); static void resize(xcb_window_t, int, int); @@ -29,6 +30,11 @@ xcbinit(void) conn = xcb_connect(NULL, NULL); if (xcb_connection_has_error(conn)) errx(1, "unable to connect to the X server"); + + scrn = xcb_setup_roots_iterator(xcb_get_setup(conn)).data; + + if (scrn == NULL) + errx(1, "unable to retrieve screen informations"); } static void @@ -54,6 +60,14 @@ resize(xcb_window_t w, int x, int y) if (r == NULL) return; + if ((r->x + r->width + 2*r->border_width + x) > scrn->width_in_pixels) + x = scrn->width_in_pixels - ( + r->x + r->width + (2*r->border_width)); + + if ((r->y + r->height + 2*r->border_width + y) > scrn->height_in_pixels) + y = scrn->height_in_pixels - ( + r->y + r->height + (2*r->border_width)); + val[0] = r->width + x; val[1] = r->height + y; val[2] = XCB_STACK_MODE_ABOVE;