libratbag / piper

GTK application to configure gaming devices
GNU General Public License v2.0
4.72k stars 175 forks source link

Feature Request: Ability to bind shell/python script to buttons #930

Closed Ao1Pointblank closed 8 months ago

Ao1Pointblank commented 8 months ago

Is your feature request related to a problem? Please describe. On my mouse, Logitech G403, the DPI button is pretty sensitive and can accidentally be pressed in a game, throwing me off. So, I made a script that uses ratbagctl to change the DPI/resolution based on an array stored in the script file. This script displays a notification with osd_cat to let me know I have pressed it by accident. I am contemplating how to make a script that would require the button to be held for a certain time frame before activating it.

Describe the solution you'd like My wish is for .sh or .py scripts to be bound to any mouse key, but in my case just the DPI button.

Describe alternatives you've considered This can somewhat be achieved by assigning a system-wide key-combo in my keyboard settings, and then making piper run that macro. It's not super elegant.

Additional context this is my visual dpi script: (requires osd_cat package aka xosd)

#!/bin/bash
#get variable mouse name from ratbag
G403_NAME=$(ratbagctl list | sed -n "s/:\(.*\)//p")

array=(
400
800
1200
1400
1600
)

arrayIndex=0
if [ -f "/tmp/dpi_index.txt" ]; then
    arrayIndex=`cat /tmp/dpi_index.txt`
    if [ $arrayIndex -ge ${#array[@]} ]; then
        arrayIndex=0
    fi
fi

echo "G403: ${array[$arrayIndex]}dpi" | osd_cat -p bottom -A right -c orange -d 1 -f 10x20 -O 3
ratbagctl $G403_NAME dpi set "${array[$arrayIndex]}"

((arrayIndex++))
echo $arrayIndex > /tmp/dpi_index.txt
staticssleever668 commented 8 months ago

This can somewhat be achieved by assigning a system-wide key-combo in my keyboard settings, and then making piper run that macro.

I don't think there is a better way, sorry. libratbag only configures devices, so we are limited by what device firmware can do.

In theory the only good way to do that would be to send data from the device and listen to it on PC side. If I understand your script right, you are trying to mimic pop-up with new DPI Logitech software for Windows shows when DPI is changed with a button click. I'm now aware of how Logitech mice do it, but on Sinowealth devices when DPI is switched with a button they do send such data. So I think a little program always running in the back listening for such data could be made.

This is currently out of scope of libratbag.