diff --git a/Makefile b/Makefile index 05a1031..9322d03 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,8 @@ CFLAGS = -Wall LDLIBS = -lX11 -all: xss xsswin +all: xss xsswin xcursorpos xss: LDLIBS += -lXss + +.PHONY: all diff --git a/README b/README index 046072f..49fa395 100644 --- a/README +++ b/README @@ -7,6 +7,7 @@ xsswin makes a full-screen black window and runs some other program, passing along the window ID in the environment ($XSS_WINDOW) and possibly as an argument (XSS_WINDOW gets replaced with the id). +xcursorpos prints out the x and y coordinates of the cursor. Examples -------- @@ -26,9 +27,12 @@ Run like xscreensaver (no locking): xss xsswin /usr/lib/xscreensaver/flurry -window-id XSS_WINDOW -Shell script to run an xscreensaver hack and xtrlock at the same time: +Shell script to run an xscreensaver hack and xtrlock at the same time, +but prevent locking if the cursor is in the upper-left corner: #! /bin/sh + + xcursorpos | (read x y; [ $x -lt 20 -a $y -lt 20 ]) && exit 0 xsswin /usr/lib/xscreensaver/qix -window-id XSS_WINDOW & pid=$! xtrlock diff --git a/xcursorpos.c b/xcursorpos.c new file mode 100644 index 0000000..2f79a16 --- /dev/null +++ b/xcursorpos.c @@ -0,0 +1,55 @@ +/* xcursorpos -- print current cursor coordinates + * Copyright (C) 2008 Neale Pickett + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include +#include +#include "obj.h" + +int +main(int argc, char *argv[]) +{ + Display *display = NULL; + + if (argc != 1) { + fprintf(stderr, "Usage: %s\n", argv[0]); + return 64; /* EX_USAGE */ + } + + try { + Window root, win; + int x, y, win_x, win_y; + unsigned int mask; + + if (! (display = XOpenDisplay(NULL))) raise("cannot open display"); + root = DefaultRootWindow(display); + if (! XQueryPointer(display, root, &root, &win, &x, &y, &win_x, &win_y, &mask)) { + raise("unable to query pointer"); + } + printf("%d %d\n", x, y); + } while (0); + + if (display) { + (void)XCloseDisplay(display); + } + + except { + fprintf(stderr, "Error: %s\n", exception); + return 69; /* EX_UNAVAILABLE */ + } + + return 0; +}