commit: 55343689ddd9f796d57920f5744cb59102e5bdfd
parent 3d51fa19b1cf9d6e46a03399b9ed5325cd42726b
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date: Fri, 1 Jan 2021 12:07:34 +0100
Add support for clipboard / selection
Diffstat:
2 files changed, 39 insertions(+), 0 deletions(-)
diff --git a/inaban.c b/inaban.c
@@ -600,6 +600,26 @@ server_new_xdg_surface(struct wl_listener *listener, void *data)
wl_list_insert(&server->views, &view->link);
}
+static void
+handle_request_set_primary_selection(struct wl_listener *listener, void *data)
+{
+ struct inaban_server *server = wl_container_of(listener, server, request_set_primary_selection);
+
+ struct wlr_seat_request_set_primary_selection_event *event = data;
+
+ wlr_seat_set_primary_selection(server->seat, event->source, event->serial);
+}
+
+static void
+handle_request_set_selection(struct wl_listener *listener, void *data)
+{
+ struct inaban_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);
+}
+
void
sigterm_handler(int signal)
{
@@ -794,6 +814,17 @@ main(int argc, char *argv[])
server.request_cursor.notify = seat_request_cursor;
wl_signal_add(&server.seat->events.request_set_cursor, &server.request_cursor);
+ /* Clipboard protocols */
+ wlr_data_control_manager_v1_create(server.wl_display);
+ wlr_primary_selection_v1_device_manager_create(server.wl_display);
+ wlr_gtk_primary_selection_device_manager_create(server.wl_display);
+ /* Clipboard requests handlers */
+ server.request_set_selection.notify = handle_request_set_selection;
+ wl_signal_add(&server.seat->events.request_set_selection, &server.request_set_selection);
+ server.request_set_primary_selection.notify = handle_request_set_primary_selection;
+ wl_signal_add(&server.seat->events.request_set_primary_selection,
+ &server.request_set_primary_selection);
+
/* Add a Unix socket to the Wayland display. */
const char *socket = wl_display_add_socket_auto(server.wl_display);
if(!socket)
diff --git a/inaban.h b/inaban.h
@@ -9,13 +9,17 @@
#include <wlr/render/wlr_renderer.h>
#include <wlr/types/wlr_compositor.h>
#include <wlr/types/wlr_cursor.h>
+#include <wlr/types/wlr_data_control_v1.h>
#include <wlr/types/wlr_data_device.h>
+#include <wlr/types/wlr_gtk_primary_selection.h>
#include <wlr/types/wlr_input_device.h>
#include <wlr/types/wlr_keyboard.h>
#include <wlr/types/wlr_matrix.h>
#include <wlr/types/wlr_output.h>
#include <wlr/types/wlr_output_layout.h>
#include <wlr/types/wlr_pointer.h>
+#include <wlr/types/wlr_primary_selection.h>
+#include <wlr/types/wlr_primary_selection_v1.h>
#include <wlr/types/wlr_seat.h>
#include <wlr/types/wlr_server_decoration.h>
#include <wlr/types/wlr_xcursor_manager.h>
@@ -73,6 +77,10 @@ struct inaban_server
/* window size */
int grab_width, grab_height;
+
+ /* clipboard */
+ struct wl_listener request_set_primary_selection;
+ struct wl_listener request_set_selection;
};
struct inaban_output