Created
January 31, 2023 17:13
-
-
Save Buccaneersdan/feb6acd5e6a67165c24960a6d479f0f6 to your computer and use it in GitHub Desktop.
Enable scrollwheel-click to scroll via dragging und X11 (requires python lib plumbum and linux binary xinput)
This file contains 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
from plumbum import local | |
class Candidate: | |
name = "" | |
id = -1 | |
def __init__(self, name, id): | |
self.name = name | |
self.id = id | |
def main(): | |
x = None | |
try: | |
x = local["xinput"] | |
except: | |
print("Command xinput is not installed") | |
if x is None: | |
exit(1) | |
r, stdout, stderr = x.run(["list"], retcode=None) | |
if r != 0: | |
raise Exception("xinput failed") | |
lines = stdout.split("\n") | |
candidates = [] | |
b = b'\xe2\x86\xb3' | |
n = 1 | |
for line in lines: | |
if line.lower().find("pointer") > -1: | |
stupidlbchar = line.find(b.decode()) | |
if stupidlbchar > -1: | |
line = str(n) + ") " + line[stupidlbchar+1:].strip() | |
parenpos = line.find(")") | |
if parenpos == -1: | |
continue | |
tabpos = line.find("\t") | |
if tabpos == -1: | |
continue | |
cn = line[parenpos+2:tabpos].strip() | |
idpos = line.find("id", tabpos) | |
parenpos = line.find("[", idpos + 3) | |
id = line[idpos+3:parenpos].strip() | |
candidates.append(Candidate(cn, int(id))) | |
n += 1 | |
candidate_count = len(candidates) | |
if candidate_count == 0: | |
raise Exception("No mouse-devices found") | |
for c in candidates: | |
# print(c.name) | |
if \ | |
c.name.find("2.4G Mouse") > -1 or \ | |
c.name.find("2.4G Wireless Mouse") > -1 or \ | |
c.name.find("CX 2.4G Receiver Mouse") > -1 or \ | |
c.name.find("Logitech Wireless Mouse") > -1: | |
lrc, lro, lre = x["--list-props", c.id].run(retcode=None) | |
if lrc != 0: | |
raise Exception(lre) | |
for line in lro.splitlines(): | |
if line.find("libinput Scroll Method Enabled (") > -1: | |
parenpos = line.find("(") | |
parenpos2 = line.find(")") | |
if parenpos > -1 and parenpos2 > -1: | |
methid = int(line[parenpos+1:parenpos2]) | |
lrc2, ro, lre2 = x["set-int-prop", str(c.id), str(methid), "8", "0", "0", "1"].run(retcode=None) | |
if lrc2 != 0: | |
raise Exception(lre2) | |
return 0 | |
if __name__ == "__main__": | |
rc = 0 | |
err = "" | |
try: | |
rc = main() | |
except SystemExit as e1: | |
err = str(e1) | |
i = 0 | |
try: | |
i = int(err) | |
except ValueError: | |
i = 2 | |
rc = i | |
except Exception as e2: | |
i = 3 | |
err = str(e2) | |
if rc != 0: | |
print("Error:\nerrcode: {}\nerrmessage: {}".format(rc, err)) | |
exit(rc) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment