diff options
Diffstat (limited to 'sway/input')
-rw-r--r-- | sway/input/switch.c | 57 |
1 files changed, 40 insertions, 17 deletions
diff --git a/sway/input/switch.c b/sway/input/switch.c index d825c5c3..72d1245f 100644 --- a/sway/input/switch.c +++ b/sway/input/switch.c | |||
@@ -13,39 +13,30 @@ struct sway_switch *sway_switch_create(struct sway_seat *seat, | |||
13 | } | 13 | } |
14 | device->switch_device = switch_device; | 14 | device->switch_device = switch_device; |
15 | switch_device->seat_device = device; | 15 | switch_device->seat_device = device; |
16 | switch_device->state = WLR_SWITCH_STATE_OFF; | ||
16 | wl_list_init(&switch_device->switch_toggle.link); | 17 | wl_list_init(&switch_device->switch_toggle.link); |
17 | sway_log(SWAY_DEBUG, "Allocated switch for device"); | 18 | sway_log(SWAY_DEBUG, "Allocated switch for device"); |
18 | 19 | ||
19 | return switch_device; | 20 | return switch_device; |
20 | } | 21 | } |
21 | 22 | ||
22 | static void handle_switch_toggle(struct wl_listener *listener, void *data) { | 23 | static void execute_binding(struct sway_switch *sway_switch) { |
23 | struct sway_switch *sway_switch = | ||
24 | wl_container_of(listener, sway_switch, switch_toggle); | ||
25 | struct sway_seat* seat = sway_switch->seat_device->sway_seat; | 24 | struct sway_seat* seat = sway_switch->seat_device->sway_seat; |
26 | struct wlr_seat *wlr_seat = seat->wlr_seat; | ||
27 | struct wlr_input_device *wlr_device = | ||
28 | sway_switch->seat_device->input_device->wlr_device; | ||
29 | |||
30 | wlr_idle_notify_activity(server.idle, wlr_seat); | ||
31 | bool input_inhibited = seat->exclusive_client != NULL; | 25 | bool input_inhibited = seat->exclusive_client != NULL; |
32 | 26 | ||
33 | char *device_identifier = input_device_get_identifier(wlr_device); | ||
34 | |||
35 | struct wlr_event_switch_toggle *event = data; | ||
36 | enum wlr_switch_type type = event->switch_type; | ||
37 | enum wlr_switch_state state = event->switch_state; | ||
38 | sway_log(SWAY_DEBUG, "%s: type %d state %d", device_identifier, type, state); | ||
39 | |||
40 | list_t *bindings = config->current_mode->switch_bindings; | 27 | list_t *bindings = config->current_mode->switch_bindings; |
41 | struct sway_switch_binding *matched_binding = NULL; | 28 | struct sway_switch_binding *matched_binding = NULL; |
42 | for (int i = 0; i < bindings->length; ++i) { | 29 | for (int i = 0; i < bindings->length; ++i) { |
43 | struct sway_switch_binding *binding = bindings->items[i]; | 30 | struct sway_switch_binding *binding = bindings->items[i]; |
44 | if (binding->type != type) { | 31 | if (binding->type != sway_switch->type) { |
45 | continue; | 32 | continue; |
46 | } | 33 | } |
47 | if (binding->state != WLR_SWITCH_STATE_TOGGLE && | 34 | if (binding->state != WLR_SWITCH_STATE_TOGGLE && |
48 | binding->state != state) { | 35 | binding->state != sway_switch->state) { |
36 | continue; | ||
37 | } | ||
38 | if (config->reloading && (binding->state == WLR_SWITCH_STATE_TOGGLE | ||
39 | || (binding->flags & BINDING_RELOAD) == 0)) { | ||
49 | continue; | 40 | continue; |
50 | } | 41 | } |
51 | bool binding_locked = binding->flags & BINDING_LOCKED; | 42 | bool binding_locked = binding->flags & BINDING_LOCKED; |
@@ -73,7 +64,25 @@ static void handle_switch_toggle(struct wl_listener *listener, void *data) { | |||
73 | 64 | ||
74 | transaction_commit_dirty(); | 65 | transaction_commit_dirty(); |
75 | 66 | ||
67 | } | ||
68 | |||
69 | static void handle_switch_toggle(struct wl_listener *listener, void *data) { | ||
70 | struct sway_switch *sway_switch = | ||
71 | wl_container_of(listener, sway_switch, switch_toggle); | ||
72 | struct wlr_event_switch_toggle *event = data; | ||
73 | struct wlr_seat* wlr_seat = sway_switch->seat_device->sway_seat->wlr_seat; | ||
74 | wlr_idle_notify_activity(server.idle, wlr_seat); | ||
75 | |||
76 | struct wlr_input_device *wlr_device = | ||
77 | sway_switch->seat_device->input_device->wlr_device; | ||
78 | char *device_identifier = input_device_get_identifier(wlr_device); | ||
79 | sway_log(SWAY_DEBUG, "%s: type %d state %d", device_identifier, | ||
80 | event->switch_type, event->switch_state); | ||
76 | free(device_identifier); | 81 | free(device_identifier); |
82 | |||
83 | sway_switch->type = event->switch_type; | ||
84 | sway_switch->state = event->switch_state; | ||
85 | execute_binding(sway_switch); | ||
77 | } | 86 | } |
78 | 87 | ||
79 | void sway_switch_configure(struct sway_switch *sway_switch) { | 88 | void sway_switch_configure(struct sway_switch *sway_switch) { |
@@ -93,3 +102,17 @@ void sway_switch_destroy(struct sway_switch *sway_switch) { | |||
93 | wl_list_remove(&sway_switch->switch_toggle.link); | 102 | wl_list_remove(&sway_switch->switch_toggle.link); |
94 | free(sway_switch); | 103 | free(sway_switch); |
95 | } | 104 | } |
105 | |||
106 | void sway_switch_retrigger_bindings_for_all(void) { | ||
107 | struct sway_seat *seat; | ||
108 | wl_list_for_each(seat, &server.input->seats, link) { | ||
109 | struct sway_seat_device *seat_device; | ||
110 | wl_list_for_each(seat_device, &seat->devices, link) { | ||
111 | struct sway_input_device *input_device = seat_device->input_device; | ||
112 | if (input_device->wlr_device->type != WLR_INPUT_DEVICE_SWITCH) { | ||
113 | continue; | ||
114 | } | ||
115 | execute_binding(seat_device->switch_device); | ||
116 | }; | ||
117 | } | ||
118 | } | ||