diff options
Diffstat (limited to 'sway/input')
-rw-r--r-- | sway/input/seat.c | 70 |
1 files changed, 63 insertions, 7 deletions
diff --git a/sway/input/seat.c b/sway/input/seat.c index ce009d7e..2e386d2c 100644 --- a/sway/input/seat.c +++ b/sway/input/seat.c | |||
@@ -19,6 +19,7 @@ | |||
19 | #include "sway/ipc-server.h" | 19 | #include "sway/ipc-server.h" |
20 | #include "sway/layers.h" | 20 | #include "sway/layers.h" |
21 | #include "sway/output.h" | 21 | #include "sway/output.h" |
22 | #include "sway/server.h" | ||
22 | #include "sway/tree/arrange.h" | 23 | #include "sway/tree/arrange.h" |
23 | #include "sway/tree/container.h" | 24 | #include "sway/tree/container.h" |
24 | #include "sway/tree/root.h" | 25 | #include "sway/tree/root.h" |
@@ -722,17 +723,72 @@ void seat_remove_device(struct sway_seat *seat, | |||
722 | seat_update_capabilities(seat); | 723 | seat_update_capabilities(seat); |
723 | } | 724 | } |
724 | 725 | ||
726 | static bool xcursor_manager_is_named(const struct wlr_xcursor_manager *manager, | ||
727 | const char *name) { | ||
728 | return (!manager->name && !name) || | ||
729 | (name && manager->name && strcmp(name, manager->name) == 0); | ||
730 | } | ||
731 | |||
725 | void seat_configure_xcursor(struct sway_seat *seat) { | 732 | void seat_configure_xcursor(struct sway_seat *seat) { |
726 | // TODO configure theme and size | 733 | unsigned cursor_size = 24; |
727 | const char *cursor_theme = NULL; | 734 | const char *cursor_theme = NULL; |
728 | 735 | ||
729 | if (!seat->cursor->xcursor_manager) { | 736 | const struct seat_config *seat_config = seat_get_config(seat); |
730 | seat->cursor->xcursor_manager = | 737 | if (!seat_config) { |
731 | wlr_xcursor_manager_create(cursor_theme, 24); | 738 | seat_config = seat_get_config_by_name("*"); |
732 | if (sway_assert(seat->cursor->xcursor_manager, | 739 | } |
733 | "Cannot create XCursor manager for theme")) { | 740 | if (seat_config) { |
734 | return; | 741 | cursor_size = seat_config->xcursor_theme.size; |
742 | cursor_theme = seat_config->xcursor_theme.name; | ||
743 | } | ||
744 | |||
745 | if (seat == input_manager_get_default_seat()) { | ||
746 | char cursor_size_fmt[16]; | ||
747 | snprintf(cursor_size_fmt, sizeof(cursor_size_fmt), "%d", cursor_size); | ||
748 | setenv("XCURSOR_SIZE", cursor_size_fmt, 1); | ||
749 | if (cursor_theme != NULL) { | ||
750 | setenv("XCURSOR_THEME", cursor_theme, 1); | ||
735 | } | 751 | } |
752 | |||
753 | #if HAVE_XWAYLAND | ||
754 | if (!server.xwayland.xcursor_manager || | ||
755 | !xcursor_manager_is_named(server.xwayland.xcursor_manager, | ||
756 | cursor_theme) || | ||
757 | server.xwayland.xcursor_manager->size != cursor_size) { | ||
758 | |||
759 | wlr_xcursor_manager_destroy(server.xwayland.xcursor_manager); | ||
760 | |||
761 | server.xwayland.xcursor_manager = | ||
762 | wlr_xcursor_manager_create(cursor_theme, cursor_size); | ||
763 | sway_assert(server.xwayland.xcursor_manager, | ||
764 | "Cannot create XCursor manager for theme"); | ||
765 | |||
766 | wlr_xcursor_manager_load(server.xwayland.xcursor_manager, 1); | ||
767 | struct wlr_xcursor *xcursor = wlr_xcursor_manager_get_xcursor( | ||
768 | server.xwayland.xcursor_manager, "left_ptr", 1); | ||
769 | if (xcursor != NULL) { | ||
770 | struct wlr_xcursor_image *image = xcursor->images[0]; | ||
771 | wlr_xwayland_set_cursor( | ||
772 | server.xwayland.wlr_xwayland, image->buffer, | ||
773 | image->width * 4, image->width, image->height, | ||
774 | image->hotspot_x, image->hotspot_y); | ||
775 | } | ||
776 | } | ||
777 | #endif | ||
778 | } | ||
779 | |||
780 | /* Create xcursor manager if we don't have one already, or if the | ||
781 | * theme has changed */ | ||
782 | if (!seat->cursor->xcursor_manager || | ||
783 | !xcursor_manager_is_named( | ||
784 | seat->cursor->xcursor_manager, cursor_theme) || | ||
785 | seat->cursor->xcursor_manager->size != cursor_size) { | ||
786 | |||
787 | wlr_xcursor_manager_destroy(seat->cursor->xcursor_manager); | ||
788 | seat->cursor->xcursor_manager = | ||
789 | wlr_xcursor_manager_create(cursor_theme, cursor_size); | ||
790 | sway_assert(seat->cursor->xcursor_manager, | ||
791 | "Cannot create XCursor manager for theme"); | ||
736 | } | 792 | } |
737 | 793 | ||
738 | for (int i = 0; i < root->outputs->length; ++i) { | 794 | for (int i = 0; i < root->outputs->length; ++i) { |