wmutils

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

commit b715c5e6a880562520dc818d24bc784ded8f77e4
parent 43cfe64796c8df2648071aa15983e0ff8b998858
Author: z3bra <willy@mailoo.org>
Date:   Wed Jun 10 21:28:45 2015

Allow resizing windows via absolute coordinates

Diffstat:
 man/wrs.1 | 11 ++++++++++-
 wrs.c     | 25 ++++++++++++++++++++-----
 2 files changed, 30 insertions(+), 6 deletions(-)

diff --git a/man/wrs.1 b/man/wrs.1 @@ -3,9 +3,10 @@ .Os wmutils .Sh NAME .Nm wrs -.Nd resize windows (relatively) +.Nd resize windows .Sh SYNOPSIS .Nm wrs +.Op Fl a .Ar x y wid Op ... .Sh DESCRIPTION .Nm @@ -15,6 +16,14 @@ based on the relative pixel values .Ar x and .Ar y . +.Bl -tag -width Ds +.It Fl a +Absolute mode. The window will be resized up to the +.Ar x +and +.Ar y +coordinates. +.El .Sh ENVIRONMENT .Nm acts on the X display specified by the diff --git a/wrs.c b/wrs.c @@ -7,21 +7,26 @@ #include "util.h" +enum { + ABSOLUTE = 0, + RELATIVE = 1 +}; + static xcb_connection_t *conn; static xcb_screen_t *scr; static void usage(char *); -static void resize(xcb_window_t, int, int); +static void resize(xcb_window_t, int, int, int); static void usage(char *name) { - fprintf(stderr, "usage: %s <x> <y> <wid> [wid..]", name); + fprintf(stderr, "usage: %s [-a] <x> <y> <wid> [wid..]", name); exit(1); } static void -resize(xcb_window_t w, int x, int y) +resize(xcb_window_t w, int mode, int x, int y) { uint32_t val[3]; uint32_t mask = XCB_CONFIG_WINDOW_WIDTH @@ -36,6 +41,11 @@ resize(xcb_window_t w, int x, int y) if (r == NULL) return; + if (mode == ABSOLUTE) { + x -= r->x + r->width; + y -= r->y + r->height; + } + if ((r->x + r->width + 2*r->border_width + x) > scr->width_in_pixels) x = scr->width_in_pixels - ( r->x + r->width + (2*r->border_width)); @@ -56,18 +66,23 @@ resize(xcb_window_t w, int x, int y) int main(int argc, char **argv) { - int x, y; + int x, y, mode = RELATIVE; if (argc < 4) usage(argv[0]); init_xcb(&conn); get_screen(conn, &scr); + if (argv[1][0] == '-' && argv[1][1] == 'a') { + mode = ABSOLUTE; + argv++; + } + x = atoi(*(++argv)); y = atoi(*(++argv)); while (*argv) - resize(strtoul(*argv++, NULL, 16), x, y); + resize(strtoul(*argv++, NULL, 16), mode, x, y); xcb_flush(conn);