flatten directory structure, remove system/ nesting
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
# input-remapper-switcher
|
||||
|
||||
Automatically switches [input-remapper](https://github.com/sezanzeb/input-remapper) presets on a per-game (or per-app) basis when used with the **Hyprland** window manager.
|
||||
|
||||
## How It Works
|
||||
|
||||
1. Connects to the Hyprland socket (`.socket2.sock`) and listens for `activewindowv2` events.
|
||||
2. On each window change, it grabs the focused window's **class** and **title** via `hyprctl activewindow -j | jq`.
|
||||
3. If either value matches a configured entry in the `PROFILES` associative array, it activates the corresponding input-remapper preset on your device.
|
||||
4. When an unknown window is focused, it deactivates the last active preset.
|
||||
|
||||
> Uses `input-remapper-control` under the hood to start/stop presets.
|
||||
|
||||
## Adding a Game Profile
|
||||
|
||||
1. Find the window class or title of your game:
|
||||
- Run `hyprctl clients` and locate the game in the output (class and title are listed for each window)
|
||||
2. Get the exact name of your input device:
|
||||
- `sudo input-remapper-control --list-devices`
|
||||
3. Edit `input-remapper-switcher.sh` and add an entry to the `PROFILES` array (line 6):
|
||||
|
||||
```bash
|
||||
declare -A PROFILES=(
|
||||
["Grand Theft Auto V"]="GTA"
|
||||
["steam_app_1151340"]="Fallout"
|
||||
["steam_app_1203620"]="Enshrouded"
|
||||
# Add yours here:
|
||||
["Your Window Class or Title"]="Your Preset Name"
|
||||
)
|
||||
```
|
||||
|
||||
4. If your device is different, update `DEVICE_NAME` on line 13:
|
||||
```bash
|
||||
DEVICE_NAME="Your Device Name"
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
Run the script manually or launch it at Hyprland startup (e.g., in `hyprland.conf`):
|
||||
|
||||
```conf
|
||||
exec-once = ~/.config/hypr/scripts/input-remapper-switcher.sh
|
||||
```
|
||||
|
||||
The script runs in the foreground listening for events — it does not daemonize on its own.
|
||||
+82
@@ -0,0 +1,82 @@
|
||||
#!/usr/bin/env bash
|
||||
# ~/.config/hypr/scripts/input-remapper-switcher.sh
|
||||
|
||||
# Define your mappings: "Window Class" -> "Preset Name"
|
||||
# Use 'hyprctl clients' to find the 'class' of your windows.
|
||||
declare -A PROFILES=(
|
||||
["Grand Theft Auto V"]="GTA"
|
||||
["steam_app_1151340"]="Fallout"
|
||||
["steam_app_1203620"]="Enshrouded"
|
||||
)
|
||||
|
||||
# Get exact name via: sudo input-remapper-control --list-devices
|
||||
DEVICE_NAME="Logitech G502 LIGHTSPEED Wireless Gaming Mouse"
|
||||
|
||||
last_class=""
|
||||
last_title=""
|
||||
|
||||
class(){
|
||||
local target_preset_class="${PROFILES[$active_class]}"
|
||||
|
||||
echo "Activating preset '$target_preset_class' for class '$active_class'"
|
||||
input-remapper-control --command start --device "$DEVICE_NAME" --preset "$target_preset_class" > /dev/null 2>&1
|
||||
|
||||
last_class="${target_preset_class}"
|
||||
}
|
||||
|
||||
title(){
|
||||
local target_preset_title="${PROFILES[$active_title]}"
|
||||
|
||||
echo "Activating preset '$target_preset_title' for title '$active_title'"
|
||||
input-remapper-control --command start --device "$DEVICE_NAME" --preset "$target_preset_title" > /dev/null 2>&1
|
||||
|
||||
last_title="${target_preset_title}"
|
||||
}
|
||||
|
||||
none(){
|
||||
|
||||
if [[ -n $last_class ]]; then
|
||||
echo "Deactivating preset for '${last_class}'"
|
||||
input-remapper-control --command stop --device "$DEVICE_NAME" --preset "${active_class}" > /dev/null 2>&1
|
||||
last_class=""
|
||||
elif [[ -n $last_title ]]; then
|
||||
echo "Deactivating preset for '${last_title}'"
|
||||
input-remapper-control --command stop --device "$DEVICE_NAME" --preset "${active_title}" > /dev/null 2>&1
|
||||
last_title=""
|
||||
fi
|
||||
}
|
||||
|
||||
doit(){
|
||||
# local active_class
|
||||
active_class=$(hyprctl activewindow -j | jq -r '.class')
|
||||
# local active_title
|
||||
active_title=$(hyprctl activewindow -j | jq -r '.title')
|
||||
|
||||
if [[ -v PROFILES["$active_class"] ]]; then
|
||||
# echo "found class ${active_class}"
|
||||
class
|
||||
elif [[ -v PROFILES["$active_title"] ]]; then
|
||||
# echo "found title ${active_title}"
|
||||
title
|
||||
else
|
||||
none
|
||||
fi
|
||||
}
|
||||
|
||||
cleanup() {
|
||||
echo ""
|
||||
echo "Performing cleanup on exit..."
|
||||
# Cleanup logic here
|
||||
}
|
||||
|
||||
# Trap EXIT covers normal exit, errors, SIGINT, and SIGTERM
|
||||
trap cleanup EXIT
|
||||
|
||||
# Listen to the Hyprland socket for active window changes
|
||||
# 'activewindowv2' sends events when the active window changes
|
||||
socat - "UNIX-CONNECT:$XDG_RUNTIME_DIR/hypr/$HYPRLAND_INSTANCE_SIGNATURE/.socket2.sock" | \
|
||||
while read -r line; do
|
||||
if [[ "$line" =~ ^activewindowv2 ]]; then
|
||||
doit
|
||||
fi
|
||||
done
|
||||
Reference in New Issue
Block a user