From fa5d709fc3ea96b14163cdad435caccdbdd5bbda Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Sat, 25 Apr 2020 01:44:45 +0200 Subject: [PATCH] tinywl: handle request set selection --- tinywl/tinywl.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/tinywl/tinywl.c b/tinywl/tinywl.c index 3fe65c16..70e13233 100644 --- a/tinywl/tinywl.c +++ b/tinywl/tinywl.c @@ -50,6 +50,7 @@ struct tinywl_server { struct wlr_seat *seat; struct wl_listener new_input; struct wl_listener request_cursor; + struct wl_listener request_set_selection; struct wl_list keyboards; enum tinywl_cursor_mode cursor_mode; struct tinywl_view *grabbed_view; @@ -298,6 +299,17 @@ static void seat_request_cursor(struct wl_listener *listener, void *data) { } } +static void seat_request_set_selection(struct wl_listener *listener, void *data) { + /* This event is raised by the seat when a client wants to set the selection, + * usually when the user copies something. wlroots allows compositors to + * ignore such requests if they so choose, but in tinywl we always honor + */ + struct tinywl_server *server = wl_container_of( + listener, server, request_set_selection); + struct wlr_seat_request_set_selection_event *event = data; + wlr_seat_set_selection(server->seat, event->source, event->serial); +} + static bool view_at(struct tinywl_view *view, double lx, double ly, struct wlr_surface **surface, double *sx, double *sy) { @@ -827,7 +839,9 @@ int main(int argc, char *argv[]) { /* This creates some hands-off wlroots interfaces. The compositor is * necessary for clients to allocate surfaces and the data device manager * handles the clipboard. Each of these wlroots interfaces has room for you - * to dig your fingers in and play with their behavior if you want. */ + * to dig your fingers in and play with their behavior if you want. Note that + * the clients cannot set the selection directly without compositor approval, + * see the handling of the request_set_selection event below.*/ wlr_compositor_create(server.wl_display, server.renderer); wlr_data_device_manager_create(server.wl_display); @@ -904,6 +918,9 @@ int main(int argc, char *argv[]) { server.request_cursor.notify = seat_request_cursor; wl_signal_add(&server.seat->events.request_set_cursor, &server.request_cursor); + server.request_set_selection.notify = seat_request_set_selection; + wl_signal_add(&server.seat->events.request_set_selection, + &server.request_set_selection); /* Add a Unix socket to the Wayland display. */ const char *socket = wl_display_add_socket_auto(server.wl_display);