Skip to content

Commit 8432136

Browse files
committed
Add support for eraser button mappings
1 parent 99c9a86 commit 8432136

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

src/gsetwacom/__init__.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,49 @@ def stylus_set_button_action(ctx, button: str, action: str, keybinding: str | No
577577
settings.set_enum(key, val)
578578

579579

580+
@stylus.command(name="set-eraser-button-action")
581+
@click.argument(
582+
"action",
583+
type=click.Choice(["eraser", "left", "middle", "right", "back", "forward", "switch-monitor", "keybinding"]),
584+
)
585+
@click.argument(
586+
"keybinding",
587+
type=str,
588+
required=False,
589+
)
590+
@click.pass_context
591+
def stylus_eraser_set_button_action(ctx, action: str, keybinding: str | None):
592+
"""
593+
Change the eraser button action of this stylus.
594+
"""
595+
if action == "keybinding":
596+
if keybinding is None:
597+
msg = "Keybinding must be provided for action keybinding"
598+
raise click.UsageError(msg)
599+
else: # noqa: PLR5501
600+
if keybinding is not None:
601+
msg = "Keybinding is only valid for action keybinding"
602+
raise click.UsageError(msg)
603+
604+
settings = ctx.obj
605+
606+
if not settings.has_key("eraser-button-mode"):
607+
click.secho("Eraser button mapping requires GNOME 50 or later, aborting")
608+
return
609+
610+
if keybinding is not None:
611+
settings.set_string("eraser-button-keybinding", keybinding)
612+
613+
if action == "eraser":
614+
settings.set_enum("eraser-button-mode", 0)
615+
else:
616+
val = {"left": 0, "middle": 1, "right": 2, "back": 3, "forward": 4, "switch-monitor": 5, "keybinding": 6}[
617+
action
618+
]
619+
settings.set_enum("eraser-button-action", val)
620+
settings.set_enum("eraser-button-mode", 1)
621+
622+
580623
def main():
581624
gsetwacom()
582625

0 commit comments

Comments
 (0)