wmutils

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

commit e62fde54308511ff5e2b5a715fd691d071b0545a
parent c420551c1091fb6edda67493ea22925050a792ea
Author: dcat <dcat@iotek.org>
Date:   Thu Dec 18 17:06:04 2014

new tool: wmp

Diffstat:
 Makefile     |  3 ++-
 man/Makefile |  3 ++-
 man/wmp.1    | 25 +++++++++++++++++++++++++
 wmp.c        | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 88 insertions(+), 2 deletions(-)

diff --git a/Makefile b/Makefile @@ -14,7 +14,8 @@ SRC = \ wrs.c \ chwb.c \ ignw.c \ - wname.c + wname.c \ + wmp.c OBJ = $(SRC:.c=.o) BIN = $(SRC:.c=) diff --git a/man/Makefile b/man/Makefile @@ -13,7 +13,8 @@ SRC = \ wrs.1 \ chwb.1 \ ignw.1 \ - wname.1 + wname.1 \ + wmp.1 MAN = $(SRC:.1=.1.gz) diff --git a/man/wmp.1 b/man/wmp.1 @@ -0,0 +1,25 @@ +.Dd December 13, 2014 +.Dt WTP 1 +.Os wmutils +.Sh NAME +.Nm wmp +.Nd warp mouse cursor +.Sh SYNOPSIS +.Nm wmp +.Ar <a | r> <x> <y> +.Sh DESCRIPTION +.Nm +warps cursor to an absolute or relative position, passed by +.Ar x +and +.Ar y , +.Sh ENVIRONMENT +.Nm +acts on the X display specified by the +.Ev DISPLAY +variable. +.Sh EXAMPLES +.Pp +.Dl $ wmp a $(wattr xy `pfw`) +.Pp +.Dl $ wmp r -100 0 diff --git a/wmp.c b/wmp.c @@ -0,0 +1,59 @@ +/* See LICENSE file for copyright and license details. */ + +#include <xcb/xcb.h> +#include <stdlib.h> +#include <stdio.h> +#include <err.h> + +#include "util.h" + +enum { + ABSOLUTE = 0, + RELATIVE = 1 +}; + +static xcb_connection_t *conn; +static xcb_screen_t *scr; + +static void usage (char *); +static void warp_cursor (int, int, int); + +static void +usage (char *name) +{ + fprintf(stderr, "For more details see %s(1)\n", name); + exit(1); +} + +static void +warp_cursor (int x, int y, int mode) +{ + xcb_warp_pointer(conn, XCB_NONE, mode ? XCB_NONE : scr->root, + 0, 0, 0, 0, x, y); +} + +int +main (int argc, char **argv) +{ + int mode = ABSOLUTE; + + if (argc != 4) + usage(argv[0]); + + init_xcb(&conn); + get_screen(conn, &scr); + + switch (argv[1][0]) { + case 'a': mode = ABSOLUTE; + break; + case 'r': mode = RELATIVE; + break; + } + + warp_cursor(atoi(argv[2]), atoi(argv[3]), mode); + + xcb_flush(conn); + + kill_xcb(&conn); + return 0; +}