diff --git a/include/sway/config.h b/include/sway/config.h index fda0e83f..538930f2 100644 --- a/include/sway/config.h +++ b/include/sway/config.h @@ -70,12 +70,18 @@ struct sway_mouse_binding { char *command; }; +enum sway_switch_trigger { + SWAY_SWITCH_TRIGGER_OFF, + SWAY_SWITCH_TRIGGER_ON, + SWAY_SWITCH_TRIGGER_TOGGLE, +}; + /** * A laptop switch binding and an associated command. */ struct sway_switch_binding { enum wlr_switch_type type; - enum wlr_switch_state state; + enum sway_switch_trigger trigger; uint32_t flags; char *command; }; diff --git a/sway/commands/bind.c b/sway/commands/bind.c index 25be415e..26c99e63 100644 --- a/sway/commands/bind.c +++ b/sway/commands/bind.c @@ -47,7 +47,7 @@ static bool binding_switch_compare(struct sway_switch_binding *binding_a, if (binding_a->type != binding_b->type) { return false; } - if (binding_a->state != binding_b->state) { + if (binding_a->trigger != binding_b->trigger) { return false; } if ((binding_a->flags & BINDING_LOCKED) != @@ -551,11 +551,11 @@ struct cmd_results *cmd_bind_or_unbind_switch(int argc, char **argv, "unknown switch %s)", bindtype, split->items[0]); } if (strcmp(split->items[1], "on") == 0) { - binding->state = WLR_SWITCH_STATE_ON; + binding->trigger = SWAY_SWITCH_TRIGGER_ON; } else if (strcmp(split->items[1], "off") == 0) { - binding->state = WLR_SWITCH_STATE_OFF; + binding->trigger = SWAY_SWITCH_TRIGGER_OFF; } else if (strcmp(split->items[1], "toggle") == 0) { - binding->state = WLR_SWITCH_STATE_TOGGLE; + binding->trigger = SWAY_SWITCH_TRIGGER_TOGGLE; } else { free_switch_binding(binding); return cmd_results_new(CMD_FAILURE, diff --git a/sway/input/switch.c b/sway/input/switch.c index 9ea87a1a..fc296d18 100644 --- a/sway/input/switch.c +++ b/sway/input/switch.c @@ -19,6 +19,19 @@ struct sway_switch *sway_switch_create(struct sway_seat *seat, return switch_device; } +static bool sway_switch_trigger_test(enum sway_switch_trigger trigger, + enum wlr_switch_state state) { + switch (trigger) { + case SWAY_SWITCH_TRIGGER_ON: + return state == WLR_SWITCH_STATE_ON; + case SWAY_SWITCH_TRIGGER_OFF: + return state == WLR_SWITCH_STATE_OFF; + case SWAY_SWITCH_TRIGGER_TOGGLE: + return true; + } + abort(); // unreachable +} + static void execute_binding(struct sway_switch *sway_switch) { struct sway_seat* seat = sway_switch->seat_device->sway_seat; bool input_inhibited = seat->exclusive_client != NULL; @@ -30,11 +43,10 @@ static void execute_binding(struct sway_switch *sway_switch) { if (binding->type != sway_switch->type) { continue; } - if (binding->state != WLR_SWITCH_STATE_TOGGLE && - binding->state != sway_switch->state) { + if (!sway_switch_trigger_test(binding->trigger, sway_switch->state)) { continue; } - if (config->reloading && (binding->state == WLR_SWITCH_STATE_TOGGLE + if (config->reloading && (binding->trigger == SWAY_SWITCH_TRIGGER_TOGGLE || (binding->flags & BINDING_RELOAD) == 0)) { continue; }