Trying to manually remap mouse buttons
Hi all,
I want to remap my side mouse buttons to move across desktops. I previously used input-remapper, but it doesn't support Runit.
Here is my attempt with python:
import evdev
import os
import subprocess
down = 1
up = 0
btn_up = 276
btn_down = 275
def output(cmd):
return subprocess.check_output(cmd, shell=True).strip().decode("utf-8")
def get_desktop():
return int(output("wmctrl -d | grep '*' | awk '{print $1;}'"))
def set_desktop(index):
os.system(f"wmctrl -s {index}")
def on_up():
set_desktop(get_desktop()+1)
def on_down():
set_desktop(get_desktop()-1)
devices = [evdev.InputDevice(path) for path in evdev.list_devices()]
mice = [device for device in devices if "mouse" in device.name.lower()
and not "keyboard" in device.name.lower()]
print(f"Mice: {mice}")
mouse = mice[0]
print(f"Using {mouse.name} at {mouse.path}")
for event in mouse.read_loop():
if event.code == 276 and event.value == 1:
on_up()
if event.code == 275 and event.value == 1:
on_down()
So far so good, the desktops are changed as expected.
Unfortunately, the BTN_SIDE and BTN_EXTRA events are still passed to the window under the mouse. After switching desktops, if there's a browser window under the cursor, it goes back one page, for example.
Is there a way to capture these particular events in the script and stop their propagation?