diff options
Diffstat (limited to 'sway/input/input-manager.c')
-rw-r--r-- | sway/input/input-manager.c | 60 |
1 files changed, 47 insertions, 13 deletions
diff --git a/sway/input/input-manager.c b/sway/input/input-manager.c index 39f4b795..288fddc4 100644 --- a/sway/input/input-manager.c +++ b/sway/input/input-manager.c @@ -3,7 +3,7 @@ #include <stdio.h> #include <string.h> #include <math.h> -#include <wlr/backend/libinput.h> +#include <wlr/config.h> #include <wlr/types/wlr_cursor.h> #include <wlr/types/wlr_keyboard_group.h> #include <wlr/types/wlr_input_inhibitor.h> @@ -22,6 +22,10 @@ #include "list.h" #include "log.h" +#if WLR_HAS_LIBINPUT_BACKEND +#include <wlr/backend/libinput.h> +#endif + #define DEFAULT_SEAT "seat0" struct input_config *current_input_config = NULL; @@ -76,20 +80,13 @@ char *input_device_get_identifier(struct wlr_input_device *device) { } } - const char *fmt = "%d:%d:%s"; - int len = snprintf(NULL, 0, fmt, vendor, product, name) + 1; - char *identifier = malloc(len); - if (!identifier) { - sway_log(SWAY_ERROR, "Unable to allocate unique input device name"); - return NULL; - } - - snprintf(identifier, len, fmt, vendor, product, name); + char *identifier = format_str("%d:%d:%s", vendor, product, name); free(name); return identifier; } static bool device_is_touchpad(struct sway_input_device *device) { +#if WLR_HAS_LIBINPUT_BACKEND if (device->wlr_device->type != WLR_INPUT_DEVICE_POINTER || !wlr_input_device_is_libinput(device->wlr_device)) { return false; @@ -99,6 +96,9 @@ static bool device_is_touchpad(struct sway_input_device *device) { wlr_libinput_get_device_handle(device->wlr_device); return libinput_device_config_tap_get_finger_count(libinput_device) > 0; +#else + return false; +#endif } const char *input_device_get_type(struct sway_input_device *device) { @@ -236,7 +236,11 @@ static void handle_new_input(struct wl_listener *listener, void *data) { apply_input_type_config(input_device); +#if WLR_HAS_LIBINPUT_BACKEND bool config_changed = sway_input_configure_libinput_device(input_device); +#else + bool config_changed = false; +#endif wl_signal_add(&device->events.destroy, &input_device->device_destroy); input_device->device_destroy.notify = handle_device_destroy; @@ -491,6 +495,8 @@ struct sway_input_manager *input_manager_create(struct sway_server *server) { wl_signal_add(&input->keyboard_shortcuts_inhibit->events.new_inhibitor, &input->keyboard_shortcuts_inhibit_new_inhibitor); + input->pointer_gestures = wlr_pointer_gestures_v1_create(server->wl_display); + return input; } @@ -528,11 +534,27 @@ static void retranslate_keysyms(struct input_config *input_config) { return; } } + + for (int i = 0; i < config->input_type_configs->length; ++i) { + struct input_config *ic = config->input_type_configs->items[i]; + if (ic->xkb_layout || ic->xkb_file) { + // this is the first config with xkb_layout or xkb_file + if (ic->identifier == input_config->identifier) { + translate_keysyms(ic); + } + + return; + } + } } static void input_manager_configure_input( struct sway_input_device *input_device) { +#if WLR_HAS_LIBINPUT_BACKEND bool config_changed = sway_input_configure_libinput_device(input_device); +#else + bool config_changed = false; +#endif struct sway_seat *seat = NULL; wl_list_for_each(seat, &server.input->seats, link) { seat_configure_device(seat, input_device); @@ -542,10 +564,20 @@ static void input_manager_configure_input( } } -void input_manager_configure_all_inputs(void) { - struct sway_input_device *input_device = NULL; +void input_manager_configure_all_input_mappings(void) { + struct sway_input_device *input_device; wl_list_for_each(input_device, &server.input->devices, link) { - input_manager_configure_input(input_device); + struct sway_seat *seat; + wl_list_for_each(seat, &server.input->seats, link) { + seat_configure_device_mapping(seat, input_device); + } + +#if WLR_HAS_LIBINPUT_BACKEND + // Input devices mapped to unavailable outputs get their libinput + // send_events setting switched to false. We need to re-enable this + // when the output appears. + sway_input_configure_libinput_device_send_events(input_device); +#endif } } @@ -567,7 +599,9 @@ void input_manager_apply_input_config(struct input_config *input_config) { } void input_manager_reset_input(struct sway_input_device *input_device) { +#if WLR_HAS_LIBINPUT_BACKEND sway_input_reset_libinput_device(input_device); +#endif struct sway_seat *seat = NULL; wl_list_for_each(seat, &server.input->seats, link) { seat_reset_device(seat, input_device); |