diff options
-rw-r--r-- | include/sway/config.h | 8 | ||||
-rw-r--r-- | sway/commands/bind.c | 8 | ||||
-rw-r--r-- | sway/input/switch.c | 18 |
3 files changed, 26 insertions, 8 deletions
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 { | |||
70 | char *command; | 70 | char *command; |
71 | }; | 71 | }; |
72 | 72 | ||
73 | enum sway_switch_trigger { | ||
74 | SWAY_SWITCH_TRIGGER_OFF, | ||
75 | SWAY_SWITCH_TRIGGER_ON, | ||
76 | SWAY_SWITCH_TRIGGER_TOGGLE, | ||
77 | }; | ||
78 | |||
73 | /** | 79 | /** |
74 | * A laptop switch binding and an associated command. | 80 | * A laptop switch binding and an associated command. |
75 | */ | 81 | */ |
76 | struct sway_switch_binding { | 82 | struct sway_switch_binding { |
77 | enum wlr_switch_type type; | 83 | enum wlr_switch_type type; |
78 | enum wlr_switch_state state; | 84 | enum sway_switch_trigger trigger; |
79 | uint32_t flags; | 85 | uint32_t flags; |
80 | char *command; | 86 | char *command; |
81 | }; | 87 | }; |
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, | |||
47 | if (binding_a->type != binding_b->type) { | 47 | if (binding_a->type != binding_b->type) { |
48 | return false; | 48 | return false; |
49 | } | 49 | } |
50 | if (binding_a->state != binding_b->state) { | 50 | if (binding_a->trigger != binding_b->trigger) { |
51 | return false; | 51 | return false; |
52 | } | 52 | } |
53 | if ((binding_a->flags & BINDING_LOCKED) != | 53 | if ((binding_a->flags & BINDING_LOCKED) != |
@@ -551,11 +551,11 @@ struct cmd_results *cmd_bind_or_unbind_switch(int argc, char **argv, | |||
551 | "unknown switch %s)", bindtype, split->items[0]); | 551 | "unknown switch %s)", bindtype, split->items[0]); |
552 | } | 552 | } |
553 | if (strcmp(split->items[1], "on") == 0) { | 553 | if (strcmp(split->items[1], "on") == 0) { |
554 | binding->state = WLR_SWITCH_STATE_ON; | 554 | binding->trigger = SWAY_SWITCH_TRIGGER_ON; |
555 | } else if (strcmp(split->items[1], "off") == 0) { | 555 | } else if (strcmp(split->items[1], "off") == 0) { |
556 | binding->state = WLR_SWITCH_STATE_OFF; | 556 | binding->trigger = SWAY_SWITCH_TRIGGER_OFF; |
557 | } else if (strcmp(split->items[1], "toggle") == 0) { | 557 | } else if (strcmp(split->items[1], "toggle") == 0) { |
558 | binding->state = WLR_SWITCH_STATE_TOGGLE; | 558 | binding->trigger = SWAY_SWITCH_TRIGGER_TOGGLE; |
559 | } else { | 559 | } else { |
560 | free_switch_binding(binding); | 560 | free_switch_binding(binding); |
561 | return cmd_results_new(CMD_FAILURE, | 561 | 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, | |||
19 | return switch_device; | 19 | return switch_device; |
20 | } | 20 | } |
21 | 21 | ||
22 | static bool sway_switch_trigger_test(enum sway_switch_trigger trigger, | ||
23 | enum wlr_switch_state state) { | ||
24 | switch (trigger) { | ||
25 | case SWAY_SWITCH_TRIGGER_ON: | ||
26 | return state == WLR_SWITCH_STATE_ON; | ||
27 | case SWAY_SWITCH_TRIGGER_OFF: | ||
28 | return state == WLR_SWITCH_STATE_OFF; | ||
29 | case SWAY_SWITCH_TRIGGER_TOGGLE: | ||
30 | return true; | ||
31 | } | ||
32 | abort(); // unreachable | ||
33 | } | ||
34 | |||
22 | static void execute_binding(struct sway_switch *sway_switch) { | 35 | static void execute_binding(struct sway_switch *sway_switch) { |
23 | struct sway_seat* seat = sway_switch->seat_device->sway_seat; | 36 | struct sway_seat* seat = sway_switch->seat_device->sway_seat; |
24 | bool input_inhibited = seat->exclusive_client != NULL; | 37 | bool input_inhibited = seat->exclusive_client != NULL; |
@@ -30,11 +43,10 @@ static void execute_binding(struct sway_switch *sway_switch) { | |||
30 | if (binding->type != sway_switch->type) { | 43 | if (binding->type != sway_switch->type) { |
31 | continue; | 44 | continue; |
32 | } | 45 | } |
33 | if (binding->state != WLR_SWITCH_STATE_TOGGLE && | 46 | if (!sway_switch_trigger_test(binding->trigger, sway_switch->state)) { |
34 | binding->state != sway_switch->state) { | ||
35 | continue; | 47 | continue; |
36 | } | 48 | } |
37 | if (config->reloading && (binding->state == WLR_SWITCH_STATE_TOGGLE | 49 | if (config->reloading && (binding->trigger == SWAY_SWITCH_TRIGGER_TOGGLE |
38 | || (binding->flags & BINDING_RELOAD) == 0)) { | 50 | || (binding->flags & BINDING_RELOAD) == 0)) { |
39 | continue; | 51 | continue; |
40 | } | 52 | } |