aboutsummaryrefslogtreecommitdiffstats
path: root/sway/input/switch.c
diff options
context:
space:
mode:
Diffstat (limited to 'sway/input/switch.c')
-rw-r--r--sway/input/switch.c38
1 files changed, 22 insertions, 16 deletions
diff --git a/sway/input/switch.c b/sway/input/switch.c
index b7c28df1..831f4dbf 100644
--- a/sway/input/switch.c
+++ b/sway/input/switch.c
@@ -1,7 +1,5 @@
1#include "sway/config.h" 1#include "sway/config.h"
2#include "sway/desktop/transaction.h"
3#include "sway/input/switch.h" 2#include "sway/input/switch.h"
4#include <wlr/types/wlr_idle.h>
5#include "log.h" 3#include "log.h"
6 4
7struct sway_switch *sway_switch_create(struct sway_seat *seat, 5struct sway_switch *sway_switch_create(struct sway_seat *seat,
@@ -12,6 +10,7 @@ struct sway_switch *sway_switch_create(struct sway_seat *seat,
12 return NULL; 10 return NULL;
13 } 11 }
14 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);
15 switch_device->seat_device = device; 14 switch_device->seat_device = device;
16 switch_device->state = WLR_SWITCH_STATE_OFF; 15 switch_device->state = WLR_SWITCH_STATE_OFF;
17 wl_list_init(&switch_device->switch_toggle.link); 16 wl_list_init(&switch_device->switch_toggle.link);
@@ -20,9 +19,22 @@ struct sway_switch *sway_switch_create(struct sway_seat *seat,
20 return switch_device; 19 return switch_device;
21} 20}
22 21
22static 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
23static void execute_binding(struct sway_switch *sway_switch) { 35static void execute_binding(struct sway_switch *sway_switch) {
24 struct sway_seat* seat = sway_switch->seat_device->sway_seat; 36 struct sway_seat *seat = sway_switch->seat_device->sway_seat;
25 bool input_inhibited = seat->exclusive_client != NULL; 37 bool locked = server.session_lock.lock;
26 38
27 list_t *bindings = config->current_mode->switch_bindings; 39 list_t *bindings = config->current_mode->switch_bindings;
28 struct sway_switch_binding *matched_binding = NULL; 40 struct sway_switch_binding *matched_binding = NULL;
@@ -31,22 +43,21 @@ static void execute_binding(struct sway_switch *sway_switch) {
31 if (binding->type != sway_switch->type) { 43 if (binding->type != sway_switch->type) {
32 continue; 44 continue;
33 } 45 }
34 if (binding->state != WLR_SWITCH_STATE_TOGGLE && 46 if (!sway_switch_trigger_test(binding->trigger, sway_switch->state)) {
35 binding->state != sway_switch->state) {
36 continue; 47 continue;
37 } 48 }
38 if (config->reloading && (binding->state == WLR_SWITCH_STATE_TOGGLE 49 if (config->reloading && (binding->trigger == SWAY_SWITCH_TRIGGER_TOGGLE
39 || (binding->flags & BINDING_RELOAD) == 0)) { 50 || (binding->flags & BINDING_RELOAD) == 0)) {
40 continue; 51 continue;
41 } 52 }
42 bool binding_locked = binding->flags & BINDING_LOCKED; 53 bool binding_locked = binding->flags & BINDING_LOCKED;
43 if (!binding_locked && input_inhibited) { 54 if (!binding_locked && locked) {
44 continue; 55 continue;
45 } 56 }
46 57
47 matched_binding = binding; 58 matched_binding = binding;
48 59
49 if (binding_locked == input_inhibited) { 60 if (binding_locked == locked) {
50 break; 61 break;
51 } 62 }
52 } 63 }
@@ -61,15 +72,12 @@ static void execute_binding(struct sway_switch *sway_switch) {
61 seat_execute_command(seat, dummy_binding); 72 seat_execute_command(seat, dummy_binding);
62 free(dummy_binding); 73 free(dummy_binding);
63 } 74 }
64
65 transaction_commit_dirty();
66
67} 75}
68 76
69static void handle_switch_toggle(struct wl_listener *listener, void *data) { 77static void handle_switch_toggle(struct wl_listener *listener, void *data) {
70 struct sway_switch *sway_switch = 78 struct sway_switch *sway_switch =
71 wl_container_of(listener, sway_switch, switch_toggle); 79 wl_container_of(listener, sway_switch, switch_toggle);
72 struct wlr_event_switch_toggle *event = data; 80 struct wlr_switch_toggle_event *event = data;
73 struct sway_seat *seat = sway_switch->seat_device->sway_seat; 81 struct sway_seat *seat = sway_switch->seat_device->sway_seat;
74 seat_idle_notify_activity(seat, IDLE_SOURCE_SWITCH); 82 seat_idle_notify_activity(seat, IDLE_SOURCE_SWITCH);
75 83
@@ -86,10 +94,8 @@ static void handle_switch_toggle(struct wl_listener *listener, void *data) {
86} 94}
87 95
88void sway_switch_configure(struct sway_switch *sway_switch) { 96void sway_switch_configure(struct sway_switch *sway_switch) {
89 struct wlr_input_device *wlr_device =
90 sway_switch->seat_device->input_device->wlr_device;
91 wl_list_remove(&sway_switch->switch_toggle.link); 97 wl_list_remove(&sway_switch->switch_toggle.link);
92 wl_signal_add(&wlr_device->switch_device->events.toggle, 98 wl_signal_add(&sway_switch->wlr->events.toggle,
93 &sway_switch->switch_toggle); 99 &sway_switch->switch_toggle);
94 sway_switch->switch_toggle.notify = handle_switch_toggle; 100 sway_switch->switch_toggle.notify = handle_switch_toggle;
95 sway_log(SWAY_DEBUG, "Configured switch for device"); 101 sway_log(SWAY_DEBUG, "Configured switch for device");