Make InputManager a toplevel struct

This commit is contained in:
Isaac Freund 2020-05-02 16:28:17 +02:00
parent a03cab94fc
commit 4c97531860
No known key found for this signature in database
GPG key ID: 86DED400DDFD7A11
3 changed files with 103 additions and 104 deletions

View file

@ -1,29 +1,29 @@
const Self = @This();
const std = @import("std");
const c = @import("c.zig");
const Log = @import("log.zig").Log;
const Seat = @import("seat.zig").Seat;
const Server = @import("server.zig");
pub const InputManager = struct {
const Self = @This();
const default_seat_name = "default";
const default_seat_name = "default";
server: *Server,
server: *Server,
wlr_input_inhibit_manager: *c.wlr_input_inhibit_manager,
wlr_input_inhibit_manager: *c.wlr_input_inhibit_manager,
seats: std.TailQueue(Seat),
default_seat: *Seat,
seats: std.TailQueue(Seat),
default_seat: *Seat,
exclusive_client: ?*c.wl_client,
exclusive_client: ?*c.wl_client,
listen_inhibit_activate: c.wl_listener,
listen_inhibit_deactivate: c.wl_listener,
listen_new_input: c.wl_listener,
listen_inhibit_activate: c.wl_listener,
listen_inhibit_deactivate: c.wl_listener,
listen_new_input: c.wl_listener,
pub fn init(self: *Self, server: *Server) !void {
pub fn init(self: *Self, server: *Server) !void {
self.server = server;
// This is automatically freed when the display is destroyed
@ -55,33 +55,33 @@ pub const InputManager = struct {
self.listen_new_input.notify = handleNewInput;
c.wl_signal_add(&self.server.wlr_backend.events.new_input, &self.listen_new_input);
}
}
pub fn deinit(self: *Self) void {
pub fn deinit(self: *Self) void {
while (self.seats.pop()) |seat_node| {
seat_node.data.deinit();
self.server.allocator.destroy(seat_node);
}
}
}
/// Must be called whenever a view is unmapped.
pub fn handleViewUnmap(self: Self, view: *View) void {
/// Must be called whenever a view is unmapped.
pub fn handleViewUnmap(self: Self, view: *View) void {
var it = self.seats.first;
while (it) |node| : (it = node.next) {
const seat = &node.data;
seat.handleViewUnmap(view);
}
}
}
/// Returns true if input is currently allowed on the passed surface.
pub fn inputAllowed(self: Self, wlr_surface: *c.wlr_surface) bool {
/// Returns true if input is currently allowed on the passed surface.
pub fn inputAllowed(self: Self, wlr_surface: *c.wlr_surface) bool {
return if (self.exclusive_client) |exclusive_client|
exclusive_client == c.wl_resource_get_client(wlr_surface.resource)
else
true;
}
}
fn handleInhibitActivate(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
fn handleInhibitActivate(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
const self = @fieldParentPtr(Self, "listen_inhibit_activate", listener.?);
Log.Debug.log("Input inhibitor activated", .{});
@ -93,9 +93,9 @@ pub const InputManager = struct {
}
self.exclusive_client = self.wlr_input_inhibit_manager.active_client;
}
}
fn handleInhibitDeactivate(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
fn handleInhibitDeactivate(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
const self = @fieldParentPtr(Self, "listen_inhibit_deactivate", listener.?);
Log.Debug.log("Input inhibitor deactivated", .{});
@ -115,10 +115,10 @@ pub const InputManager = struct {
while (seat_it) |seat_node| : (seat_it = seat_node.next) {
seat_node.data.focus(null);
}
}
}
/// This event is raised by the backend when a new input device becomes available.
fn handleNewInput(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
/// This event is raised by the backend when a new input device becomes available.
fn handleNewInput(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
const self = @fieldParentPtr(Self, "listen_new_input", listener.?);
const device = @ptrCast(*c.wlr_input_device, @alignCast(@alignOf(*c.wlr_input_device), data));
@ -126,5 +126,4 @@ pub const InputManager = struct {
if (self.seats.first) |seat_node| {
seat_node.data.addDevice(device) catch unreachable;
}
}
};
}

View file

@ -2,7 +2,7 @@ const c = @import("c.zig");
const std = @import("std");
const Cursor = @import("cursor.zig").Cursor;
const InputManager = @import("input_manager.zig").InputManager;
const InputManager = @import("input_manager.zig");
const Keyboard = @import("keyboard.zig").Keyboard;
const LayerSurface = @import("layer_surface.zig").LayerSurface;
const Output = @import("output.zig").Output;

View file

@ -6,7 +6,7 @@ const c = @import("c.zig");
const Config = @import("config.zig");
const DecorationManager = @import("decoration_manager.zig");
const InputManager = @import("input_manager.zig").InputManager;
const InputManager = @import("input_manager.zig");
const Log = @import("log.zig").Log;
const Output = @import("output.zig").Output;
const Root = @import("root.zig").Root;