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.c32
1 files changed, 20 insertions, 12 deletions
diff --git a/sway/input/switch.c b/sway/input/switch.c
index b7c28df1..fc7dfaff 100644
--- a/sway/input/switch.c
+++ b/sway/input/switch.c
@@ -1,5 +1,4 @@
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> 3#include <wlr/types/wlr_idle.h>
5#include "log.h" 4#include "log.h"
@@ -12,6 +11,7 @@ struct sway_switch *sway_switch_create(struct sway_seat *seat,
12 return NULL; 11 return NULL;
13 } 12 }
14 device->switch_device = switch_device; 13 device->switch_device = switch_device;
14 switch_device->wlr = wlr_switch_from_input_device(device->input_device->wlr_device);
15 switch_device->seat_device = device; 15 switch_device->seat_device = device;
16 switch_device->state = WLR_SWITCH_STATE_OFF; 16 switch_device->state = WLR_SWITCH_STATE_OFF;
17 wl_list_init(&switch_device->switch_toggle.link); 17 wl_list_init(&switch_device->switch_toggle.link);
@@ -20,9 +20,23 @@ struct sway_switch *sway_switch_create(struct sway_seat *seat,
20 return switch_device; 20 return switch_device;
21} 21}
22 22
23static bool sway_switch_trigger_test(enum sway_switch_trigger trigger,
24 enum wlr_switch_state state) {
25 switch (trigger) {
26 case SWAY_SWITCH_TRIGGER_ON:
27 return state == WLR_SWITCH_STATE_ON;
28 case SWAY_SWITCH_TRIGGER_OFF:
29 return state == WLR_SWITCH_STATE_OFF;
30 case SWAY_SWITCH_TRIGGER_TOGGLE:
31 return true;
32 }
33 abort(); // unreachable
34}
35
23static void execute_binding(struct sway_switch *sway_switch) { 36static void execute_binding(struct sway_switch *sway_switch) {
24 struct sway_seat* seat = sway_switch->seat_device->sway_seat; 37 struct sway_seat* seat = sway_switch->seat_device->sway_seat;
25 bool input_inhibited = seat->exclusive_client != NULL; 38 bool input_inhibited = seat->exclusive_client != NULL ||
39 server.session_lock.locked;
26 40
27 list_t *bindings = config->current_mode->switch_bindings; 41 list_t *bindings = config->current_mode->switch_bindings;
28 struct sway_switch_binding *matched_binding = NULL; 42 struct sway_switch_binding *matched_binding = NULL;
@@ -31,11 +45,10 @@ static void execute_binding(struct sway_switch *sway_switch) {
31 if (binding->type != sway_switch->type) { 45 if (binding->type != sway_switch->type) {
32 continue; 46 continue;
33 } 47 }
34 if (binding->state != WLR_SWITCH_STATE_TOGGLE && 48 if (!sway_switch_trigger_test(binding->trigger, sway_switch->state)) {
35 binding->state != sway_switch->state) {
36 continue; 49 continue;
37 } 50 }
38 if (config->reloading && (binding->state == WLR_SWITCH_STATE_TOGGLE 51 if (config->reloading && (binding->trigger == SWAY_SWITCH_TRIGGER_TOGGLE
39 || (binding->flags & BINDING_RELOAD) == 0)) { 52 || (binding->flags & BINDING_RELOAD) == 0)) {
40 continue; 53 continue;
41 } 54 }
@@ -61,15 +74,12 @@ static void execute_binding(struct sway_switch *sway_switch) {
61 seat_execute_command(seat, dummy_binding); 74 seat_execute_command(seat, dummy_binding);
62 free(dummy_binding); 75 free(dummy_binding);
63 } 76 }
64
65 transaction_commit_dirty();
66
67} 77}
68 78
69static void handle_switch_toggle(struct wl_listener *listener, void *data) { 79static void handle_switch_toggle(struct wl_listener *listener, void *data) {
70 struct sway_switch *sway_switch = 80 struct sway_switch *sway_switch =
71 wl_container_of(listener, sway_switch, switch_toggle); 81 wl_container_of(listener, sway_switch, switch_toggle);
72 struct wlr_event_switch_toggle *event = data; 82 struct wlr_switch_toggle_event *event = data;
73 struct sway_seat *seat = sway_switch->seat_device->sway_seat; 83 struct sway_seat *seat = sway_switch->seat_device->sway_seat;
74 seat_idle_notify_activity(seat, IDLE_SOURCE_SWITCH); 84 seat_idle_notify_activity(seat, IDLE_SOURCE_SWITCH);
75 85
@@ -86,10 +96,8 @@ static void handle_switch_toggle(struct wl_listener *listener, void *data) {
86} 96}
87 97
88void sway_switch_configure(struct sway_switch *sway_switch) { 98void 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); 99 wl_list_remove(&sway_switch->switch_toggle.link);
92 wl_signal_add(&wlr_device->switch_device->events.toggle, 100 wl_signal_add(&sway_switch->wlr->events.toggle,
93 &sway_switch->switch_toggle); 101 &sway_switch->switch_toggle);
94 sway_switch->switch_toggle.notify = handle_switch_toggle; 102 sway_switch->switch_toggle.notify = handle_switch_toggle;
95 sway_log(SWAY_DEBUG, "Configured switch for device"); 103 sway_log(SWAY_DEBUG, "Configured switch for device");