scripts/huion-tablet-x11.py

64 lines
1.8 KiB
Python
Executable file

#!/usr/bin/env python3
# Set Huion H430P parameters from saved profiles using xsetwacom
# Driver: https://github.com/DIGImend/digimend-kernel-drivers
#
# Write your config into ~/.config/huion-tablet-yml
# Example:
#
# presets:
# my-preset:
# screen: DP2-2
# area: 0 0 24384 15240
# buttons:
# pad:
# 1: key Ctrl Z
# 2: key Ctrl Shift Z
# 3: key +
# 8: key -
# then run huion-tablet.py my-preset
from subprocess import run
import argparse
import os.path
import yaml
def set_parameter(device, *args):
if device == "stylus":
device = "HUION Huion Tablet Pen stylus"
elif device == "pad":
device = "HUION Huion Tablet Pad pad"
args = map(str, args)
run(["xsetwacom", "set", device, *args], check=True)
parser = argparse.ArgumentParser(description="setup huion h430p tablet")
parser.add_argument("--area", type=str, default="")
parser.add_argument("--screen", type=str, default="")
parser.add_argument("preset", metavar="PRESET", type=str, nargs="?", help="a preset")
args = parser.parse_args()
area = "0 0 24384 15240"
screen = ""
if args.preset is not None:
with open(os.path.expanduser("~/.config/huion-tablet.yml"), "r") as f:
config = yaml.load(f, Loader=yaml.SafeLoader)
preset = config["presets"][args.preset]
area = preset["area"]
screen = preset["screen"]
if "buttons" in preset:
for device in preset["buttons"]:
for button, mapping in preset["buttons"][device].items():
set_parameter(device, "button", button, *str(mapping).split(" "))
if args.area != "":
area = args.area
if args.screen != "":
screen = args.screen
area = tuple(map(int, area.split(" ")))
set_parameter("stylus", "Area", " ".join(map(str, area)))
set_parameter("stylus", "MapToOutput", screen)