lehrkraefte:blc:plg:stift

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
lehrkraefte:blc:plg:stift [2023/11/03 10:59]
Karlheinz Schubert [Stift bei mehreren Bildschirmen]
lehrkraefte:blc:plg:stift [2024/01/20 10:59] (current)
Karlheinz Schubert
Line 21: Line 21:
 Folgendes Python-Script behebt das Problem, indem es den Stift nur auf den TouchScreen des Laptops (eDP-1) mapped:  Folgendes Python-Script behebt das Problem, indem es den Stift nur auf den TouchScreen des Laptops (eDP-1) mapped: 
  
-{{lehrkraefte:sbt:map-pen.py}}+{{lehrkreafte: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: 
-         +            print("Use -v or --verbose to see xinput output\nSet mappings:"
-    nameLength = max([len(n) for n in devNames]) +        is_wayland() 
-    for devName in devNames+        if is_wayland(): 
-        devId getIDs(devName+            display_id = display_id_wayland 
-        print(f" - Map {devName:{nameLength}} with Id={devId:02} to '{displayId}'"+            device_names = device_names_wayland 
-        setXinputMap(devIddisplayId+        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("")     print("")
 +    input("Press Enter to continue...")
 +
 </code> </code>
  
 Mit --verbose (oder -v) aufrufen, um //xinput// Ausgaben zu zeigen. Mit --verbose (oder -v) aufrufen, um //xinput// Ausgaben zu zeigen.
 </hidden> </hidden>
  • lehrkraefte/blc/plg/stift.1699005586.txt.gz
  • Last modified: 2023/11/03 10:59
  • by Karlheinz Schubert