Last active
March 16, 2024 13:28
-
-
Save tanwald/df0a62c64d6c701038324cc95ecc6221 to your computer and use it in GitHub Desktop.
gnome mouse wheel hack for overview triggering and workspace switching without overview
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
######################################################################################################################## | |
# INSTALLATION | |
######################################################################################################################## | |
BIND_SERVICE="[Unit] | |
Description=binding mouse events to keyboard shortcuts | |
After=display-manager.service | |
[Service] | |
ExecStart=bash /home/tanwald/.local/system/bind.sh | |
Restart=always | |
RestartSec=4s | |
[Install] | |
WantedBy=multi-user.target" | |
if [[ "$1" == "install" ]]; then | |
sudo dnf install evemu -y | |
if [[ ! -f /usr/lib/systemd/system/bind.service ]] || [[ "$2" == "--force" ]]; then | |
echo "$BIND_SERVICE" | sudo tee /usr/lib/systemd/system/bind.service | |
sudo systemctl enable --now bind | |
else | |
echo "Service bind.service already exists. Use the --force! Aborting..." | |
exit 1 | |
fi | |
exit 0 | |
fi | |
######################################################################################################################## | |
# INITIALIZATION | |
######################################################################################################################## | |
KEYBOARD=$(libinput list-devices | grep -iv 'mouse' | grep -A1 'Dell.*Keyboard$' | sed -rn 's/.*(\/dev.*)/\1/p') | |
MOUSE=$(libinput list-devices | grep -iv 'keyboard' | grep -A1 'Logitech.*Mouse' | sed -rn 's/.*(\/dev.*)/\1/p') | |
echo "Keyboard: $KEYBOARD" | |
echo "Mouse: $MOUSE" | |
######################################################################################################################## | |
# FUNCTIONS | |
######################################################################################################################## | |
# event codes: sudo evemu-describe | |
function _key_press() { | |
evemu-event "$KEYBOARD" --type EV_KEY --code "$1" --value 1 --sync | |
} | |
function _key_release() { | |
evemu-event "$KEYBOARD" --type EV_KEY --code "$1" --value 0 --sync | |
} | |
function _key() { | |
_key_press "$1" | |
_key_release "$1" | |
} | |
function _switch_workspace() { | |
local -r _direction="$1" | |
_key_press KEY_LEFTCTRL | |
_key_press KEY_LEFTALT | |
if [[ ${_direction} == -* ]]; then | |
_key KEY_LEFT | |
else | |
_key KEY_RIGHT | |
fi | |
_key_release KEY_LEFTCTRL | |
_key_release KEY_LEFTALT | |
} | |
function _show_apps() { | |
_key_press KEY_LEFTMETA | |
_key KEY_A | |
_key_release KEY_LEFTMETA | |
} | |
######################################################################################################################## | |
# MAIN | |
######################################################################################################################## | |
while read -ra _line; do | |
if [[ "${_line[1]}" == "POINTER_SCROLL_WHEEL" ]] && | |
[[ "${_line[6]}" != "0.00/0.0" ]] && | |
# disable in overview | |
machinectl shell tanwald@ /usr/bin/dbus-send --print-reply --dest=org.gnome.Shell \ | |
/org/gnome/Shell \ | |
org.freedesktop.DBus.Properties.Get \ | |
string:org.gnome.Shell \ | |
string:OverviewActive 2>&1 | | |
grep -q 'boolean false'; then | |
# switch workspace | |
_switch_workspace "${_line[6]}" | |
elif [[ "${_line[1]}" == "POINTER_BUTTON" ]] && | |
[[ "${_line[3]}" == "BTN_MIDDLE" ]] && | |
[[ "${_line[8]}" == "1" ]]; then | |
# show all apps | |
_show_apps | |
fi | |
done < <(stdbuf -oL libinput debug-events --device "${MOUSE}" &) | |
wait |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment