From 5bf161e74412272199603794a1f4e46024fb915c Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Fri, 27 Mar 2020 18:31:03 +0100 Subject: Implement basic xdg decoration management --- src/decoration_manager.zig | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 src/decoration_manager.zig (limited to 'src/decoration_manager.zig') diff --git a/src/decoration_manager.zig b/src/decoration_manager.zig new file mode 100644 index 0000000..d6beb1e --- /dev/null +++ b/src/decoration_manager.zig @@ -0,0 +1,45 @@ +const std = @import("std"); +const c = @import("c.zig").c; + +const Decoration = @import("decoration.zig").Decoration; +const Server = @import("server.zig").Server; + +pub const DecorationManager = struct { + const Self = @This(); + + server: *Server, + + wlr_xdg_decoration_manager: *c.wlr_xdg_decoration_manager_v1, + + decorations: std.SinglyLinkedList(Decoration), + + 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; + + 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 decoration_manager = @fieldParentPtr( + DecorationManager, + "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 = decoration_manager.decorations.allocateNode(decoration_manager.server.allocator) catch unreachable; + node.data.init(decoration_manager, wlr_xdg_toplevel_decoration); + decoration_manager.decorations.prepend(node); + } +}; -- cgit v1.2.3