diff options
Diffstat (limited to 'sway/input/switch.c')
-rw-r--r-- | sway/input/switch.c | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/sway/input/switch.c b/sway/input/switch.c index 9ea87a1a..fc7dfaff 100644 --- a/sway/input/switch.c +++ b/sway/input/switch.c @@ -11,6 +11,7 @@ struct sway_switch *sway_switch_create(struct sway_seat *seat, return NULL; } device->switch_device = switch_device; + switch_device->wlr = wlr_switch_from_input_device(device->input_device->wlr_device); switch_device->seat_device = device; switch_device->state = WLR_SWITCH_STATE_OFF; wl_list_init(&switch_device->switch_toggle.link); @@ -19,9 +20,23 @@ struct sway_switch *sway_switch_create(struct sway_seat *seat, return switch_device; } +static bool sway_switch_trigger_test(enum sway_switch_trigger trigger, + enum wlr_switch_state state) { + switch (trigger) { + case SWAY_SWITCH_TRIGGER_ON: + return state == WLR_SWITCH_STATE_ON; + case SWAY_SWITCH_TRIGGER_OFF: + return state == WLR_SWITCH_STATE_OFF; + case SWAY_SWITCH_TRIGGER_TOGGLE: + return true; + } + abort(); // unreachable +} + static void execute_binding(struct sway_switch *sway_switch) { struct sway_seat* seat = sway_switch->seat_device->sway_seat; - bool input_inhibited = seat->exclusive_client != NULL; + bool input_inhibited = seat->exclusive_client != NULL || + server.session_lock.locked; list_t *bindings = config->current_mode->switch_bindings; struct sway_switch_binding *matched_binding = NULL; @@ -30,11 +45,10 @@ static void execute_binding(struct sway_switch *sway_switch) { if (binding->type != sway_switch->type) { continue; } - if (binding->state != WLR_SWITCH_STATE_TOGGLE && - binding->state != sway_switch->state) { + if (!sway_switch_trigger_test(binding->trigger, sway_switch->state)) { continue; } - if (config->reloading && (binding->state == WLR_SWITCH_STATE_TOGGLE + if (config->reloading && (binding->trigger == SWAY_SWITCH_TRIGGER_TOGGLE || (binding->flags & BINDING_RELOAD) == 0)) { continue; } @@ -65,7 +79,7 @@ static void execute_binding(struct sway_switch *sway_switch) { static void handle_switch_toggle(struct wl_listener *listener, void *data) { struct sway_switch *sway_switch = wl_container_of(listener, sway_switch, switch_toggle); - struct wlr_event_switch_toggle *event = data; + struct wlr_switch_toggle_event *event = data; struct sway_seat *seat = sway_switch->seat_device->sway_seat; seat_idle_notify_activity(seat, IDLE_SOURCE_SWITCH); @@ -82,10 +96,8 @@ static void handle_switch_toggle(struct wl_listener *listener, void *data) { } void sway_switch_configure(struct sway_switch *sway_switch) { - struct wlr_input_device *wlr_device = - sway_switch->seat_device->input_device->wlr_device; wl_list_remove(&sway_switch->switch_toggle.link); - wl_signal_add(&wlr_device->switch_device->events.toggle, + wl_signal_add(&sway_switch->wlr->events.toggle, &sway_switch->switch_toggle); sway_switch->switch_toggle.notify = handle_switch_toggle; sway_log(SWAY_DEBUG, "Configured switch for device"); |