diff options
Diffstat (limited to 'sway/input')
-rw-r--r-- | sway/input/input-manager.c | 25 | ||||
-rw-r--r-- | sway/input/seat.c | 27 |
2 files changed, 32 insertions, 20 deletions
diff --git a/sway/input/input-manager.c b/sway/input/input-manager.c index 4f3c3ee5..d9d20200 100644 --- a/sway/input/input-manager.c +++ b/sway/input/input-manager.c @@ -83,7 +83,8 @@ static struct sway_input_device *input_sway_device_from_wlr( static bool input_has_seat_configuration(struct sway_input_manager *input) { struct sway_seat *seat = NULL; wl_list_for_each(seat, &input->seats, link) { - if (seat->config) { + struct seat_config *seat_config = seat_get_config(seat); + if (seat_config) { return true; } } @@ -225,11 +226,13 @@ static void handle_new_input(struct wl_listener *listener, void *data) { return; } + struct seat_config *seat_config = seat_get_config(seat); + bool added = false; wl_list_for_each(seat, &input->seats, link) { - bool has_attachment = seat->config && - (seat_config_get_attachment(seat->config, input_device->identifier) || - seat_config_get_attachment(seat->config, "*")); + bool has_attachment = config && + (seat_config_get_attachment(seat_config, input_device->identifier) || + seat_config_get_attachment(seat_config, "*")); if (has_attachment) { seat_add_device(seat, input_device); @@ -239,7 +242,7 @@ static void handle_new_input(struct wl_listener *listener, void *data) { if (!added) { wl_list_for_each(seat, &input->seats, link) { - if (seat->config && seat->config->fallback == 1) { + if (seat_config && seat_config->fallback == 1) { seat_add_device(seat, input_device); added = true; } @@ -326,7 +329,7 @@ void input_manager_apply_seat_config(struct sway_input_manager *input, return; } - seat_set_config(seat, seat_config); + seat_apply_config(seat, seat_config); // for every device, try to add it to a seat and if no seat has it // attached, add it to the fallback seats. @@ -335,11 +338,12 @@ void input_manager_apply_seat_config(struct sway_input_manager *input, list_t *seat_list = create_list(); struct sway_seat *seat = NULL; wl_list_for_each(seat, &input->seats, link) { - if (!seat->config) { + struct seat_config *seat_config = seat_get_config(seat); + if (!seat_config) { continue; } - if (seat_config_get_attachment(seat->config, "*") || - seat_config_get_attachment(seat->config, + if (seat_config_get_attachment(seat_config, "*") || + seat_config_get_attachment(seat_config, input_device->identifier)) { list_add(seat_list, seat); } @@ -362,7 +366,8 @@ void input_manager_apply_seat_config(struct sway_input_manager *input, } } else { wl_list_for_each(seat, &input->seats, link) { - if (seat->config && seat->config->fallback == 1) { + struct seat_config *seat_config = seat_get_config(seat); + if (seat_config && seat_config->fallback == 1) { seat_add_device(seat, input_device); } else { seat_remove_device(seat, input_device); diff --git a/sway/input/seat.c b/sway/input/seat.c index c2ecd1c4..91a9e32b 100644 --- a/sway/input/seat.c +++ b/sway/input/seat.c @@ -199,9 +199,11 @@ void seat_configure_device(struct sway_seat *seat, return; } - if (seat->config) { + struct seat_config *seat_config = seat_get_config(seat); + + if (seat_config) { seat_device->attachment_config = - seat_config_get_attachment(seat->config, input_device->identifier); + seat_config_get_attachment(seat_config, input_device->identifier); } switch (input_device->wlr_device->type) { @@ -415,12 +417,8 @@ struct sway_container *seat_get_focus_by_type(struct sway_seat *seat, return container_parent(focus, type); } -void seat_set_config(struct sway_seat *seat, +void seat_apply_config(struct sway_seat *seat, struct seat_config *seat_config) { - // clear configs - free_seat_config(seat->config); - seat->config = NULL; - struct sway_seat_device *seat_device = NULL; wl_list_for_each(seat_device, &seat->devices, link) { seat_device->attachment_config = NULL; @@ -430,10 +428,19 @@ void seat_set_config(struct sway_seat *seat, return; } - // add configs - seat->config = copy_seat_config(seat_config); - wl_list_for_each(seat_device, &seat->devices, link) { seat_configure_device(seat, seat_device->input_device); } } + +struct seat_config *seat_get_config(struct sway_seat *seat) { + struct seat_config *seat_config = NULL; + for (int i = 0; i < config->seat_configs->length; ++i ) { + seat_config = config->seat_configs->items[i]; + if (strcmp(seat->wlr_seat->name, seat_config->name) == 0) { + return seat_config; + } + } + + return NULL; +} |