Skip to content

Instantly share code, notes, and snippets.

@pedrovhb
Last active April 4, 2023 15:58
Show Gist options
  • Save pedrovhb/41e9d5b7b7b5c13fe2c94aa4cee1193a to your computer and use it in GitHub Desktop.
Save pedrovhb/41e9d5b7b7b5c13fe2c94aa4cee1193a to your computer and use it in GitHub Desktop.
This makes it so that as long as that button is being held, moving the cursors scrolls instead.
#! /usr/bin/env python
import re
import subprocess
import textwrap
RE_LOGITECH_ID = rb"Logitech MX Ergo[\s\-\w]+id=(\d+).*pointer"
def set_ergo_scroll() -> None:
"""Set button scrolling behavior for MX Ergo."""
print("Setting ergo scroll...")
inputs = subprocess.run(["xinput", "list"], capture_output=True).stdout
ergo_ids = re.findall(RE_LOGITECH_ID, inputs)
for ergo_id in ergo_ids:
commands = (
[
"xinput",
"set-prop",
ergo_id,
"libinput Scroll Method Enabled",
"0,",
"0,",
"1",
],
["xinput", "set-prop", ergo_id, "libinput Button Scrolling Button", "8"],
)
for cmd in commands:
proc = subprocess.run(cmd, capture_output=True)
if proc.returncode != 0:
print(f"Error calling xinput.\n")
print(f"stdout:")
print(textwrap.indent(proc.stdout.decode(), " "))
print(f"stderr:")
print(textwrap.indent(proc.stderr.decode(), " "))
exit()
print("Ergo scroll set.")
if __name__ == "__main__":
set_ergo_scroll()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment