Make huion-tablet compatible with wayland
This commit is contained in:
parent
ecd7808dd1
commit
31319baa22
63
huion-tablet-x11.py
Executable file
63
huion-tablet-x11.py
Executable 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)
|
|
@ -1,63 +1,50 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env nix-shell
|
||||||
# Set Huion H430P parameters from saved profiles using xsetwacom
|
#!nix-shell -i python3 -p "python3.withPackages(ps: [ ps.pyyaml ])"
|
||||||
# Driver: https://github.com/DIGImend/digimend-kernel-drivers
|
# 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:
|
# Example:
|
||||||
#
|
#
|
||||||
# presets:
|
# presets:
|
||||||
# my-preset:
|
# my-preset:
|
||||||
# screen: DP2-2
|
# screen: DP-4
|
||||||
# area: 0 0 24384 15240
|
# area: 0 0 1 1
|
||||||
# buttons:
|
#
|
||||||
# pad:
|
|
||||||
# 1: key Ctrl Z
|
|
||||||
# 2: key Ctrl Shift Z
|
|
||||||
# 3: key +
|
|
||||||
# 8: key -
|
|
||||||
# then run huion-tablet.py my-preset
|
# then run huion-tablet.py my-preset
|
||||||
|
|
||||||
from subprocess import run
|
from subprocess import run
|
||||||
import argparse
|
|
||||||
import os.path
|
import os.path
|
||||||
|
import sys
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
|
|
||||||
def set_parameter(device, *args):
|
def _set_parameter(parameter, *args):
|
||||||
if device == "stylus":
|
|
||||||
device = "HUION Huion Tablet Pen stylus"
|
|
||||||
elif device == "pad":
|
|
||||||
device = "HUION Huion Tablet Pad pad"
|
|
||||||
args = map(str, 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")
|
def map_to_output(identifier):
|
||||||
parser.add_argument("--area", type=str, default="")
|
_set_parameter("map_to_output", identifier)
|
||||||
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:
|
def map_from_region(x1, y1, x2, y2):
|
||||||
with open(os.path.expanduser("~/.config/huion-tablet.yml"), "r") as f:
|
_set_parameter("map_from_region", f"{x1}x{y1}", f"{x2}x{y2}")
|
||||||
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(" ")))
|
preset = sys.argv[1]
|
||||||
|
|
||||||
set_parameter("stylus", "Area", " ".join(map(str, area)))
|
with open(os.path.expanduser("~/.config/huion-tablet.yml"), "r") as f:
|
||||||
set_parameter("stylus", "MapToOutput", screen)
|
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)
|
||||||
|
|
Loading…
Reference in a new issue