Minor cleanup

pull/24/head v1.8
Martin Tournoij 2 years ago
parent 398e540c44
commit a78c716475
No known key found for this signature in database

@ -1,2 +1 @@
github: arp242 github: arp242
patreon: arp242

@ -1,6 +1,6 @@
The MIT License (MIT) The MIT License (MIT)
Copyright © 2015-2017 Martin Tournoij Copyright © Martin Tournoij
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to of this software and associated documentation files (the "Software"), to

@ -1,9 +1,20 @@
CC?=cc CC ?= cc
CFLAGS?=-std=c99 -pedantic -Wall -Os PREFIX ?= /usr/local
PREFIX?=/usr/local NAME ?= find-cursor
CFLAGS += -std=c99 -pedantic -Wall -Wextra -Wpedantic -Os
LDFLAGS += -L/usr/lib -lX11 -lXext -lXfixes
.PHONY: all clean install uninstall
all: all:
${CC} ${CFLAGS} ${LDFLAGS} -o find-cursor find-cursor.c -lX11 -lXext -lXfixes ${CC} ${CFLAGS} ${LDFLAGS} -o ${NAME} *.c
clean:
rm -f ${NAME}
install: install:
install -Dm755 find-cursor $(DESTDIR)$(PREFIX)/bin/find-cursor install -Dm755 ${NAME} ${DESTDIR}${PREFIX}/bin/${NAME}
uninstall:
rm -f ${DESTDIR}${PREFIX}/bin/${NAME}

