Implement wlr_virtual_pointer_unstable_v1 protocol

This commit is contained in:
Marten Ringwelski 2020-10-30 12:37:20 +01:00
parent 1bd6f6bed1
commit 76217970f5
2 changed files with 26 additions and 0 deletions

View File

@ -1,6 +1,7 @@
// This file is part of river, a dynamic tiling wayland compositor. // This file is part of river, a dynamic tiling wayland compositor.
// //
// Copyright 2020 Isaac Freund // Copyright 2020 Isaac Freund
// Copyright 2020 Marten Ringwelski
// //
// This program is free software: you can redistribute it and/or modify // This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by // it under the terms of the GNU General Public License as published by
@ -34,6 +35,7 @@ server: *Server,
wlr_idle: *c.wlr_idle, wlr_idle: *c.wlr_idle,
wlr_input_inhibit_manager: *c.wlr_input_inhibit_manager, wlr_input_inhibit_manager: *c.wlr_input_inhibit_manager,
wlr_virtual_pointer_manager: *c.wlr_virtual_pointer_manager_v1,
seats: std.TailQueue(Seat) = .{}, seats: std.TailQueue(Seat) = .{},
@ -42,6 +44,7 @@ exclusive_client: ?*c.wl_client = null,
listen_inhibit_activate: c.wl_listener = undefined, listen_inhibit_activate: c.wl_listener = undefined,
listen_inhibit_deactivate: c.wl_listener = undefined, listen_inhibit_deactivate: c.wl_listener = undefined,
listen_new_input: c.wl_listener = undefined, listen_new_input: c.wl_listener = undefined,
listen_new_virtual_pointer: c.wl_listener = undefined,
pub fn init(self: *Self, server: *Server) !void { pub fn init(self: *Self, server: *Server) !void {
const seat_node = try util.gpa.create(std.TailQueue(Seat).Node); const seat_node = try util.gpa.create(std.TailQueue(Seat).Node);
@ -52,6 +55,8 @@ pub fn init(self: *Self, server: *Server) !void {
.wlr_idle = c.wlr_idle_create(server.wl_display) orelse return error.OutOfMemory, .wlr_idle = c.wlr_idle_create(server.wl_display) orelse return error.OutOfMemory,
.wlr_input_inhibit_manager = c.wlr_input_inhibit_manager_create(server.wl_display) orelse .wlr_input_inhibit_manager = c.wlr_input_inhibit_manager_create(server.wl_display) orelse
return error.OutOfMemory, return error.OutOfMemory,
.wlr_virtual_pointer_manager = c.wlr_virtual_pointer_manager_v1_create(server.wl_display) orelse
return error.OutOfMemory,
}; };
self.seats.prepend(seat_node); self.seats.prepend(seat_node);
@ -68,6 +73,9 @@ pub fn init(self: *Self, server: *Server) !void {
self.listen_new_input.notify = handleNewInput; self.listen_new_input.notify = handleNewInput;
c.wl_signal_add(&self.server.wlr_backend.events.new_input, &self.listen_new_input); c.wl_signal_add(&self.server.wlr_backend.events.new_input, &self.listen_new_input);
self.listen_new_virtual_pointer.notify = handleNewVirtualPointer;
c.wl_signal_add(&self.wlr_virtual_pointer_manager.events.new_virtual_pointer, &self.listen_new_virtual_pointer);
} }
pub fn deinit(self: *Self) void { pub fn deinit(self: *Self) void {
@ -156,3 +164,20 @@ fn handleNewInput(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
// TODO: suport multiple seats // TODO: suport multiple seats
self.defaultSeat().addDevice(device); self.defaultSeat().addDevice(device);
} }
fn handleNewVirtualPointer(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
const self = @fieldParentPtr(Self, "listen_new_virtual_pointer", listener.?);
const event = util.voidCast(c.wlr_virtual_pointer_v1_new_pointer_event, data.?);
// TODO Support multiple seats and don't ignore
if (event.suggested_seat != null) {
log.debug(.input_manager, "Ignoring seat suggestion from virtual pointer", .{});
}
// TODO dont ignore output suggestion
if (event.suggested_output != null) {
log.debug(.input_manager, "Ignoring output suggestion from virtual pointer", .{});
}
const new_pointer: *c.wlr_virtual_pointer_v1 = event.new_pointer;
self.defaultSeat().addDevice(&new_pointer.input_device);
}

View File

@ -53,6 +53,7 @@ pub usingnamespace @cImport({
@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_viewporter.h"); @cInclude("wlr/types/wlr_viewporter.h");
@cInclude("wlr/types/wlr_virtual_pointer_v1.h");
@cInclude("wlr/types/wlr_xcursor_manager.h"); @cInclude("wlr/types/wlr_xcursor_manager.h");
@cInclude("wlr/types/wlr_xdg_decoration_v1.h"); @cInclude("wlr/types/wlr_xdg_decoration_v1.h");
@cInclude("wlr/types/wlr_xdg_output_v1.h"); @cInclude("wlr/types/wlr_xdg_output_v1.h");