From 18f5fcb1ef52e14c774a596050ea7fca0cc6a7e5 Mon Sep 17 00:00:00 2001 From: Leon Henrik Plickat Date: Tue, 6 Oct 2020 17:02:07 +0200 Subject: [PATCH] Implement primary selection --- river/Seat.zig | 10 ++++++++++ river/Server.zig | 4 ++++ river/c.zig | 3 +++ 3 files changed, 17 insertions(+) diff --git a/river/Seat.zig b/river/Seat.zig index bb6e557..e80368c 100644 --- a/river/Seat.zig +++ b/river/Seat.zig @@ -69,6 +69,7 @@ status_trackers: std.SinglyLinkedList(SeatStatus) = .{}, listen_request_set_selection: c.wl_listener = undefined, listen_request_start_drag: c.wl_listener = undefined, listen_start_drag: c.wl_listener = undefined, +listen_request_set_primary_selection: c.wl_listener = undefined, pub fn init(self: *Self, input_manager: *InputManager, name: [*:0]const u8) !void { self.* = .{ @@ -89,6 +90,9 @@ pub fn init(self: *Self, input_manager: *InputManager, name: [*:0]const u8) !voi self.listen_start_drag.notify = handleStartDrag; c.wl_signal_add(&self.wlr_seat.events.start_drag, &self.listen_start_drag); + + self.listen_request_set_primary_selection.notify = handleRequestPrimarySelection; + c.wl_signal_add(&self.wlr_seat.events.request_set_primary_selection, &self.listen_request_set_primary_selection); } pub fn deinit(self: *Self) void { @@ -366,3 +370,9 @@ fn handleStartDrag(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void } self.cursor.mode = .passthrough; } + +fn handleRequestPrimarySelection(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void { + const self = @fieldParentPtr(Self, "listen_request_set_primary_selection", listener.?); + const event = util.voidCast(c.wlr_seat_request_set_primary_selection_event, data.?); + c.wlr_seat_set_primary_selection(self.wlr_seat, event.source, event.serial); +} diff --git a/river/Server.zig b/river/Server.zig index fd8aeff..c2eb0c8 100644 --- a/river/Server.zig +++ b/river/Server.zig @@ -118,6 +118,10 @@ pub fn init(self: *Self) !void { c.wl_signal_add(&self.wlr_xwayland.events.new_surface, &self.listen_new_xwayland_surface); } + // Set up primary selection + _ = c.wlr_primary_selection_v1_device_manager_create(self.wl_display); + _ = c.wlr_gtk_primary_selection_device_manager_create(self.wl_display); + self.config = try Config.init(); try self.decoration_manager.init(self); try self.root.init(self); diff --git a/river/c.zig b/river/c.zig index ead36a3..f9814e6 100644 --- a/river/c.zig +++ b/river/c.zig @@ -35,6 +35,7 @@ pub usingnamespace @cImport({ @cInclude("wlr/types/wlr_data_control_v1.h"); @cInclude("wlr/types/wlr_data_device.h"); @cInclude("wlr/types/wlr_gamma_control_v1.h"); + @cInclude("wlr/types/wlr_gtk_primary_selection.h"); @cInclude("wlr/types/wlr_idle.h"); @cInclude("wlr/types/wlr_input_device.h"); @cInclude("wlr/types/wlr_input_inhibitor.h"); @@ -44,6 +45,8 @@ pub usingnamespace @cImport({ @cInclude("wlr/types/wlr_output.h"); @cInclude("wlr/types/wlr_output_layout.h"); @cInclude("wlr/types/wlr_pointer.h"); + @cInclude("wlr/types/wlr_primary_selection.h"); + @cInclude("wlr/types/wlr_primary_selection_v1.h"); @cInclude("wlr/types/wlr_screencopy_v1.h"); @cInclude("wlr/types/wlr_seat.h"); @cInclude("wlr/types/wlr_xcursor_manager.h");