@ -1,5 +1,3 @@
[![This project is considered stable](https://img.shields.io/badge/Status-stable-green.svg)](https://arp242.net/status/stable)
Simple XLib program to highlight the cursor position. This is similar to the Simple XLib program to highlight the cursor position. This is similar to the
feature found in Windows XP (and possibly later?) feature found in Windows XP (and possibly later?)

@ -1,10 +1,10 @@
/* /*
* http://code.arp242.net/find-cursor * http://code.arp242.net/find-cursor
* Copyright © 2015-2020 Martin Tournoij <martin@arp242.net> * Copyright © Martin Tournoij <martin@arp242.net>
* See below for full copyright * See below for full copyright
*/ */
#define _XOPEN_SOURCE 500 #define _DEFAULT_SOURCE
#include <getopt.h> #include <getopt.h>
#include <stdint.h> #include <stdint.h>
@ -25,8 +25,7 @@ int parse_num(int ch, char *opt, char *name);
int pointer_screen(char *name, Display *display); int pointer_screen(char *name, Display *display);
void draw(char *name, Display *display, int screen, void draw(char *name, Display *display, int screen,
int size, int distance, int wait, int line_width, char *color_name, int size, int distance, int wait, int line_width, char *color_name,
int follow, int transparent, int grow, int outline, char *ocolor_name, int follow, int transparent, int grow, int outline, char *ocolor_name);
int repeat);
static struct option longopts[] = { static struct option longopts[] = {
{"help", no_argument, NULL, 'h'}, {"help", no_argument, NULL, 'h'},
@ -45,62 +44,64 @@ static struct option longopts[] = {
}; };
void usage(char *name) { void usage(char *name) {
printf("find-cursor highlights the cursor position by drawing circles around it.\n"); printf(""
printf("https://github.com/arp242/find-cursor\n"); "find-cursor highlights the cursor position by drawing circles around it.\n"
printf("\n"); "https://github.com/arp242/find-cursor\n"
printf("Flags:\n"); "\n"
printf(" -h, --help Show this help.\n"); "Flags:\n"
printf("\n"); " -h, --help Show this help.\n"
printf("Shape options:\n"); "\n"
printf(" -s, --size Maximum size the circle will grow to in pixels.\n"); "Shape options:\n"
printf(" -d, --distance Distance between the circles in pixels.\n"); " -s, --size Maximum size the circle will grow to in pixels.\n"
printf(" -l, --line-width Width of the lines in pixels.\n"); " -d, --distance Distance between the circles in pixels.\n"
printf(" -w, --wait Time to wait before drawing the next circle in\n"); " -l, --line-width Width of the lines in pixels.\n"
printf(" tenths of milliseconds.\n"); " -w, --wait Time to wait before drawing the next circle in\n"
printf(" -c, --color Color as X11 color name or RGB (e.g. #ff0000)\n"); " tenths of milliseconds.\n"
printf(" -g, --grow Grow the animation in size, rather than shrinking it.\n"); " -c, --color Color as X11 color name or RGB (e.g. #ff0000)\n"
printf("\n"); " -g, --grow Grow the animation in size, rather than shrinking it.\n"
printf("Extra options:\n"); "\n"
printf(" -f, --follow Follow the cursor position as the cursor is moving.\n"); "Extra options:\n"
printf(" -t, --transparent Make the window truly 'transparent'. This helps with\n"); " -f, --follow Follow the cursor position as the cursor is moving.\n"
printf(" some display issues when following the cursor position,\n"); " -t, --transparent Make the window truly 'transparent'. This helps with\n"
printf(" but it doesn't work well with all WMs, which is why\n"); " some display issues when following the cursor position,\n"
printf(" it's disabled by default.\n"); " but it doesn't work well with all WMs, which is why\n"
printf(" -o, --outline Width in pixels of outline; uses 2px if no value is given.\n"); " it's disabled by default.\n"
printf(" Helps visibility on all backgrounds.\n"); " -o, --outline Width in pixels of outline; uses 2px if no value is given.\n"
printf(" -O, --outline-color Color of outline; if omitted it will automatically use\n"); " Helps visibility on all backgrounds.\n"
printf(" the opposite color. No effect if -o isn't set.\n"); " -O, --outline-color Color of outline; if omitted it will automatically use\n"
printf(" -r, --repeat Number of times to repeat the animation; use 0 to repeat\n"); " the opposite color. No effect if -o isn't set.\n"
printf(" indefinitely.\n"); " -r, --repeat Number of times to repeat the animation; use 0 to repeat\n"
printf("\n"); " indefinitely.\n"
printf("Examples:\n"); "\n"
printf(" The defaults:\n"); "Examples:\n"
printf(" %s --size 320 --distance 40 --wait 400 --line-width 4 --color black\n\n", name); " The defaults:\n"
printf(" Draw a solid circle:\n"); " %s --size 320 --distance 40 --wait 400 --line-width 4 --color black\n\n"
printf(" %s --size 100 --distance 1 --wait 20 --line-width 1\n\n", name); " Draw a solid circle:\n"
printf(" Always draw a full circle on top of the cursor:\n"); " %s --size 100 --distance 1 --wait 20 --line-width 1\n\n"
printf(" %s --repeat 0 --follow --distance 1 --wait 1 --line-width 16 --size 16\n", name); " Always draw a full circle on top of the cursor:\n"
printf("\n"); " %s --repeat 0 --follow --distance 1 --wait 1 --line-width 16 --size 16\n"
printf("Launching:\n"); "\n"
printf(" You will want to map a key in your window manager to run find-cursor.\n"); "Launching:\n"
printf(" You can also use xbindkeys, which should work with any window manager.\n"); " You will want to map a key in your window manager to run find-cursor.\n"
printf("\n"); " You can also use xbindkeys, which should work with any window manager.\n"
printf(" I run it with xcape:\n"); "\n"
printf(" xcape -e 'Control_L=Escape;Shift_L=KP_Add'\n"); " I run it with xcape:\n"
printf("\n"); " xcape -e 'Control_L=Escape;Shift_L=KP_Add'\n"
printf(" When Left Shift is tapped a Keypad Add is sent; I configured my window\n"); "\n"
printf(" manager to launch find-cursor with that.\n"); " When Left Shift is tapped a Keypad Add is sent; I configured my window\n"
printf("\n"); " manager to launch find-cursor with that.\n"
printf(" I don't have a numpad on my keyboard; you can also use F13 or some\n"); "\n"
printf(" other unused key.\n"); " I don't have a numpad on my keyboard; you can also use F13 or some\n"
" other unused key.\n",
name, name, name);
} }
// Parse number from commandline, or show error and exit if it's not a number. // Parse number from commandline, or show error and exit if it's not a number.
int parse_num(int ch, char *opt, char *name) { int parse_num(int ch, char *opt, char *name) {
char *end; char *end;
long result = strtol(optarg, &end, 10); long result = strtol(opt, &end, 10);
if (*end) { if (*end) {
fprintf(stderr, "%s: %d must be a number\n\n", name, ch); fprintf(stderr, "%s: value for -%c must be a number\n\n", name, ch);
usage(name); usage(name);
exit(1); exit(1);
} }
@ -205,37 +206,31 @@ int main(int argc, char* argv[]) {
do do
draw(argv[0], display, pointer_screen(argv[0], display), draw(argv[0], display, pointer_screen(argv[0], display),
size, distance, wait, line_width, color_name, size, distance, wait, line_width, color_name,
follow, transparent, grow, outline, ocolor_name, follow, transparent, grow, outline, ocolor_name);
repeat);
while (repeat == -1 || repeat--); while (repeat == -1 || repeat--);
XCloseDisplay(display); XCloseDisplay(display);
} }
// On multiscreen systems, identify which one the cursor is on // Identify which screen the cursor is on.
int pointer_screen(char *name, Display *display) { int pointer_screen(char *name, Display *display) {
int screencount = ScreenCount(display); int screencount = ScreenCount(display);
// The traditional case // The traditional case
if (screencount == 1) { if (screencount == 1)
return DefaultScreen(display); return DefaultScreen(display);
}
// Multihead // Multihead
for (int s=0; s < screencount; s++) { for (int s=0; s < screencount; s++) {
int x = 0, y = 0; Window root, win;
Window window = 0; int unused = 0;
Window root = 0; unsigned int unusedu = 0;
int dummy_int = 0; Screen *screen = ScreenOfDisplay(display, s);
unsigned int dummy_uint = 0;
Screen *screen = ScreenOfDisplay(display, s);
int found = XQueryPointer(display, RootWindowOfScreen(screen), int found = XQueryPointer(display, RootWindowOfScreen(screen),
&root, &window, &root, &win, &unused, &unused, &unused, &unused, &unusedu);
&x, &y, &dummy_int, &dummy_int, &dummy_uint); if (found)
if (found) {
return s; return s;
}
} }
// Fall through (should never happen) // Fall through (should never happen)
@ -253,8 +248,7 @@ void cursor_center(Display *display, int size, int *x, int *y) {
void draw(char *name, Display *display, int screen, void draw(char *name, Display *display, int screen,
int size, int distance, int wait, int line_width, char *color_name, int size, int distance, int wait, int line_width, char *color_name,
int follow, int transparent, int grow, int outline, char *ocolor_name, int follow, int transparent, int grow, int outline, char *ocolor_name
int repeat
) { ) {
// Get the mouse cursor position and size. // Get the mouse cursor position and size.
int center_x, center_y; int center_x, center_y;
@ -425,26 +419,24 @@ void draw(char *name, Display *display, int screen,
} }
/* /* The MIT License (MIT)
* The MIT License (MIT)
* *
* Copyright © 2015-2020 Martin Tournoij * Copyright © Martin Tournoij
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to * of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the * deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is * sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions: * furnished to do so, subject to the following conditions:
* *
* The above copyright notice and this permission notice shall be included in * The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software. * all copies or substantial portions of the Software.
* *
* The software is provided "as is", without warranty of any kind, express or * The software is provided "as is", without warranty of any kind, express or
* implied, including but not limited to the warranties of merchantability, * implied, including but not limited to the warranties of merchantability,
* fitness for a particular purpose and noninfringement. In no event shall the * fitness for a particular purpose and noninfringement. In no event shall the
* authors or copyright holders be liable for any claim, damages or other * authors or copyright holders be liable for any claim, damages or other
* liability, whether in an action of contract, tort or otherwise, arising * liability, whether in an action of contract, tort or otherwise, arising
* from, out of or in connection with the software or the use or other dealings * from, out of or in connection with the software or the use or other dealings
* in the software. * in the software. */
*/

Loading…
Cancel
Save