twattr, wtp: properly take borders in consideration - wmutils - X windows manipulation utilities
(HTM) git clone git://z3bra.org/wmutils
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
(DIR) LICENSE
---
(DIR) commit 0ac45c44cc65f8f5a13bce19af368b07e9862ce1
(DIR) parent 24476a5a737c678bfdeae3ce97dbc1fac1af0797
(HTM) Author: z3bra <willy@mailoo.org>
Date: Mon, 1 Dec 2014 20:31:30 +0100
wattr, wtp: properly take borders in consideration
Diffstat:
M wattr.c | 8 ++++----
M wtp.c | 30 +++++++++++++++++-------------
2 files changed, 21 insertions(+), 17 deletions(-)
---
(DIR) diff --git a/wattr.c b/wattr.c
t@@ -72,10 +72,10 @@ getattribute(xcb_window_t w, int attr)
errx(1, "0x%08x: no such window", w);
switch (attr) {
- case ATTR_W: attr = r->width + 2 * r->border_width; break;
- case ATTR_H: attr = r->height + 2 * r->border_width; break;
- case ATTR_X: attr = r->x - r->border_width; break;
- case ATTR_Y: attr = r->y - r->border_width; break;
+ case ATTR_X: attr = r->x; break;
+ case ATTR_Y: attr = r->y; break;
+ case ATTR_W: attr = r->width; break;
+ case ATTR_H: attr = r->height; break;
case ATTR_B: attr = r->border_width; break;
}
(DIR) diff --git a/wtp.c b/wtp.c
t@@ -42,36 +42,40 @@ cleanup (void)
static int
get_border (xcb_window_t win)
{
+ unsigned int bw = 0;
xcb_get_geometry_reply_t *geom;
geom = xcb_get_geometry_reply(conn, xcb_get_geometry(conn, win), NULL);
if (!geom)
errx(1, "failed to get geometry");
- return geom->border_width;
+ bw = geom->border_width;
+
+ free(geom);
+ return bw;
}
static void
teleport (xcb_window_t win, int x, int y, int w, int h)
{
- uint32_t values[2];
- int mode;
+ int bw = 0;
+ uint32_t values[4];
+ uint32_t mask = XCB_CONFIG_WINDOW_X
+ | XCB_CONFIG_WINDOW_Y
+ | XCB_CONFIG_WINDOW_WIDTH
+ | XCB_CONFIG_WINDOW_HEIGHT;
- mode = get_border(win);
- if (mode < 0)
+ bw = get_border(win);
+
+ if (bw < 0)
return;
values[0] = x;
values[1] = y;
+ values[2] = w - (2*bw);
+ values[3] = h - (2*bw);
- xcb_configure_window(conn, win, XCB_CONFIG_WINDOW_X
- | XCB_CONFIG_WINDOW_Y, values);
-
- values[0] = mode ? w - mode - 1 : w;
- values[1] = mode ? h - mode - 1 : h;
-
- xcb_configure_window(conn, win, XCB_CONFIG_WINDOW_WIDTH
- | XCB_CONFIG_WINDOW_HEIGHT, values);
+ xcb_configure_window(conn, win, mask, values);
}
int