From 7dceceb175af597fb97893e4a60ef542048a48f1 Mon Sep 17 00:00:00 2001 From: rafa_99 Date: Sat, 26 Mar 2022 02:38:45 +0000 Subject: Suckless style stuff --- .gitignore | 2 ++ Makefile | 11 +++++++---- README.md | 13 ++++++------- config.def.h | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ config.h | 62 ------------------------------------------------------------ xmouseless.c | 7 ++----- 6 files changed, 74 insertions(+), 78 deletions(-) create mode 100644 .gitignore create mode 100644 config.def.h delete mode 100644 config.h diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9387af5 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +config.h +xmouseless diff --git a/Makefile b/Makefile index f8e8698..413012e 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ # xmouseless VERSION = 0.1.1 -CC = /usr/bin/gcc -CFLAGS = -Wall -g +CC = cc +CFLAGS = -Wall LDFLAGS = -lX11 -lXtst -lpthread PREFIX = /usr/local @@ -9,14 +9,17 @@ PREFIX = /usr/local SRC = xmouseless.c BIN = xmouseless -all: $(BIN) +all: config.h build -$(BIN): $(SRC) config.h +build: $(CC) $(CFLAGS) -o $(BIN) $(SRC) $(LDFLAGS) clean: rm -f $(BIN) +config.h: + cp config.def.h config.h + install: all mkdir -p $(PREFIX)/bin cp -f $(BIN) $(PREFIX)/bin diff --git a/README.md b/README.md index 6685c2e..dda7257 100644 --- a/README.md +++ b/README.md @@ -28,10 +28,10 @@ available. When pressing an exit key, the program exits. The usage is quite intuitive and with some practice, you can move the pointer to a specific location very fast. Basically, you move the pointer by pressing some -keys (the defaults are i, k, j and l for up, down, left and right) -and change the speed by pressing modifier keys. -The keys f, d and s (by default) are used to simulate mouse clicks and grabbing. -With some other keys, you can scroll up, down, left and right and execute +keys (the defaults are h, j, k and l for left, down, up and right) +and change the speed by pressing number keys from 1 through 3. +The keys u, i and o (by default) are used to simulate mouse clicks and grabbing. +With some other keys, you can scroll up, down, left and right and execute previously defined shell commands. You probably want to define a key binding to start xmouseless. @@ -39,7 +39,6 @@ You probably want to define a key binding to start xmouseless. ## Configuration -The configuration is done in config.h, which is a C header file, +The configuration is done in config.def.h, which is a C header file, but you don't need any programming knowledge to edit it. -After you edited the file, you have to run make again. - +After you edited the file, you have to run make again. diff --git a/config.def.h b/config.def.h new file mode 100644 index 0000000..ae47709 --- /dev/null +++ b/config.def.h @@ -0,0 +1,57 @@ +/* the rate at which the mouse moves in Hz + * does not change its speed */ +static const unsigned int move_rate = 50; + +/* the default speed of the mouse pointer + * in pixels per second */ +static const unsigned int default_speed = 500; + +/* changes the speed of the mouse pointer */ +static SpeedBinding speed_bindings[] = { + /* key speed */ + { XK_3, 3000 }, + { XK_2, 1500 }, + { XK_1, 100 }, +}; + +/* moves the mouse pointer + * you can also add any other direction (e.g. diagonals) */ +static MoveBinding move_bindings[] = { + /* key x y */ + { XK_h, -1, 0 }, + { XK_l, 1, 0 }, + { XK_k, 0, -1 }, + { XK_j, 0, 1 }, +}; + +/* 1: left + * 2: middle + * 3: right */ +static ClickBinding click_bindings[] = { + /* key button */ + { XK_space, 1 }, + { XK_u, 1 }, + { XK_o, 2 }, + { XK_i, 3 }, +}; + +/* scrolls up, down, left and right + * a higher value scrolls faster */ +static ScrollBinding scroll_bindings[] = { + /* key x y */ + { XK_s, 0 , 25 }, + { XK_w, 0 , -25 }, + { XK_d, 25, 0 }, + { XK_a, -25, 0 }, +}; + +/* executes shell commands */ +static ShellBinding shell_bindings[] = { + /* key command */ + { XK_0, "xdotool mousemove 0 0" }, +}; + +/* exits on key release which allows click and exit with one key */ +static KeySym exit_keys[] = { + XK_Escape, XK_q, XK_space +}; diff --git a/config.h b/config.h deleted file mode 100644 index 7164980..0000000 --- a/config.h +++ /dev/null @@ -1,62 +0,0 @@ - -/* the rate at which the mouse moves in Hz - * does not change its speed */ -static const unsigned int move_rate = 50; - -/* the default speed of the mouse pointer - * in pixels per second */ -static const unsigned int default_speed = 500; - -/* changes the speed of the mouse pointer */ -static SpeedBinding speed_bindings[] = { - /* key speed */ - { XK_Super_L, 3000 }, - { XK_Alt_L, 1500 }, - { XK_a, 100 }, - { XK_Control_L, 10 }, -}; - -/* moves the mouse pointer - * you can also add any other direction (e.g. diagonals) */ -static MoveBinding move_bindings[] = { - /* key x y */ - { XK_j, -1, 0 }, - { XK_l, 1, 0 }, - { XK_i, 0, -1 }, - { XK_k, 0, 1 }, -}; - -/* 1: left - * 2: middle - * 3: right */ -static ClickBinding click_bindings[] = { - /* key button */ - { XK_space, 1 }, - { XK_f, 1 }, - { XK_d, 2 }, - { XK_s, 3 }, -}; - -/* scrolls up, down, left and right - * a higher value scrolls faster */ -static ScrollBinding scroll_bindings[] = { - /* key x y */ - { XK_n, 0 , 25 }, - { XK_p, 0 , -25 }, - { XK_plus, 0 , 80 }, - { XK_minus, 0 , -80 }, - { XK_h, 25, 0 }, - { XK_g, -25, 0 }, -}; - -/* executes shell commands */ -static ShellBinding shell_bindings[] = { - /* key command */ - { XK_b, "wmctrl -a firefox" }, - { XK_0, "xdotool mousemove 0 0" }, -}; - -/* exits on key release which allows click and exit with one key */ -static KeySym exit_keys[] = { - XK_Escape, XK_q, XK_space -}; diff --git a/xmouseless.c b/xmouseless.c index 75d2aea..12a789e 100644 --- a/xmouseless.c +++ b/xmouseless.c @@ -1,6 +1,6 @@ /* * xmouseless -*/ + */ #include #include #include @@ -197,7 +197,6 @@ void handle_key(KeyCode keycode, Bool is_press) { for (i = 0; i < LENGTH(click_bindings); i++) { if (click_bindings[i].keysym == keysym) { click(click_bindings[i].button, is_press); - printf("click: %i %i\n", click_bindings[i].button, is_press); } } @@ -205,7 +204,6 @@ void handle_key(KeyCode keycode, Bool is_press) { for (i = 0; i < LENGTH(speed_bindings); i++) { if (speed_bindings[i].keysym == keysym) { speed = is_press ? speed_bindings[i].speed : default_speed; - printf("speed: %i\n", speed); } } @@ -231,7 +229,6 @@ void handle_key(KeyCode keycode, Bool is_press) { /* shell bindings */ for (i = 0; i < LENGTH(shell_bindings); i++) { if (shell_bindings[i].keysym == keysym) { - printf("executing: %s\n", shell_bindings[i].command); if (fork() == 0) { system(shell_bindings[i].command); exit(EXIT_SUCCESS); @@ -239,7 +236,7 @@ void handle_key(KeyCode keycode, Bool is_press) { } } - /* exit */ + /* exit */ for (i = 0; i < LENGTH(exit_keys); i++) { if (exit_keys[i] == keysym) { close_x(EXIT_SUCCESS); -- cgit v1.2.3