Files
desk-reminder/README.md

124 lines
3.5 KiB
Markdown

# desk-reminder
![Logo](./docs/icons/256x256/desk-reminder.png)
Small Linux utility that enforces periodic standing desk adjustments. After 20 minutes
sitting, the screen is locked until the user switches to standing mode on their adjustable
standing desk. This works via an ecard reader attached to the back of the computer
screen and the wall, which allows this program to detect when the user is standing or
sitting.
## What It Does
- Grabs a specific input keyboard device with `EVIOCGRAB`, so key events from that device are hidden from other applications.
- Reads digit key presses (`0-9`) until `Enter`.
- Hashes the entered numeric string with SHA-256 and compares the first 8 bytes (as a 64-bit number) against a hardcoded value.
- If the hash matches, it resets the standing timer, kills `i3lock`, and re-enables keyboards.
- A background watcher thread checks elapsed time every second.
- Once elapsed time reaches the configured interval, it disables keyboard devices via `xinput` and starts `i3lock` with a lockscreen image.
Default interval is 20 minutes.
## Dependencies
Build-time:
- GCC
- OpenSSL development headers/libraries (`libssl-dev` on Debian/Ubuntu)
- POSIX threads (`pthread`)
- Linux input headers (`linux/input.h`)
Runtime:
- `xinput`
- `i3lock`
- X11 session (because keyboard disabling uses `xinput`)
- Permission to read the target input device in `/dev/input/by-id/...`
## Build
The current `Makefile` does not match the source filename in this repository (`desk-reminder.c`), so compile directly:
```bash
gcc -Wall -Wextra -O2 desk-reminder.c -o desk-reminder -lssl -lcrypto -lpthread
```
## Configure
Edit the hardcoded device path in `desk-reminder.c`:
```c
const char *dev = "/dev/input/by-id/usb-IC_Reader_IC_Reader_08FF20171101-event-kbd";
```
Use one of these to find your device path:
```bash
ls -l /dev/input/by-id/
cat /proc/bus/input/devices
```
## Usage
Run with default interval (20 minutes):
```bash
./desk-reminder
```
Set interval explicitly:
```bash
./desk-reminder -i 20m
./desk-reminder -i 1200s
```
`-i` accepts a positive integer and optional unit suffix:
- `s` for seconds
- `m` for minutes (default if no suffix)
Examples:
- `-i 30` means 30 minutes
- `-i 30m` means 30 minutes
- `-i 45s` means 45 seconds
## Operational Notes
- This program grabs the configured device exclusively.
- When timeout is reached, keyboard devices are disabled using:
- `xinput --list --short | grep -i keyboard | grep -v XTEST | ... | xinput disable`
- On successful reset code entry, keyboards are re-enabled with the matching `xinput enable` pipeline.
- Screen lock image is hardcoded to:
- `/usr/local/share/lockscreens/standing_gopher.png`
Ensure this file exists, or adjust the command in source.
## Safety / Recovery
- Keep another input method available during testing (for example, a second terminal/TTY).
- Test with a short interval first (`-i 30s`) to verify behavior.
- If something goes wrong and keyboards remain disabled, use another session/input device to run:
```bash
xinput --list --short | grep -i keyboard | grep -v XTEST | sed -E 's/.*id=([0-9]+).*/\1/' | xargs -r -n1 xinput enable
pkill i3lock
```
## Limitations
- Linux-only.
- X11-specific keyboard management (not Wayland-native).
- Input device path, reset hash target, and lockscreen path are all hardcoded.
- No systemd service/unit is included in this repository.
## License
This project is licensed under the GNU General Public License, version 3.
See `LICENSE` for the full text.