twrs: limit resize to screen size - wmutils - X windows manipulation utilities
(HTM) git clone git://z3bra.org/wmutils
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
(DIR) LICENSE
---
(DIR) commit ef360bdd5009e0dab8da2e6c7c4df47b50f18ff8
(DIR) parent 3eb29b06a2e57b17ad8f53784ab4e61cbb1d1498
(HTM) Author: z3bra <willy@mailoo.org>
Date: Mon, 1 Dec 2014 13:59:30 +0100
wrs: limit resize to screen size
Diffstat:
M wrs.c | 14 ++++++++++++++
1 file changed, 14 insertions(+), 0 deletions(-)
---
(DIR) diff --git a/wrs.c b/wrs.c
t@@ -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);
t@@ -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
t@@ -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;