twmp can now return the pointer position - wmutils - X windows manipulation utilities
(HTM) git clone git://z3bra.org/wmutils
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
(DIR) LICENSE
---
(DIR) commit eef39204878016fdcc0959132e8c3627e45eaf14
(DIR) parent f78d3e0b7c3151aabb086bf31392604e9ab662a1
(HTM) Author: z3bra <willy@mailoo.org>
Date: Fri, 23 Jan 2015 20:09:33 +0100
wmp can now return the pointer position
Diffstat:
M man/wmp.1 | 15 ++++++++++++---
M wmp.c | 41 ++++++++++++++++++++++++++-----
2 files changed, 47 insertions(+), 9 deletions(-)
---
(DIR) diff --git a/man/wmp.1 b/man/wmp.1
t@@ -6,14 +6,17 @@
.Nd warp mouse cursor
.Sh SYNOPSIS
.Nm wmp
-.Fl ar
-.Ar <x> <y>
+.Fl [ ar
+.Ar <x> <y> ]
+.Ar [ wid ]
.Sh DESCRIPTION
.Nm
warps cursor to an absolute or relative position, passed by
.Ar x
and
-.Ar y ,
+.Ar y .
+Returns the position relative to the root window, or
+.Ar wid .
.Sh ENVIRONMENT
.Nm
acts on the X display specified by the
t@@ -24,3 +27,9 @@ variable.
.Dl $ wmp a $(wattr xy `pfw`)
.Pp
.Dl $ wmp r -100 0
+.Pp
+.Dl $ wmp 0x01600006
+.Dl 311 49
+.Pp
+.Dl $ wmp
+.Dl 915 548
(DIR) diff --git a/wmp.c b/wmp.c
t@@ -13,20 +13,40 @@ enum {
RELATIVE = 1
};
-static xcb_connection_t *conn;
static xcb_screen_t *scr;
+static xcb_connection_t *conn;
static void usage(char *);
+static void spot_cursor(int, uint32_t);
static void warp_cursor(int, int, int);
static void
usage(char *name)
{
- fprintf(stderr, "usage: %s -ar <x> <y>\n", name);
+ fprintf(stderr, "usage: %s [-ar <x> <y>] [wid]\n", name);
exit(1);
}
static void
+spot_cursor(int mode, uint32_t win)
+{
+ xcb_query_pointer_reply_t *r;
+ xcb_query_pointer_cookie_t c;
+
+ c = xcb_query_pointer(conn, win);
+ r = xcb_query_pointer_reply(conn, c, NULL);
+
+ if (r == NULL)
+ errx(1, "cannot retrieve pointer position");
+
+ if (r->child != XCB_NONE) {
+ printf("%d %d\n", r->win_x, r->win_y);
+ } else {
+ printf("%d %d\n", r->root_x, r->root_y);
+ }
+}
+
+static void
warp_cursor(int x, int y, int mode)
{
xcb_warp_pointer(conn, XCB_NONE, mode ? XCB_NONE : scr->root,
t@@ -38,9 +58,7 @@ main(int argc, char **argv)
{
char *argv0;
int mode = ABSOLUTE;
-
- if (argc != 4)
- usage(argv[0]);
+ uint32_t win;
ARGBEGIN {
case 'a': mode = ABSOLUTE;
t@@ -53,7 +71,18 @@ main(int argc, char **argv)
init_xcb(&conn);
get_screen(conn, &scr);
- warp_cursor(atoi(argv[0]), atoi(argv[1]), mode);
+ switch (argc) {
+ case 0:
+ case 1:
+ win = argc > 0 ? strtoul(*argv, NULL, 16) : scr->root;
+ spot_cursor(mode, win);
+ break;
+ case 2:
+ warp_cursor(atoi(argv[0]), atoi(argv[1]), mode);
+ break;
+ default:
+ usage(argv0);
+ }
xcb_flush(conn);