diff options
-rw-r--r-- | include/sway/input/libinput.h | 2 | ||||
-rw-r--r-- | meson.build | 1 | ||||
-rw-r--r-- | sway/input/libinput.c | 23 | ||||
-rw-r--r-- | sway/input/seat.c | 49 | ||||
-rw-r--r-- | sway/meson.build | 1 |
5 files changed, 76 insertions, 0 deletions
diff --git a/include/sway/input/libinput.h b/include/sway/input/libinput.h index de019976..890d632e 100644 --- a/include/sway/input/libinput.h +++ b/include/sway/input/libinput.h | |||
@@ -6,4 +6,6 @@ void sway_input_configure_libinput_device(struct sway_input_device *device); | |||
6 | 6 | ||
7 | void sway_input_reset_libinput_device(struct sway_input_device *device); | 7 | void sway_input_reset_libinput_device(struct sway_input_device *device); |
8 | 8 | ||
9 | bool sway_libinput_device_is_builtin(struct sway_input_device *device); | ||
10 | |||
9 | #endif | 11 | #endif |
diff --git a/meson.build b/meson.build index cb4ee20e..60daf882 100644 --- a/meson.build +++ b/meson.build | |||
@@ -54,6 +54,7 @@ libinput = dependency('libinput', version: '>=1.6.0') | |||
54 | xcb = dependency('xcb', required: get_option('xwayland')) | 54 | xcb = dependency('xcb', required: get_option('xwayland')) |
55 | drm_full = dependency('libdrm') # only needed for drm_fourcc.h | 55 | drm_full = dependency('libdrm') # only needed for drm_fourcc.h |
56 | drm = drm_full.partial_dependency(compile_args: true, includes: true) | 56 | drm = drm_full.partial_dependency(compile_args: true, includes: true) |
57 | libudev = dependency('libudev') | ||
57 | bash_comp = dependency('bash-completion', required: false) | 58 | bash_comp = dependency('bash-completion', required: false) |
58 | fish_comp = dependency('fish', required: false) | 59 | fish_comp = dependency('fish', required: false) |
59 | math = cc.find_library('m') | 60 | math = cc.find_library('m') |
diff --git a/sway/input/libinput.c b/sway/input/libinput.c index 54520f9e..060a584a 100644 --- a/sway/input/libinput.c +++ b/sway/input/libinput.c | |||
@@ -1,5 +1,6 @@ | |||
1 | #include <float.h> | 1 | #include <float.h> |
2 | #include <libinput.h> | 2 | #include <libinput.h> |
3 | #include <libudev.h> | ||
3 | #include <limits.h> | 4 | #include <limits.h> |
4 | #include <wlr/backend/libinput.h> | 5 | #include <wlr/backend/libinput.h> |
5 | #include "log.h" | 6 | #include "log.h" |
@@ -312,3 +313,25 @@ void sway_input_reset_libinput_device(struct sway_input_device *input_device) { | |||
312 | ipc_event_input("libinput_config", input_device); | 313 | ipc_event_input("libinput_config", input_device); |
313 | } | 314 | } |
314 | } | 315 | } |
316 | |||
317 | bool sway_libinput_device_is_builtin(struct sway_input_device *sway_device) { | ||
318 | if (!wlr_input_device_is_libinput(sway_device->wlr_device)) { | ||
319 | return false; | ||
320 | } | ||
321 | |||
322 | struct libinput_device *device = | ||
323 | wlr_libinput_get_device_handle(sway_device->wlr_device); | ||
324 | struct udev_device *udev_device = | ||
325 | libinput_device_get_udev_device(device); | ||
326 | if (!udev_device) { | ||
327 | return false; | ||
328 | } | ||
329 | |||
330 | const char *id_path = udev_device_get_property_value(udev_device, "ID_PATH"); | ||
331 | if (!id_path) { | ||
332 | return false; | ||
333 | } | ||
334 | |||
335 | const char prefix[] = "platform-"; | ||
336 | return strncmp(id_path, prefix, strlen(prefix)) == 0; | ||
337 | } | ||
diff --git a/sway/input/seat.c b/sway/input/seat.c index e6e1d4fb..d23525a8 100644 --- a/sway/input/seat.c +++ b/sway/input/seat.c | |||
@@ -20,6 +20,7 @@ | |||
20 | #include "sway/input/cursor.h" | 20 | #include "sway/input/cursor.h" |
21 | #include "sway/input/input-manager.h" | 21 | #include "sway/input/input-manager.h" |
22 | #include "sway/input/keyboard.h" | 22 | #include "sway/input/keyboard.h" |
23 | #include "sway/input/libinput.h" | ||
23 | #include "sway/input/seat.h" | 24 | #include "sway/input/seat.h" |
24 | #include "sway/input/switch.h" | 25 | #include "sway/input/switch.h" |
25 | #include "sway/input/tablet.h" | 26 | #include "sway/input/tablet.h" |
@@ -666,6 +667,40 @@ static void seat_reset_input_config(struct sway_seat *seat, | |||
666 | sway_device->input_device->wlr_device, NULL); | 667 | sway_device->input_device->wlr_device, NULL); |
667 | } | 668 | } |
668 | 669 | ||
670 | static bool has_prefix(const char *str, const char *prefix) { | ||
671 | return strncmp(str, prefix, strlen(prefix)) == 0; | ||
672 | } | ||
673 | |||
674 | /** | ||
675 | * Get the name of the built-in output, if any. Returns NULL if there isn't | ||
676 | * exactly one built-in output. | ||
677 | */ | ||
678 | static const char *get_builtin_output_name(void) { | ||
679 | const char *match = NULL; | ||
680 | for (int i = 0; i < root->outputs->length; ++i) { | ||
681 | struct sway_output *output = root->outputs->items[i]; | ||
682 | const char *name = output->wlr_output->name; | ||
683 | if (has_prefix(name, "eDP-") || has_prefix(name, "LVDS-") || | ||
684 | has_prefix(name, "DSI-")) { | ||
685 | if (match != NULL) { | ||
686 | return NULL; | ||
687 | } | ||
688 | match = name; | ||
689 | } | ||
690 | } | ||
691 | return match; | ||
692 | } | ||
693 | |||
694 | static bool is_touch_or_tablet_tool(struct sway_seat_device *seat_device) { | ||
695 | switch (seat_device->input_device->wlr_device->type) { | ||
696 | case WLR_INPUT_DEVICE_TOUCH: | ||
697 | case WLR_INPUT_DEVICE_TABLET_TOOL: | ||
698 | return true; | ||
699 | default: | ||
700 | return false; | ||
701 | } | ||
702 | } | ||
703 | |||
669 | static void seat_apply_input_config(struct sway_seat *seat, | 704 | static void seat_apply_input_config(struct sway_seat *seat, |
670 | struct sway_seat_device *sway_device) { | 705 | struct sway_seat_device *sway_device) { |
671 | struct input_config *ic = | 706 | struct input_config *ic = |
@@ -681,7 +716,21 @@ static void seat_apply_input_config(struct sway_seat *seat, | |||
681 | 716 | ||
682 | switch (mapped_to) { | 717 | switch (mapped_to) { |
683 | case MAPPED_TO_DEFAULT: | 718 | case MAPPED_TO_DEFAULT: |
719 | /* | ||
720 | * If the wlroots backend provides an output name, use that. | ||
721 | * | ||
722 | * Otherwise, try to map built-in touch and tablet tool devices to the | ||
723 | * built-in output. | ||
724 | */ | ||
684 | mapped_to_output = sway_device->input_device->wlr_device->output_name; | 725 | mapped_to_output = sway_device->input_device->wlr_device->output_name; |
726 | if (mapped_to_output == NULL && is_touch_or_tablet_tool(sway_device) && | ||
727 | sway_libinput_device_is_builtin(sway_device->input_device)) { | ||
728 | mapped_to_output = get_builtin_output_name(); | ||
729 | if (mapped_to_output) { | ||
730 | sway_log(SWAY_DEBUG, "Auto-detected output '%s' for device '%s'", | ||
731 | mapped_to_output, sway_device->input_device->identifier); | ||
732 | } | ||
733 | } | ||
685 | if (mapped_to_output == NULL) { | 734 | if (mapped_to_output == NULL) { |
686 | return; | 735 | return; |
687 | } | 736 | } |
diff --git a/sway/meson.build b/sway/meson.build index f163ee90..b52fada4 100644 --- a/sway/meson.build +++ b/sway/meson.build | |||
@@ -208,6 +208,7 @@ sway_deps = [ | |||
208 | jsonc, | 208 | jsonc, |
209 | libevdev, | 209 | libevdev, |
210 | libinput, | 210 | libinput, |
211 | libudev, | ||
211 | math, | 212 | math, |
212 | pango, | 213 | pango, |
213 | pcre, | 214 | pcre, |