tnew tool: wtf - wmutils - X windows manipulation utilities
 (HTM) git clone git://z3bra.org/wmutils
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit 5b3c19ed7506ec1a6ac8637314d34840d111d8f5
 (DIR) parent 7f854033f612a174a889c81384ca8730f1df717e
 (HTM) Author: dcat <dcat@iotek.org>
       Date:   Fri, 28 Nov 2014 02:49:02 +0100
       
       new tool: wtf
       
       Diffstat:
         M Makefile                            |       3 ++-
         A wtf.c                               |      80 +++++++++++++++++++++++++++++++
       
       2 files changed, 82 insertions(+), 1 deletion(-)
       ---
 (DIR) diff --git a/Makefile b/Makefile
       t@@ -15,7 +15,8 @@ SRC =           \
                wattr.c \
                wtp.c   \
                wmv.c   \
       -        chwso.c
       +        chwso.c \
       +        wtf.c
        
        OBJ = $(SRC:.c=.o)
        BIN = $(SRC:.c=)
 (DIR) diff --git a/wtf.c b/wtf.c
       t@@ -0,0 +1,80 @@
       +/**
       +*      Copyright (c) 2014, Broseph <dcat (at) iotek (dot) org>
       +*
       +*      Permission to use, copy, modify, and/or distribute this software for any
       +*      purpose with or without fee is hereby granted, provided that the above
       +*      copyright notice and this permission notice appear in all copies.
       +*
       +*      THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
       +*      WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
       +*      MERCHANTABILITY AND FITNESS IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
       +*      ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
       +*      WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
       +*      ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
       +*      OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
       +**/
       +
       +#include <xcb/xcb.h>
       +#include <stdlib.h>
       +#include <stdio.h>
       +#include <err.h>
       +
       +static xcb_connection_t   *conn;
       +
       +static void cleanup        (void);
       +static void usage          (char *name);
       +static void center_pointer (xcb_window_t);
       +
       +static void
       +cleanup (void)
       +{
       +        if (conn)
       +                xcb_disconnect(conn);
       +}
       +
       +static void
       +usage (char *name)
       +{
       +        fprintf(stderr, "usage: %s <wid>\n", name);
       +        exit(1);
       +}
       +
       +static void
       +center_pointer (xcb_window_t win)
       +{
       +        xcb_get_geometry_reply_t *geom;
       +        geom = xcb_get_geometry_reply(conn, xcb_get_geometry(conn, win), NULL);
       +
       +        if (!geom)
       +                errx(1, "center_pointer: missing geometry!");
       +
       +        xcb_warp_pointer(conn, XCB_NONE, win, 0, 0, 0, 0,
       +                        (geom->width  + (geom->border_width * 2)) / 2,
       +                        (geom->height + (geom->border_width * 2)) / 2);
       +
       +        xcb_set_input_focus(conn, XCB_INPUT_FOCUS_POINTER_ROOT, win,
       +                        XCB_CURRENT_TIME);
       +}
       +
       +
       +int
       +main (int argc, char **argv)
       +{
       +        atexit(cleanup);
       +        xcb_window_t win;
       +
       +        if (argc != 2)
       +                usage(argv[0]);
       +
       +        if (xcb_connection_has_error(conn = xcb_connect(NULL, NULL)))
       +                errx(1, "error connecting to X");
       +
       +        win = strtoul(argv[1], NULL, 16);
       +        if (!win)
       +                errx(1, "could not get focused window");
       +
       +        center_pointer(win);
       +        xcb_flush(conn);
       +
       +        return 0;
       +}