| 1 | # AGENTS.md |
| 2 | |
| 3 | ## Project overview |
| 4 | |
| 5 | **jstest-gtk** is a Linux GTK+ (gtkmm-3) graphical joystick tester and configurator. It talks to the classic Linux joystick API (`/dev/input/js*`), shows live axis/button state, and can remap axes/buttons and adjust calibration (deadzone, range, invert) via `ioctl` on the joydev device. |
| 6 | |
| 7 | License: GPL-3.0-or-later. Original author: Ingo Ruhnke. Later work includes USB-ID-based layout configs and libudev hotplug (e.g. Raphael Rosch). |
| 8 | |
| 9 | ### What it does |
| 10 | |
| 11 | - Main window with device combo and live axis/button view (`JoystickTestWidget`) |
| 12 | - Live test UI with progress bars, optional stick/trigger drawings (`JoystickTestWidget`) |
| 13 | - Axis/button remapping (`JoystickMapWidget` / `RemapWidget`) — applied to the kernel joydev mapping (not persistent across reboot) |
| 14 | - Calibration editor and a simple “move sticks to extremes” wizard (`JoystickCalibrationWidget`, `CalibrateMaximumDialog`) |
| 15 | - Optional per-controller config files under `data/` matched by USB vendor:product ID (via libudev) |
| 16 | - Hotplug: `UdevMonitor` refreshes the list and marks devices disconnected/reconnected in the test window |
| 17 | |
| 18 | ### Non-goals / platform limits |
| 19 | |
| 20 | - Linux-only (joydev + udev) |
| 21 | - Calibration/mapping apply to **joydev**, not raw evdev; some SDL builds ignore joydev unless forced (see `README.md`) |
| 22 | - No Windows/macOS support |
| 23 | |
| 24 | ## Layout |
| 25 | |
| 26 | | Path | Role | |
| 27 | |------|------| |
| 28 | | `src/main.cpp` / `main.hpp` | App entry, CLI (`--datadir`, `--simple`, `--verbose`), owns GUIs | |
| 29 | | `src/joystick.*` | Device open, events, calibration/mapping ioctls, USB ID via udev | |
| 30 | | `src/joystick_test_widget.*` | Main window: device combo, test UI, udev refresh | |
| 31 | | `src/joystick_calibration_widget.*` | Manual calibration UI | |
| 32 | | `src/joystick_map_widget.*` / `remap_widget.*` | Reorder axes/buttons | |
| 33 | | `src/joystick_config_files.*` | Load `data/mappings/*-mapping.config` | |
| 34 | | `src/udev_monitor.*` | Netlink udev watch for `/js` nodes | |
| 35 | | `src/evdev_helper.*` | Name helpers for ABS_/BTN_ codes (mapping labels) | |
| 36 | | `src/*_widget.*` | Cairo stick/rudder/throttle drawing; buttons are `Gtk::ToggleButton` | |
| 37 | | `data/icons/` | Controller PNGs and app SVG | |
| 38 | | `data/mappings/` | USB-ID mapping configs + README | |
| 39 | | `data/applications/` | Desktop entry | |
| 40 | | `doc/` | Man page (`jstest-gtk.1`) | |
| 41 | | `CMakeLists.txt` | Build/install; uses `GNUInstallDirs` | |
| 42 | |
| 43 | ### Data directory |
| 44 | |
| 45 | - Compile-time default: `JSTEST_GTK_DATADIR` = `${CMAKE_INSTALL_FULL_DATADIR}/jstest-gtk/` (from CMake) |
| 46 | - Runtime override: `--datadir DIR` (should end with `/`) |
| 47 | - Layout under the datadir: `icons/…`, `mappings/…` |
| 48 | - Configs load from `datadir + "mappings"`; icon basenames from configs resolve under `datadir + "icons/"` |
| 49 | |
| 50 | ### Mapping configs (`data/mappings/*-mapping.config`) |
| 51 | |
| 52 | Simple `key=value` files (`#` comments). Important keys: |
| 53 | |
| 54 | - `js_type` — selects graphical layout (e.g. `xbox360`, `ps4-dualshock4`, `gamecube`) |
| 55 | - `usb_id` — one or more `vvvv:pppp` lines to match |
| 56 | - `icon_filename` — PNG basename under `icons/` (e.g. `xbox360.png`) |
| 57 | - `axis_N` / `button_N` — display labels |
| 58 | |
| 59 | Unknown devices fall back to axis-count heuristics and `icons/generic.png`. |
| 60 | |
| 61 | ## Versioning |
| 62 | |
| 63 | - **Source of truth:** top-level `VERSION` file (e.g. `0.2.0-dev`). Drop the `-dev` suffix when tagging a final release. |
| 64 | - **CMake:** if `-DPROJECT_VERSION_FULL=...` is not set, reads `VERSION`. Defines `JSTEST_GTK_VERSION` for the binary. `project(VERSION ...)` uses the numeric `major.minor.patch` prefix only. |
| 65 | - **Nix flake:** reads `VERSION`, appends `+g${shortRev}` (or `dirty`), passes `-DPROJECT_VERSION_FULL=...` via `cmakeFlags`. |
| 66 | - **CLI:** `--version` prints `jstest-gtk ${JSTEST_GTK_VERSION}`. |
| 67 | - Do not hardcode version numbers in source; point at `VERSION` / `PROJECT_VERSION_FULL` / `JSTEST_GTK_VERSION`. |
| 68 | |
| 69 | ## Build |
| 70 | |
| 71 | Dependencies: CMake ≥ 3.5, gtkmm-3.0, sigc++-2.0, X11, **libudev**, threads. |
| 72 | |
| 73 | ```bash |
| 74 | mkdir build && cd build |
| 75 | cmake .. |
| 76 | make |
| 77 | ``` |
| 78 | |
| 79 | Install layout: |
| 80 | |
| 81 | - Binary → `${CMAKE_INSTALL_BINDIR}/jstest-gtk` (datadir baked in at compile time) |
| 82 | - Icons/mappings → `${CMAKE_INSTALL_DATADIR}/jstest-gtk/{icons,mappings}/` |
| 83 | - Desktop file → `${CMAKE_INSTALL_DATADIR}/applications/` |
| 84 | - App icon → hicolor scalable apps |
| 85 | - Man page → `${CMAKE_INSTALL_MANDIR}/man1/` |
| 86 | |
| 87 | Optional Nix flake is present (`flake.nix`). |
| 88 | |
| 89 | ## CLI |
| 90 | |
| 91 | ``` |
| 92 | jstest-gtk [OPTIONS] [DEVICE] |
| 93 | -h, --help |
| 94 | -v, --version |
| 95 | --simple Hide stick graphics |
| 96 | --verbose Extra logging (`m_verbose`) |
| 97 | --datadir DIR Data/config/icon directory |
| 98 | DEVICE e.g. /dev/input/js0 (skip list, open test UI) |
| 99 | ``` |
| 100 | |
| 101 | ## Working guidelines |
| 102 | |
| 103 | - Each change shall be followed by a detailed git commit message at the end. |
| 104 | - Prefer compile-time datadir + explicit `--datadir`; do not add multi-path “guess where data lives” logic unless asked. |
| 105 | - Keep joydev calibration/mapping behavior intact when touching device code; test paths go through `Joystick`. |
| 106 | - New controller types: add a `data/*-mapping.config`, icon if needed, document `js_type` in `data/README.txt`, and a `setup_*_equiv()` path in `JoystickTestWidget` if a custom stick layout is required. |