diff options
Diffstat (limited to 'sway/input/switch.c')
-rw-r--r-- | sway/input/switch.c | 34 |
1 files changed, 22 insertions, 12 deletions
diff --git a/sway/input/switch.c b/sway/input/switch.c index 9ea87a1a..831f4dbf 100644 --- a/sway/input/switch.c +++ b/sway/input/switch.c | |||
@@ -1,6 +1,5 @@ | |||
1 | #include "sway/config.h" | 1 | #include "sway/config.h" |
2 | #include "sway/input/switch.h" | 2 | #include "sway/input/switch.h" |
3 | #include <wlr/types/wlr_idle.h> | ||
4 | #include "log.h" | 3 | #include "log.h" |
5 | 4 | ||
6 | struct sway_switch *sway_switch_create(struct sway_seat *seat, | 5 | struct sway_switch *sway_switch_create(struct sway_seat *seat, |
@@ -11,6 +10,7 @@ struct sway_switch *sway_switch_create(struct sway_seat *seat, | |||
11 | return NULL; | 10 | return NULL; |
12 | } | 11 | } |
13 | device->switch_device = switch_device; | 12 | device->switch_device = switch_device; |
13 | switch_device->wlr = wlr_switch_from_input_device(device->input_device->wlr_device); | ||
14 | switch_device->seat_device = device; | 14 | switch_device->seat_device = device; |
15 | switch_device->state = WLR_SWITCH_STATE_OFF; | 15 | switch_device->state = WLR_SWITCH_STATE_OFF; |
16 | wl_list_init(&switch_device->switch_toggle.link); | 16 | wl_list_init(&switch_device->switch_toggle.link); |
@@ -19,9 +19,22 @@ 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 locked = server.session_lock.lock; |
25 | 38 | ||
26 | list_t *bindings = config->current_mode->switch_bindings; | 39 | list_t *bindings = config->current_mode->switch_bindings; |
27 | struct sway_switch_binding *matched_binding = NULL; | 40 | struct sway_switch_binding *matched_binding = NULL; |
@@ -30,22 +43,21 @@ 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 | } |
41 | bool binding_locked = binding->flags & BINDING_LOCKED; | 53 | bool binding_locked = binding->flags & BINDING_LOCKED; |
42 | if (!binding_locked && input_inhibited) { | 54 | if (!binding_locked && locked) { |
43 | continue; | 55 | continue; |
44 | } | 56 | } |
45 | 57 | ||
46 | matched_binding = binding; | 58 | matched_binding = binding; |
47 | 59 | ||
48 | if (binding_locked == input_inhibited) { | 60 | if (binding_locked == locked) { |
49 | break; | 61 | break; |
50 | } | 62 | } |
51 | } | 63 | } |
@@ -65,7 +77,7 @@ static void execute_binding(struct sway_switch *sway_switch) { | |||
65 | static void handle_switch_toggle(struct wl_listener *listener, void *data) { | 77 | static void handle_switch_toggle(struct wl_listener *listener, void *data) { |
66 | struct sway_switch *sway_switch = | 78 | struct sway_switch *sway_switch = |
67 | wl_container_of(listener, sway_switch, switch_toggle); | 79 | wl_container_of(listener, sway_switch, switch_toggle); |
68 | struct wlr_event_switch_toggle *event = data; | 80 | struct wlr_switch_toggle_event *event = data; |
69 | struct sway_seat *seat = sway_switch->seat_device->sway_seat; | 81 | struct sway_seat *seat = sway_switch->seat_device->sway_seat; |
70 | seat_idle_notify_activity(seat, IDLE_SOURCE_SWITCH); | 82 | seat_idle_notify_activity(seat, IDLE_SOURCE_SWITCH); |
71 | 83 | ||
@@ -82,10 +94,8 @@ static void handle_switch_toggle(struct wl_listener *listener, void *data) { | |||
82 | } | 94 | } |
83 | 95 | ||
84 | void sway_switch_configure(struct sway_switch *sway_switch) { | 96 | void sway_switch_configure(struct sway_switch *sway_switch) { |
85 | struct wlr_input_device *wlr_device = | ||
86 | sway_switch->seat_device->input_device->wlr_device; | ||
87 | wl_list_remove(&sway_switch->switch_toggle.link); | 97 | wl_list_remove(&sway_switch->switch_toggle.link); |
88 | wl_signal_add(&wlr_device->switch_device->events.toggle, | 98 | wl_signal_add(&sway_switch->wlr->events.toggle, |
89 | &sway_switch->switch_toggle); | 99 | &sway_switch->switch_toggle); |
90 | sway_switch->switch_toggle.notify = handle_switch_toggle; | 100 | sway_switch->switch_toggle.notify = handle_switch_toggle; |
91 | sway_log(SWAY_DEBUG, "Configured switch for device"); | 101 | sway_log(SWAY_DEBUG, "Configured switch for device"); |