#!/usr/bin/python3 import subprocess import re import sys displayId = "eDP-1" devNames = ["Pen stylus", "Finger touch", "Pen eraser"] verbose = False def cmd(c): print(c) if verbose else None res = subprocess.check_output(c, shell=True).decode() print(res) if verbose else None return res def getIDs(dev): id = re.search( r"id=(\d+)", [l for l in cmd("xinput").split("\n") if re.search(dev, l)][0] ).group(1) return id def setXinputMap(devId, displayId): cmd(f"xinput map-to-output {devId} {displayId}") if __name__ == "__main__": args = sys.argv[1:] if len(args) > 0 and ("-v" in args or "--verbose" in args): verbose = True else: print("Use -v or --verbose to see xinput output\nSet mappings:") nameLength = max([len(n) for n in devNames]) for devName in devNames: devId = getIDs(devName) print(f" - Map {devName:{nameLength}} with Id={devId:02} to '{displayId}'") setXinputMap(devId, displayId) print("")