@@ -577,6 +577,52 @@ 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+ This action is only available on styli with an eraser button, not on
596+ styli with an eraser at the other end of the stylus.
597+ """
598+ if action == "keybinding" :
599+ if keybinding is None :
600+ msg = "Keybinding must be provided for action keybinding"
601+ raise click .UsageError (msg )
602+ else : # noqa: PLR5501
603+ if keybinding is not None :
604+ msg = "Keybinding is only valid for action keybinding"
605+ raise click .UsageError (msg )
606+
607+ settings = ctx .obj
608+
609+ if not settings .has_key ("eraser-button-mode" ):
610+ click .secho ("Eraser button mapping requires GNOME 50 or later, aborting" )
611+ return
612+
613+ if keybinding is not None :
614+ settings .set_string ("eraser-button-keybinding" , keybinding )
615+
616+ if action == "eraser" :
617+ settings .set_enum ("eraser-button-mode" , 0 )
618+ else :
619+ val = {"left" : 0 , "middle" : 1 , "right" : 2 , "back" : 3 , "forward" : 4 , "switch-monitor" : 5 , "keybinding" : 6 }[
620+ action
621+ ]
622+ settings .set_enum ("eraser-button-action" , val )
623+ settings .set_enum ("eraser-button-mode" , 1 )
624+
625+
580626def main ():
581627 gsetwacom ()
582628
0 commit comments