Make huion-tablet compatible with wayland

This commit is contained in:
Simon Bruder 2020-08-28 16:42:29 +02:00
parent ecd7808dd1
commit 31319baa22
No known key found for this signature in database
GPG key ID: 6F03E0000CC5B62F
2 changed files with 94 additions and 44 deletions

63
huion-tablet-x11.py Executable file
View file

@ -0,0 +1,63 @@
#!/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)

View file

@ -1,63 +1,50 @@
#!/usr/bin/env python3
# Set Huion H430P parameters from saved profiles using xsetwacom
# Driver: https://github.com/DIGImend/digimend-kernel-drivers
#!/usr/bin/env nix-shell
#!nix-shell -i python3 -p "python3.withPackages(ps: [ ps.pyyaml ])"
# Set Huion H430P parameters from saved profiles using swaymsg
#
# Write your config into ~/.config/huion-tablet-yml
# This currently only works for setting the screen and area but not for setting
# the buttons.
#
# 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 -
# screen: DP-4
# area: 0 0 1 1
#
# then run huion-tablet.py my-preset
from subprocess import run
import argparse
import os.path
import sys
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"
def _set_parameter(parameter, *args):
args = map(str, args)
run(["xsetwacom", "set", device, *args], check=True)
run(
["swaymsg", "input", "9580:109:HUION_Huion_Tablet_Pen", parameter, *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()
def map_to_output(identifier):
_set_parameter("map_to_output", identifier)
area = "0 0 24384 15240"
screen = ""
if args.preset is not None:
with open(os.path.expanduser("~/.config/huion-tablet.yml"), "r") as f:
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/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(" "))
preset = config["presets"][preset]
if args.area != "":
area = args.area
if args.screen != "":
screen = args.screen
area = list(map(float, preset["area"].split(" ")))
assert len(area) == 4
screen = preset["screen"]
area = tuple(map(int, area.split(" ")))
set_parameter("stylus", "Area", " ".join(map(str, area)))
set_parameter("stylus", "MapToOutput", screen)
map_to_output(screen)
map_from_region(*area)