bindings: allow unlocked and locked bindings

This changes the behavior of bindings to make the `BINDING_LOCKED` flag
conflicting, which will allow for both unlocked and locked bindings.

If there are two matching bindings and one has `--locked` and the other
does not, the one with `--locked` will be preferred when locked and
the one without will be preferred when unlocked.

If there are two matching bindings and one has both a matching
`--input-device=<input>` and `--locked` and the other has neither, the
former will be preferred for both unlocked and locked.

This also refactors `get_active_binding` in `sway/input/keyboard.c`
to make it easier to read.
This commit is contained in:
Brian Ashworth 2019-05-30 03:30:08 -04:00 committed by Simon Ser
parent 2c6a10c4ba
commit 6afb392823
4 changed files with 67 additions and 26 deletions

View file

@ -38,6 +38,7 @@ static void handle_switch_toggle(struct wl_listener *listener, void *data) {
sway_log(SWAY_DEBUG, "%s: type %d state %d", device_identifier, type, state);
list_t *bindings = config->current_mode->switch_bindings;
struct sway_switch_binding *matched_binding = NULL;
for (int i = 0; i < bindings->length; ++i) {
struct sway_switch_binding *binding = bindings->items[i];
if (binding->type != type) {
@ -52,10 +53,19 @@ static void handle_switch_toggle(struct wl_listener *listener, void *data) {
continue;
}
struct sway_binding *dummy_binding = calloc(1, sizeof(struct sway_binding));
matched_binding = binding;
if (binding_locked == input_inhibited) {
break;
}
}
if (matched_binding) {
struct sway_binding *dummy_binding =
calloc(1, sizeof(struct sway_binding));
dummy_binding->type = BINDING_SWITCH;
dummy_binding->flags = binding->flags;
dummy_binding->command = binding->command;
dummy_binding->flags = matched_binding->flags;
dummy_binding->command = matched_binding->command;
seat_execute_command(seat, dummy_binding);
free(dummy_binding);