Make DecorationManager a toplevel struct

This commit is contained in:
Isaac Freund 2020-05-02 16:23:04 +02:00
parent 5dbff2c018
commit fb766fe09c
No known key found for this signature in database
GPG key ID: 86DED400DDFD7A11
3 changed files with 29 additions and 30 deletions

View file

@ -1,7 +1,7 @@
const std = @import("std");
const c = @import("c.zig");
const DecorationManager = @import("decoration_manager.zig").DecorationManager;
const DecorationManager = @import("decoration_manager.zig");
// TODO: this needs to listen for destroy and free nodes from the deco list
pub const Decoration = struct {

View file

@ -1,41 +1,40 @@
const Self = @This();
const std = @import("std");
const c = @import("c.zig");
const Decoration = @import("decoration.zig").Decoration;
const Server = @import("server.zig");
pub const DecorationManager = struct {
const Self = @This();
server: *Server,
server: *Server,
wlr_xdg_decoration_manager: *c.wlr_xdg_decoration_manager_v1,
wlr_xdg_decoration_manager: *c.wlr_xdg_decoration_manager_v1,
decorations: std.SinglyLinkedList(Decoration),
decorations: std.SinglyLinkedList(Decoration),
listen_new_toplevel_decoration: c.wl_listener,
listen_new_toplevel_decoration: c.wl_listener,
pub fn init(self: *Self, server: *Server) !void {
self.server = server;
self.wlr_xdg_decoration_manager = c.wlr_xdg_decoration_manager_v1_create(server.wl_display) orelse
return error.CantCreateWlrXdgDecorationManager;
pub fn init(self: *Self, server: *Server) !void {
self.server = server;
self.wlr_xdg_decoration_manager = c.wlr_xdg_decoration_manager_v1_create(server.wl_display) orelse
return error.CantCreateWlrXdgDecorationManager;
self.listen_new_toplevel_decoration.notify = handleNewToplevelDecoration;
c.wl_signal_add(
&self.wlr_xdg_decoration_manager.events.new_toplevel_decoration,
&self.listen_new_toplevel_decoration,
);
}
self.listen_new_toplevel_decoration.notify = handleNewToplevelDecoration;
c.wl_signal_add(
&self.wlr_xdg_decoration_manager.events.new_toplevel_decoration,
&self.listen_new_toplevel_decoration,
);
}
fn handleNewToplevelDecoration(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
const self = @fieldParentPtr(Self, "listen_new_toplevel_decoration", listener.?);
const wlr_xdg_toplevel_decoration = @ptrCast(
*c.wlr_xdg_toplevel_decoration_v1,
@alignCast(@alignOf(*c.wlr_xdg_toplevel_decoration_v1), data),
);
fn handleNewToplevelDecoration(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
const self = @fieldParentPtr(Self, "listen_new_toplevel_decoration", listener.?);
const wlr_xdg_toplevel_decoration = @ptrCast(
*c.wlr_xdg_toplevel_decoration_v1,
@alignCast(@alignOf(*c.wlr_xdg_toplevel_decoration_v1), data),
);
const node = self.decorations.allocateNode(self.server.allocator) catch unreachable;
node.data.init(self, wlr_xdg_toplevel_decoration);
self.decorations.prepend(node);
}
};
const node = self.decorations.allocateNode(self.server.allocator) catch unreachable;
node.data.init(self, wlr_xdg_toplevel_decoration);
self.decorations.prepend(node);
}

View file

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