Skip to content

Instantly share code, notes, and snippets.

@traverseda
Created August 7, 2023 18:47
Show Gist options
  • Save traverseda/8a416ac2165e591a90d67bd61759ac67 to your computer and use it in GitHub Desktop.
Save traverseda/8a416ac2165e591a90d67bd61759ac67 to your computer and use it in GitHub Desktop.
Disable keyboard and mouse under wayland using evdev
#!/bin/env python3
from pathlib import Path
import os, time, signal
import evdev
pid_file=Path("/tmp/tablet_mode")
devices = [evdev.InputDevice(path) for path in evdev.list_devices()]
print(devices)
boundinputs = (
'AT Translated Set 2 keyboard',
'Elan Touchpad',
)
if not pid_file.exists():
try:
pid_file.write_text(str(os. getpid()))
os.system("kscreen-doctor output.1.rotation.right")
for i in devices:
if i.name in boundinputs:
i.grab()
while True: time.sleep(1)
except:
os.system("kscreen-doctor output.1.rotation.normal")
pid_file.unlink()
else:
pid = os.kill(int(pid_file.read_text()),signal.SIGINT)
# tablet_mode = bool(state_file.read_text())
# if not tablet_mode:
# os.system("kscreen-doctor output.1.rotation.left")
# state_file.write_text("1")
# Path("/sys/devices/pci0000:00/808622C1:05/i2c-2/i2c-ELAN0000:00/input/input4/inhibited").write_text("1")
# # Path("/sys/devices/pci0000:00/808622C1:04/i2c-2/i2c-ELAN0000:00/input/input4/inhibited").write_text("1")
# else:
# os.system("kscreen-doctor output.1.rotation.normal")
# state_file.write_text("")
# Path("/sys/devices/pci0000:00/808622C1:05/i2c-2/i2c-ELAN0000:00/input/input4/inhibited").write_text("0")
# # Path("/sys/devices/pci0000:00/808622C1:04/i2c-2/i2c-ELAN0000:00/input/input4/inhibited").write_text("0")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment