Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Last revision Both sides next revision
lehrkraefte:blc:plg:stift [2023/11/03 10:50]
Karlheinz Schubert [Stift bei mehreren Bildschirmen]
lehrkraefte:blc:plg:stift [2024/01/20 10:56]
Karlheinz Schubert
Line 23: Line 23:
 {{lehrkraefte:sbt:map-pen.py}} {{lehrkraefte:sbt:map-pen.py}}
 <code python> <code python>
-#!/usr/bin/python3+#!/usr/bin/env -S python3
  
 import subprocess import subprocess
Line 29: Line 29:
 import sys import sys
  
-displayId = "eDP-1" +# configure you devices: 
-devNames = ["Pen stylus", "Finger touch", "Pen eraser"]+display_id_wayland = "XWAYLAND0" 
 +device_names_wayland = ["xwayland-touch", "xwayland-tablet stylus", "xwayland-tablet eraser", "xwayland-tablet cursor"
 +display_id_x11 = "eDP-1" 
 +device_names_x11 = ["Wacom Pen and multitouch sensor Finger touch", "Wacom Pen and multitouch sensor Pen stylus", "Wacom Pen and multitouch sensor Pen eraser"] 
 +# end configure 
 verbose = False verbose = False
 +
 +
 +def is_wayland():
 +    """check sessiontype (Wayland or X11)"""
 +    ret_value = cmd("echo $XDG_SESSION_TYPE").lower()
 +    return ret_value == "wayland\n"
  
  
 def cmd(c): def cmd(c):
 +    """run shell command and return output, if verbose print command and output"""
     print(c) if verbose else None     print(c) if verbose else None
     res = subprocess.check_output(c, shell=True).decode()     res = subprocess.check_output(c, shell=True).decode()
Line 41: Line 53:
  
  
-def getIDs(dev): +def get_device_id(device_name): 
-    id = re.search( +    """get xinput device id for device name""" 
-        r"id=(\d+)", [l for l in cmd("xinput").split("\n") if re.search(dev, l)][0] +    id = re.search(r"id=(\d+)", [l for l in cmd("xinput").split("\n") if re.search(device_name, l)][0]).group(1) 
-    ).group(1) +    return int(id) if id else 0
-    return id+
  
  
-def setXinputMap(devIddisplayId): +def set_xinput_mapping(device_iddisplay_id): 
-    cmd(f"xinput map-to-output {devId} {displayId}")+    cmd(f"xinput map-to-output {device_id} {display_id}")
  
  
 if __name__ == "__main__": if __name__ == "__main__":
-    args = sys.argv[1:+    try: 
-    if len(args) > 0 and ("-v" in args or "--verbose" in args): +        args = sys.argv[1:
-        verbose = True +        if len(args) > 0 and ("-v" in args or "--verbose" in args): 
-    else: +            verbose = True 
-        print("Use -v or --verbose to see xinput output\nSet mappings:"+        else: 
-    for devName in devNames+            print("Use -v or --verbose to see xinput output\nSet mappings:"
-        devId getIDs(devName+        is_wayland() 
-        print(f"Map '{devName}with Id={devId:02} to '{displayId}'"+        if is_wayland(): 
-        setXinputMap(devIddisplayId+            display_id = display_id_wayland 
- +            device_names = device_names_wayland 
-    print("fiin.")+        else: 
 +            display_id display_id_x11 
 +            device_names = device_names_x11 
 +        name_length = max([len(n) for n in device_names]
 +        for device_name in device_names: 
 +            device_id = get_device_id(device_name) 
 +            print(f" Map {device_name:{name_length}} with Id={device_id:02d} to '{display_id}'"
 +            set_xinput_mapping(device_iddisplay_id
 +    except Exception as e: 
 +        print(e) 
 +    print("") 
 +    input("Press Enter to continue...")
  
 </code> </code>
  • lehrkraefte/blc/plg/stift.txt
  • Last modified: 2024/01/20 10:59
  • by Karlheinz Schubert