From 448f78c9705c96c8bd58b1112478ca1c7d0015d8 Mon Sep 17 00:00:00 2001 From: tiosgz Date: Sun, 1 Aug 2021 16:01:57 +0000 Subject: [PATCH] Add clipboard and clipboard management support --- include/input/seat.h | 2 ++ kiwmi/input/seat.c | 33 +++++++++++++++++++++++++++++++++ kiwmi/server.c | 5 +++++ 3 files changed, 40 insertions(+) diff --git a/include/input/seat.h b/include/input/seat.h index 80a19bb..5c4f099 100644 --- a/include/input/seat.h +++ b/include/input/seat.h @@ -23,6 +23,8 @@ struct kiwmi_seat { struct kiwmi_layer *focused_layer; struct wl_listener request_set_cursor; + struct wl_listener request_set_selection; + struct wl_listener request_set_primary_selection; }; void diff --git a/kiwmi/input/seat.c b/kiwmi/input/seat.c index 3032868..5097275 100644 --- a/kiwmi/input/seat.c +++ b/kiwmi/input/seat.c @@ -10,7 +10,9 @@ #include #include +#include #include +#include #include #include @@ -111,6 +113,24 @@ request_set_cursor_notify(struct wl_listener *listener, void *data) cursor->cursor, event->surface, event->hotspot_x, event->hotspot_y); } +static void +request_set_selection_notify(struct wl_listener *listener, void *data) +{ + struct kiwmi_seat *seat = + wl_container_of(listener, seat, request_set_selection); + struct wlr_seat_request_set_selection_event *event = data; + wlr_seat_set_selection(seat->seat, event->source, event->serial); +} + +static void +request_set_primary_selection_notify(struct wl_listener *listener, void *data) +{ + struct kiwmi_seat *seat = + wl_container_of(listener, seat, request_set_primary_selection); + struct wlr_seat_request_set_primary_selection_event *event = data; + wlr_seat_set_primary_selection(seat->seat, event->source, event->serial); +} + struct kiwmi_seat * seat_create(struct kiwmi_input *input) { @@ -132,6 +152,17 @@ seat_create(struct kiwmi_input *input) wl_signal_add( &seat->seat->events.request_set_cursor, &seat->request_set_cursor); + wl_signal_add( + &seat->seat->events.request_set_selection, + &seat->request_set_selection); + seat->request_set_selection.notify = request_set_selection_notify; + + wl_signal_add( + &seat->seat->events.request_set_primary_selection, + &seat->request_set_primary_selection); + seat->request_set_primary_selection.notify = + request_set_primary_selection_notify; + return seat; } @@ -139,6 +170,8 @@ void seat_destroy(struct kiwmi_seat *seat) { wl_list_remove(&seat->request_set_cursor.link); + wl_list_remove(&seat->request_set_selection.link); + wl_list_remove(&seat->request_set_primary_selection.link); free(seat); } diff --git a/kiwmi/server.c b/kiwmi/server.c index 0f0203d..0fa2e70 100644 --- a/kiwmi/server.c +++ b/kiwmi/server.c @@ -15,6 +15,8 @@ #include #include #include +#include +#include #include #include @@ -55,6 +57,9 @@ server_init(struct kiwmi_server *server, char *config_path) return false; } + wlr_data_control_manager_v1_create(server->wl_display); + wlr_primary_selection_v1_device_manager_create(server->wl_display); + server->socket = wl_display_add_socket_auto(server->wl_display); if (!server->socket) { wlr_log(WLR_ERROR, "Failed to open Wayland socket");