tAllow moving windows to absolute coordinates - wmutils - X windows manipulation utilities
 (HTM) git clone git://z3bra.org/wmutils
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit d783d9366432fe6aa720d61aab66a099b90a2f47
 (DIR) parent b715c5e6a880562520dc818d24bc784ded8f77e4
 (HTM) Author: z3bra <willy@mailoo.org>
       Date:   Wed, 10 Jun 2015 22:15:53 +0200
       
       Allow moving windows to absolute coordinates
       
       Diffstat:
         M man/wmv.1                           |      11 ++++++++++-
         M wmv.c                               |      36 +++++++++++++++++++++-----------
       
       2 files changed, 34 insertions(+), 13 deletions(-)
       ---
 (DIR) diff --git a/man/wmv.1 b/man/wmv.1
       t@@ -4,9 +4,10 @@
        .Os wmutils
        .Sh NAME
        .Nm wmv
       -.Nd move windows (relatively)
       +.Nd move windows
        .Sh SYNOPSIS
        .Nm wmv
       +.Op Fl a
        .Ar x y wid
        .Sh DESCRIPTION
        .Nm wmv
       t@@ -25,6 +26,14 @@ pixels in the
        y
        .EN
        direction.
       +.Bl -tag -width Ds
       +.It Fl a
       +Absolute mode. The window will be centered to the 
       +.Ar x
       +and
       +.Ar y
       +coordinates.
       +.El
        .Sh ENVIRONMENT
        .Nm
        acts on the X display specified by the
 (DIR) diff --git a/wmv.c b/wmv.c
       t@@ -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 move(xcb_window_t, int, int);
       +static void move(xcb_window_t, int, int, int);
        
        static void
        usage(char *name)
        {
       -        fprintf(stderr, "usage: %s <x> <y> <win>", name);
       +        fprintf(stderr, "usage: %s [-a] <x> <y> <win>", name);
                exit(1);
        }
        
        static void
       -move(xcb_window_t win, int x, int y)
       +move(xcb_window_t win, int mode, int x, int y)
        {
                uint32_t values[2];
                int real;
       t@@ -34,6 +39,10 @@ move(xcb_window_t win, int x, int y)
                if (!geom)
                        return;
        
       +        if (mode == ABSOLUTE) {
       +                x -= geom->x + geom->width /2;
       +                y -= geom->y + geom->height/2;
       +        }
                values[0] = x ? geom->x + x : geom->x;
                values[1] = y ? geom->y + y : geom->y;
        
       t@@ -64,21 +73,24 @@ move(xcb_window_t win, int x, int y)
        int
        main(int argc, char **argv)
        {
       -        xcb_window_t win;
       -
       -        if (argc != 4)
       +        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++;
       +        }
        
       -        scr = xcb_setup_roots_iterator(xcb_get_setup(conn)).data;
       -        win = scr->root;
       +        x = atoi(*(++argv));
       +        y = atoi(*(++argv));
        
       -        win = strtoul(argv[3], NULL, 16);
       -        if (!win)
       -                errx(1, "invalid win");
       +        while (*argv)
       +                move(strtoul(*argv++, NULL, 16), mode, x, y);
        
       -        move(win, atoi(argv[1]), atoi(argv[2]));
                xcb_flush(conn);
        
                kill_xcb(&conn);