|
#!/bin/bash |
|
|
|
# This file need to be executed with root privilegies |
|
|
|
# Dependencies: |
|
# - evemu |
|
# - xinput |
|
|
|
|
|
MOUSE_ID=6 #Get the correct id with xinput list |
|
|
|
# First we'll remap the side buttons to mouse-wheel and disable the mouse-wheel. |
|
# The default mouse-wheel buttons are 4 and 5, so we remap 4 and 5 to 0, to disable it |
|
# The side buttons on my mouse are 8 and 9, so we remap those to 5 and 4 |
|
# After this command alone you should be able to scroll with the extra mouse buttons. |
|
# But you'd need one click per line-scroll |
|
# Very hard to use it like that. |
|
|
|
# DISCLAIMER: On your mouse the extra buttons may been mapped to other values than 8 and 9. |
|
# Test them with xinput --query-state $MOUSE_ID |
|
|
|
xinput set-button-map $MOUSE_ID 1 2 3 0 0 6 7 5 4 10 |
|
|
|
# The following while loop allow us to be able to keep scrolling while the button is hold down |
|
while true; do |
|
|
|
STATE1=$(xinput --query-state $MOUSE_ID | grep "button\[9" | sort); #9 and 8 are the button codes, if you run query state and press the button you'll know what button to call. |
|
|
|
STATE2=$(xinput --query-state $MOUSE_ID | grep "button\[8" | sort); |
|
|
|
|
|
if [ $STATE1 == "button[9]=up" ] && [ $STATE2 == "button[8]=up" ]; then |
|
SCROLL="NONE" |
|
fi |
|
|
|
if [ $STATE1 == "button[9]=down" ] && [ $SCROLL != "UP" ]; then |
|
SCROLL="DOWN" |
|
# Wayland doesn't support xdotool so we need to use evemu-event. |
|
# You can use sudo evemu-record /dev/input/event3 > recording.evemu to record your events |
|
# Then you can see the content of recording.evemu to check the event type, code and value |
|
# the lines will look somethhing like this: |
|
# E: 3.018057 0001 0113 0001 # EV_KEY / BTN_SIDE 1 |
|
# E: 3.018057 0001 0113 0001 # EV_KEY / BTN_SIDE 0 |
|
# Usually when you click a mouse button it will fire an event with value 1 for when the button goes down |
|
# And another event with value 0 saying the button was released |
|
# Here we want to simulate many complete clicks, that's why we need to fire two events. |
|
evemu-event /dev/input/event3 --type EV_KEY --code BTN_SIDE --value 1 --sync |
|
evemu-event /dev/input/event3 --type EV_KEY --code BTN_SIDE --value 0 --sync |
|
fi |
|
|
|
if [ $STATE2 == "button[8]=down" ] && [ $SCROLL != "DOWN" ]; then |
|
SCROLL="UP" |
|
evemu-event /dev/input/event3 --type EV_KEY --code BTN_EXTRA --value 1 --sync |
|
evemu-event /dev/input/event3 --type EV_KEY --code BTN_EXTRA --value 0 --sync |
|
fi |
|
|
|
sleep .01 # If you increase the time the scroll will be slower, if you reduce it will be faster. |
|
done |
This script was made and tested on:
Fedora 32 using Wayland
Mouse: GXT 922 Gaming Mouse
I don't know exactly why but this works on every window but terminal and gedit, I think those still rely on Xorg or something like that internally, but since I don't use those much, isn't a problem to me.