Implement primary selection

This commit is contained in:
Leon Henrik Plickat 2020-10-06 17:02:07 +02:00 committed by Isaac Freund
parent 185b403854
commit 18f5fcb1ef
3 changed files with 17 additions and 0 deletions

View file

@ -69,6 +69,7 @@ status_trackers: std.SinglyLinkedList(SeatStatus) = .{},
listen_request_set_selection: c.wl_listener = undefined, listen_request_set_selection: c.wl_listener = undefined,
listen_request_start_drag: c.wl_listener = undefined, listen_request_start_drag: c.wl_listener = undefined,
listen_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 { pub fn init(self: *Self, input_manager: *InputManager, name: [*:0]const u8) !void {
self.* = .{ self.* = .{
@ -89,6 +90,9 @@ pub fn init(self: *Self, input_manager: *InputManager, name: [*:0]const u8) !voi
self.listen_start_drag.notify = handleStartDrag; self.listen_start_drag.notify = handleStartDrag;
c.wl_signal_add(&self.wlr_seat.events.start_drag, &self.listen_start_drag); 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 { 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; 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);
}

View file

@ -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); 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(); self.config = try Config.init();
try self.decoration_manager.init(self); try self.decoration_manager.init(self);
try self.root.init(self); try self.root.init(self);

View file

@ -35,6 +35,7 @@ pub usingnamespace @cImport({
@cInclude("wlr/types/wlr_data_control_v1.h"); @cInclude("wlr/types/wlr_data_control_v1.h");
@cInclude("wlr/types/wlr_data_device.h"); @cInclude("wlr/types/wlr_data_device.h");
@cInclude("wlr/types/wlr_gamma_control_v1.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_idle.h");
@cInclude("wlr/types/wlr_input_device.h"); @cInclude("wlr/types/wlr_input_device.h");
@cInclude("wlr/types/wlr_input_inhibitor.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.h");
@cInclude("wlr/types/wlr_output_layout.h"); @cInclude("wlr/types/wlr_output_layout.h");
@cInclude("wlr/types/wlr_pointer.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_screencopy_v1.h");
@cInclude("wlr/types/wlr_seat.h"); @cInclude("wlr/types/wlr_seat.h");
@cInclude("wlr/types/wlr_xcursor_manager.h"); @cInclude("wlr/types/wlr_xcursor_manager.h");