83 lines
2.4 KiB
Bash
Executable File
83 lines
2.4 KiB
Bash
Executable File
#!/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
|