YaLTeR / niri

A scrollable-tiling Wayland compositor.
https://matrix.to/#/#niri:matrix.org
GNU General Public License v3.0
4.12k stars 123 forks source link

Allow mouse buttons bindings #761

Open xaltsc opened 3 weeks ago

xaltsc commented 3 weeks ago

From what I can tell, it's currently impossible to bind a mouse button to an action. For my use, I wish to use the next/previous (side/extra, 275, 276 as reported by wev) button (with M+) to focus left/right columns.

The issue seems to be in the Trigger enum which only defines keysyms and scroll triggers.

System Information

Paul-Eau commented 3 days ago

I made a simple script that I'm working on to work around this issue. It uses evtest to read mouse input. But be aware that this may interfere with other shortcuts used by other software (backward / forward in Firefox for example).

#!/bin/bash

MOUSE="/dev/input/event6" 
KEYBOARD="/dev/input/event4"
MOD_STATE_FILE="/tmp/mod_pressed_state"  

echo "false" > "$MOD_STATE_FILE"

evtest "$KEYBOARD" | while read -r line; do
    if [[ "$line" == *"code 125"* && "$line" == *"value 1"* ]]; then
        echo "true" > "$MOD_STATE_FILE"  
        echo "Mod pressed"
    fi

    if [[ "$line" == *"code 125"* && "$line" == *"value 0"* ]]; then
        echo "false" > "$MOD_STATE_FILE"  
        echo "Mod not pressed"
    fi
done &

evtest "$MOUSE" | while read -r line; do
    mod_pressed=$(cat "$MOD_STATE_FILE")

    if [[ "$mod_pressed" == "true" && "$line" == *"code 275"* && "$line" == *"value 1"* ]]; then
        niri msg action focus-column-left
    fi

    if [[ "$mod_pressed" == "true" && "$line" == *"code 276"* && "$line" == *"value 1"* ]]; then
        niri msg action focus-column-right
    fi
done