From fb766fe09cebf9b487192099d6e7032481e77f89 Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Sat, 2 May 2020 16:23:04 +0200 Subject: [PATCH] Make DecorationManager a toplevel struct --- src/decoration.zig | 2 +- src/decoration_manager.zig | 55 +++++++++++++++++++------------------- src/server.zig | 2 +- 3 files changed, 29 insertions(+), 30 deletions(-) diff --git a/src/decoration.zig b/src/decoration.zig index 5e8df06..aaf7129 100644 --- a/src/decoration.zig +++ b/src/decoration.zig @@ -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 { diff --git a/src/decoration_manager.zig b/src/decoration_manager.zig index d659159..7106c3d 100644 --- a/src/decoration_manager.zig +++ b/src/decoration_manager.zig @@ -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); +} diff --git a/src/server.zig b/src/server.zig index 63be2e7..600cbb8 100644 --- a/src/server.zig +++ b/src/server.zig @@ -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;