diff --git a/README.md b/README.md index b8b0fb1..c4a1852 100644 --- a/README.md +++ b/README.md @@ -13,16 +13,105 @@ The goal of this project is to make a simple implementation of the core features - use C - use xlib - - configuration at compile time / with command line arguments - IPC via unix signals - - optional features like sound support that can be disabled at compile time + - optional features like sound support I'm undecided on whether I want to include any GUI whatsoever, as kmousetool already has one if you want one. I might use a minimal UI library to add a GUI, but I don't really want a GTK or QT dependency. -### Planned Features +### Features - [ ] Click mouse after mouse movement stops - [ ] Drag mouse if mouse movement starts shortly after stopping - [ ] Play a sound on mouse click - [x] Unix signals for toggle/enable/disable + - Click mouse after mouse movement stops + - Drag mouse if mouse movement starts shortly after stopping + - Play a sound on mouse click + - defaults to using aplay + - Unix signals for toggle/enable/disable + - SIGHUP = toggle + - SIGUSR1 = enable + - SIGUSR2 = disable + - Status file + - defaults to /tmp/rtmouse-status.txt + + +#### Planned Features + + - Command line arguments + - Better configuration of audio playback method (right now it is just go find the execl call and modify it) + + +### Dependencies + + - a C compiler (should work with gcc, clang, tcc, cproc, etc.) + - libc + - xlib + - aplay, if you want sound. you can also change the audio playback command in the code + + +### Config + +For now, modify `config.h` before building. I'll add a way to use command line +arguments later. The default `config.h` is replicated below: + +```c +struct Dwell_Config config = +{ + // Minimum movement before a mouse motion activates the dwell timer + .min_movement_pixels = 10, + + // rtmouse will wait this long after mouse movement ends before clicking. + // default 500ms. you may want to make it longer + .dwell_time = 500 / TIMER_INTERVAL_MS, + + // rtmouse will drag-click if you move the mouse within this timeframe + // after a click occurs. + .drag_time = 500 / TIMER_INTERVAL_MS, + + // dragging only happens when this is on + .drag_enabled = true, + + // sound plays on click when this is on + .sound_enabled = true, + + // status_file will be modified with enabled/disabled/terminated statuses + // when this is on + .write_status = true, + .status_file = "/tmp/rtmouse-status.txt" +}; +``` + + +### Install + +```bash +./build.sh +sudo ./install.sh +``` +This will put `rtmouse` at `/usr/local/bin` and `mouse + + +### Usage + +Run `rtmouse` and it'll start up. + +You can use `killall -HUP rtmouse` to toggle enabled/disabled state, or `-USR1/-USR2` to specifically enable and disable it respectively. + + +#### i3wm + +I use i3wm, so here's how I'm integrating rtmouse with that. + +I put this in my i3 config: + +``` +exec --no-startup-id rtmouse +bindsym $mod+z exec --no-startup-id killall -HUP rtmouse && killall -USR1 i3status +``` + +and then also add this to my i3status config: + +``` +order += "read_file rtmouse" +read_file rtmouse { + path = "/tmp/rtmouse-status.txt" +} +``` diff --git a/build.sh b/build.sh index cdafb57..ff4eedf 100755 --- a/build.sh +++ b/build.sh @@ -1,2 +1,2 @@ -#!/bin/bash +#!/bin/sh cc -Wall -O2 -o rtmouse rtmouse.c -lX11 -lXi -lXtst diff --git a/config.h b/config.h new file mode 100644 index 0000000..99b45c5 --- /dev/null +++ b/config.h @@ -0,0 +1,24 @@ +struct Dwell_Config config = +{ + // Minimum movement before a mouse motion activates the dwell timer + .min_movement_pixels = 10, + + // rtmouse will wait this long after mouse movement ends before clicking. + // default 500ms. you may want to make it longer + .dwell_time = 500 / TIMER_INTERVAL_MS, + + // rtmouse will drag-click if you move the mouse within this timeframe + // after a click occurs. + .drag_time = 500 / TIMER_INTERVAL_MS, + + // dragging only happens when this is on + .drag_enabled = true, + + // sound plays on click when this is on + .sound_enabled = true, + + // status_file will be modified with enabled/disabled/terminated statuses + // when this is on + .write_status = true, + .status_file = "/tmp/rtmouse-status.txt" +}; diff --git a/install.sh b/install.sh new file mode 100755 index 0000000..88197c7 --- /dev/null +++ b/install.sh @@ -0,0 +1,6 @@ +#!/bin/sh + +set -v + +install --mode 755 -D -t /usr/local/bin rtmouse +install --mode 644 -D -t /usr/local/share/rtmouse mousetool_tap.wav diff --git a/rtmouse.c b/rtmouse.c index 2a0bcd7..6563dce 100644 --- a/rtmouse.c +++ b/rtmouse.c @@ -51,6 +51,8 @@ struct Dwell_Config const char* status_file; }; +#include "config.h" + struct Dwell_State { bool active; @@ -66,17 +68,6 @@ struct Dwell_State int xi_extension_opcode; }; -struct Dwell_Config config = -{ - .min_movement_pixels = 10, - .dwell_time = 500 / TIMER_INTERVAL_MS, - .drag_time = 500 / TIMER_INTERVAL_MS, - .drag_enabled = true, - .sound_enabled = true, - .write_status = true, - .status_file = "/tmp/rtmouse-status.txt" -}; - struct Dwell_State state = { .active = true, diff --git a/test.sh b/test.sh index 3ad0a1d..9cb7b3b 100755 --- a/test.sh +++ b/test.sh @@ -1,2 +1,2 @@ -#!/bin/bash +#!/bin/sh ./build.sh && ./rtmouse