#!/usr/bin/env cached-nix-shell #!nix-shell -i python3 -p "python3.withPackages(ps: [ ps.pyyaml ])" # Set Digitizer parameters from saved profiles using swaymsg # # This currently only works for setting the screen and area but not for setting # the buttons. # # Write your config into ~/.config/tabletcfg.yml # Example: # # presets: # my-preset: # screen: DP-4 # area: 0 0 1 1 # # then run tabletcfg.py my-preset from subprocess import run import os.path import sys import yaml def _set_parameter(parameter, *args): args = map(str, args) run( ["swaymsg", "input", "type:tablet_tool", parameter, *args], check=True, ) def map_to_output(identifier): _set_parameter("map_to_output", identifier) def map_from_region(x1, y1, x2, y2): _set_parameter("map_from_region", f"{x1}x{y1}", f"{x2}x{y2}") preset = sys.argv[1] with open(os.path.expanduser("~/.config/tabletcfg.yml"), "r") as f: config = yaml.load(f, Loader=yaml.SafeLoader) preset = config["presets"][preset] area = list(map(float, preset["area"].split(" "))) assert len(area) == 4 screen = preset["screen"] map_to_output(screen) map_from_region(*area)