code: create util.allocator and use globally

river is not a library and passing a general purpose allocators around
everywhere does not make sense and leads to ugly code. This does not
prevent us from using local arenas if they are fitting.
This commit is contained in:
Isaac Freund
2020-06-16 22:08:36 +02:00
parent fb8d855ec9
commit c5de1641dc
17 changed files with 76 additions and 86 deletions

View File

@ -63,21 +63,19 @@ pub fn init(
fn handleDestroy(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
const self = @fieldParentPtr(Self, "listen_destroy", listener.?);
const allocator = self.output.root.server.allocator;
c.wl_list_remove(&self.listen_destroy.link);
c.wl_list_remove(&self.listen_new_popup.link);
allocator.destroy(self);
util.allocator.destroy(self);
}
/// Called when a new xdg popup is requested by the client
fn handleNewPopup(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
const self = @fieldParentPtr(Self, "listen_new_popup", listener.?);
const wlr_xdg_popup = util.voidCast(c.wlr_xdg_popup, data.?);
const allocator = self.output.root.server.allocator;
// This will free itself on destroy
var xdg_popup = allocator.create(Self) catch unreachable;
var xdg_popup = util.allocator.create(Self) catch unreachable;
xdg_popup.init(self.output, self.parent_box, wlr_xdg_popup);
}