git.lucas.co / cce-compositor
Wayland compositor (wlroots)
git clone https://git.lucas.co/cce-compositor.git

commitd2119ca8605d5cde1b3b8ade82058f87ffb8cee0
parentc077d62827
authorIsaac Freund <[email protected]>
date2020-06-19 14:31
bikeshed: rename util.allocator to util.gpa

This is less typing and more clear. A definite win.

 river/Config.zig            | 10 +++++-----
 river/Control.zig           | 16 ++++++++--------
 river/Decoration.zig        |  2 +-
 river/DecorationManager.zig |  2 +-
 river/InputManager.zig      |  4 ++--
 river/LayerSurface.zig      |  4 ++--
 river/Output.zig            |  6 +++---
 river/OutputStatus.zig      |  2 +-
 river/Root.zig              |  2 +-
 river/Seat.zig              | 14 +++++++-------
 river/Server.zig            |  8 ++++----
 river/StatusManager.zig     |  8 ++++----
 river/View.zig              |  4 ++--
 river/XdgPopup.zig          |  4 ++--
 river/XdgToplevel.zig       |  2 +-
 river/XwaylandUnmanaged.zig |  2 +-
 river/main.zig              |  2 +-
 river/util.zig              |  2 +-
 18 files changed, 47 insertions(+), 47 deletions(-)

diff --git a/river/Config.zig b/river/Config.zig
index 4d0fd9e..760f5b5 100644
--- a/river/Config.zig
+++ b/river/Config.zig
@@ -56,13 +56,13 @@ pub fn init(self: *Self) !void {
     self.view_padding = 8;
     self.outer_padding = 8;
 
-    self.mode_to_id = std.StringHashMap(usize).init(util.allocator);
+    self.mode_to_id = std.StringHashMap(usize).init(util.gpa);
     try self.mode_to_id.putNoClobber("normal", 0);
 
-    self.modes = std.ArrayList(std.ArrayList(Mapping)).init(util.allocator);
-    try self.modes.append(std.ArrayList(Mapping).init(util.allocator));
+    self.modes = std.ArrayList(std.ArrayList(Mapping)).init(util.gpa);
+    try self.modes.append(std.ArrayList(Mapping).init(util.gpa));
 
-    self.float_filter = std.ArrayList([*:0]const u8).init(util.allocator);
+    self.float_filter = std.ArrayList([*:0]const u8).init(util.gpa);
 
     // Float views with app_id "float"
     try self.float_filter.append("float");
@@ -71,7 +71,7 @@ pub fn init(self: *Self) !void {
 pub fn deinit(self: Self) void {
     self.mode_to_id.deinit();
     for (self.modes.items) |mode| {
-        for (mode.items) |mapping| mapping.deinit(util.allocator);
+        for (mode.items) |mapping| mapping.deinit(util.gpa);
         mode.deinit();
     }
     self.modes.deinit();
diff --git a/river/Control.zig b/river/Control.zig
index 5e56e83..d84f519 100644
--- a/river/Control.zig
+++ b/river/Control.zig
@@ -49,7 +49,7 @@ pub fn init(self: *Self, server: *Server) !void {
         bind,
     ) orelse return error.CantCreateWlGlobal;
 
-    self.args_map = std.AutoHashMap(u32, std.ArrayList([]const u8)).init(util.allocator);
+    self.args_map = std.AutoHashMap(u32, std.ArrayList([]const u8)).init(util.gpa);
 
     self.listen_display_destroy.notify = handleDisplayDestroy;
     c.wl_display_add_destroy_listener(server.wl_display, &self.listen_display_destroy);
@@ -73,7 +73,7 @@ fn bind(wl_client: ?*c.wl_client, data: ?*c_void, version: u32, id: u32) callcon
         c.wl_client_post_no_memory(wl_client);
         return;
     };
-    self.args_map.putNoClobber(id, std.ArrayList([]const u8).init(util.allocator)) catch {
+    self.args_map.putNoClobber(id, std.ArrayList([]const u8).init(util.gpa)) catch {
         c.wl_resource_destroy(wl_resource);
         c.wl_client_post_no_memory(wl_client);
         return;
@@ -98,14 +98,14 @@ fn addArgument(wl_client: ?*c.wl_client, wl_resource: ?*c.wl_resource, arg: ?[*:
     const self = util.voidCast(Self, c.wl_resource_get_user_data(wl_resource).?);
     const id = c.wl_resource_get_id(wl_resource);
 
-    const owned_slice = std.mem.dupe(util.allocator, u8, std.mem.span(arg.?)) catch {
+    const owned_slice = std.mem.dupe(util.gpa, u8, std.mem.span(arg.?)) catch {
         c.wl_client_post_no_memory(wl_client);
         return;
     };
 
     self.args_map.get(id).?.value.append(owned_slice) catch {
         c.wl_client_post_no_memory(wl_client);
-        util.allocator.free(owned_slice);
+        util.gpa.free(owned_slice);
         return;
     };
 }
@@ -135,14 +135,14 @@ fn runCommand(
     const args = self.args_map.get(c.wl_resource_get_id(wl_resource)).?.value.items;
 
     var failure_message: []const u8 = undefined;
-    command.run(util.allocator, seat, args, &failure_message) catch |err| {
+    command.run(util.gpa, seat, args, &failure_message) catch |err| {
         if (err == command.Error.CommandFailed) {
-            defer util.allocator.free(failure_message);
-            const out = std.cstr.addNullByte(util.allocator, failure_message) catch {
+            defer util.gpa.free(failure_message);
+            const out = std.cstr.addNullByte(util.gpa, failure_message) catch {
                 c.zriver_command_callback_v1_send_failure(callback_resource, "out of memory");
                 return;
             };
-            defer util.allocator.free(out);
+            defer util.gpa.free(out);
             c.zriver_command_callback_v1_send_failure(callback_resource, out);
         } else {
             c.zriver_command_callback_v1_send_failure(
diff --git a/river/Decoration.zig b/river/Decoration.zig
index 149fe8d..863ae3f 100644
--- a/river/Decoration.zig
+++ b/river/Decoration.zig
@@ -53,7 +53,7 @@ fn handleDestroy(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
     const node = @fieldParentPtr(std.SinglyLinkedList(Self).Node, "data", self);
 
     self.decoration_manager.decorations.remove(node);
-    util.allocator.destroy(node);
+    util.gpa.destroy(node);
 }
 
 fn handleRequestMode(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
diff --git a/river/DecorationManager.zig b/river/DecorationManager.zig
index 4a78025..1b844e9 100644
--- a/river/DecorationManager.zig
+++ b/river/DecorationManager.zig
@@ -46,7 +46,7 @@ fn handleNewToplevelDecoration(listener: ?*c.wl_listener, data: ?*c_void) callco
     const self = @fieldParentPtr(Self, "listen_new_toplevel_decoration", listener.?);
     const wlr_xdg_toplevel_decoration = util.voidCast(c.wlr_xdg_toplevel_decoration_v1, data.?);
 
-    const node = self.decorations.allocateNode(util.allocator) catch unreachable;
+    const node = self.decorations.allocateNode(util.gpa) catch unreachable;
     node.data.init(self, wlr_xdg_toplevel_decoration);
     self.decorations.prepend(node);
 }
diff --git a/river/InputManager.zig b/river/InputManager.zig
index e9264a0..9c0895c 100644
--- a/river/InputManager.zig
+++ b/river/InputManager.zig
@@ -51,7 +51,7 @@ pub fn init(self: *Self, server: *Server) !void {
 
     self.seats = std.TailQueue(Seat).init();
 
-    const seat_node = try util.allocator.create(std.TailQueue(Seat).Node);
+    const seat_node = try util.gpa.create(std.TailQueue(Seat).Node);
     try seat_node.data.init(self, default_seat_name);
     self.default_seat = &seat_node.data;
     self.seats.prepend(seat_node);
@@ -78,7 +78,7 @@ pub fn init(self: *Self, server: *Server) !void {
 pub fn deinit(self: *Self) void {
     while (self.seats.pop()) |seat_node| {
         seat_node.data.deinit();
-        util.allocator.destroy(seat_node);
+        util.gpa.destroy(seat_node);
     }
 }
 
diff --git a/river/LayerSurface.zig b/river/LayerSurface.zig
index e74b24b..97cf4bc 100644
--- a/river/LayerSurface.zig
+++ b/river/LayerSurface.zig
@@ -87,7 +87,7 @@ fn handleDestroy(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
     c.wl_list_remove(&self.listen_unmap.link);
 
     const node = @fieldParentPtr(std.TailQueue(Self).Node, "data", self);
-    util.allocator.destroy(node);
+    util.gpa.destroy(node);
 }
 
 fn handleMap(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
@@ -191,6 +191,6 @@ fn handleNewPopup(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
     const wlr_xdg_popup = util.voidCast(c.wlr_xdg_popup, data.?);
 
     // This will free itself on destroy
-    var xdg_popup = util.allocator.create(XdgPopup) catch unreachable;
+    var xdg_popup = util.gpa.create(XdgPopup) catch unreachable;
     xdg_popup.init(self.output, &self.box, wlr_xdg_popup);
 }
diff --git a/river/Output.zig b/river/Output.zig
index fa5b6f6..5ac7306 100644
--- a/river/Output.zig
+++ b/river/Output.zig
@@ -111,7 +111,7 @@ pub fn init(self: *Self, root: *Root, wlr_output: *c.wlr_output) !void {
 
     self.master_factor = 0.6;
 
-    self.layout = try std.fmt.allocPrint(util.allocator, "full", .{});
+    self.layout = try std.fmt.allocPrint(util.gpa, "full", .{});
 
     self.status_trackers = std.SinglyLinkedList(OutputStatus).init();
 
@@ -234,7 +234,7 @@ fn layoutExternal(self: *Self, visible_count: u32, output_tags: u32) !void {
     const layout_width = @intCast(u32, self.usable_box.width) - config.outer_padding * 2;
     const layout_height = @intCast(u32, self.usable_box.height) - config.outer_padding * 2;
 
-    var arena = std.heap.ArenaAllocator.init(util.allocator);
+    var arena = std.heap.ArenaAllocator.init(util.gpa);
     defer arena.deinit();
 
     // Assemble command
@@ -619,7 +619,7 @@ fn handleDestroy(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
     // Remove the destroyed output from the list
     const node = @fieldParentPtr(std.TailQueue(Self).Node, "data", self);
     root.outputs.remove(node);
-    util.allocator.destroy(node);
+    util.gpa.destroy(node);
 
     // Arrange the root in case evacuated views affect the layout
     root.arrange();
diff --git a/river/OutputStatus.zig b/river/OutputStatus.zig
index 129570a..a10774d 100644
--- a/river/OutputStatus.zig
+++ b/river/OutputStatus.zig
@@ -57,7 +57,7 @@ fn destroy(wl_client: ?*c.wl_client, wl_resource: ?*c.wl_resource) callconv(.C)
 
 /// Send the current tags of each view on the output to the client.
 pub fn sendViewTags(self: Self) void {
-    var view_tags = std.ArrayList(u32).init(util.allocator);
+    var view_tags = std.ArrayList(u32).init(util.gpa);
     defer view_tags.deinit();
 
     var it = ViewStack(View).iterator(self.output.views.first, std.math.maxInt(u32));
diff --git a/river/Root.zig b/river/Root.zig
index dc1a92a..c5301a8 100644
--- a/river/Root.zig
+++ b/river/Root.zig
@@ -95,7 +95,7 @@ pub fn deinit(self: *Self) void {
 
 pub fn addOutput(self: *Self, wlr_output: *c.wlr_output) void {
     // TODO: Handle failure
-    const node = self.outputs.allocateNode(util.allocator) catch unreachable;
+    const node = self.outputs.allocateNode(util.gpa) catch unreachable;
     node.data.init(self, wlr_output) catch unreachable;
     self.outputs.append(node);
 
diff --git a/river/Seat.zig b/river/Seat.zig
index b2676c3..d025921 100644
--- a/river/Seat.zig
+++ b/river/Seat.zig
@@ -103,11 +103,11 @@ pub fn init(self: *Self, input_manager: *InputManager, name: []const u8) !void {
 pub fn deinit(self: *Self) void {
     self.cursor.deinit();
 
-    while (self.keyboards.pop()) |node| util.allocator.destroy(node);
+    while (self.keyboards.pop()) |node| util.gpa.destroy(node);
 
     while (self.focus_stack.first) |node| {
         self.focus_stack.remove(node);
-        util.allocator.destroy(node);
+        util.gpa.destroy(node);
     }
 }
 
@@ -152,7 +152,7 @@ pub fn focus(self: *Self, _view: ?*View) void {
             }
         } else {
             // The view is not in the stack, so allocate a new node and prepend it
-            const new_focus_node = util.allocator.create(
+            const new_focus_node = util.gpa.create(
                 ViewStack(*View).Node,
             ) catch unreachable;
             new_focus_node.view = view_to_focus;
@@ -256,7 +256,7 @@ pub fn handleViewUnmap(self: *Self, view: *View) void {
     while (it) |node| : (it = node.next) {
         if (node.view == view) {
             self.focus_stack.remove(node);
-            util.allocator.destroy(node);
+            util.gpa.destroy(node);
             break;
         }
     }
@@ -277,10 +277,10 @@ pub fn handleMapping(self: *Self, keysym: c.xkb_keysym_t, modifiers: u32) bool {
         if (modifiers == mapping.modifiers and keysym == mapping.keysym) {
             // Execute the bound command
             var failure_message: []const u8 = undefined;
-            command.run(util.allocator, self, mapping.command_args, &failure_message) catch |err| {
+            command.run(util.gpa, self, mapping.command_args, &failure_message) catch |err| {
                 // TODO: log the error
                 if (err == command.Error.CommandFailed)
-                    util.allocator.free(failure_message);
+                    util.gpa.free(failure_message);
             };
             return true;
         }
@@ -311,7 +311,7 @@ pub fn addDevice(self: *Self, device: *c.wlr_input_device) !void {
 fn addKeyboard(self: *Self, device: *c.wlr_input_device) !void {
     c.wlr_seat_set_keyboard(self.wlr_seat, device);
 
-    const node = try util.allocator.create(std.TailQueue(Keyboard).Node);
+    const node = try util.gpa.create(std.TailQueue(Keyboard).Node);
     try node.data.init(self, device);
     self.keyboards.append(node);
 }
diff --git a/river/Server.zig b/river/Server.zig
index 5667783..5aef0f0 100644
--- a/river/Server.zig
+++ b/river/Server.zig
@@ -186,7 +186,7 @@ fn handleNewXdgSurface(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) v
 
     // The View will add itself to the output's view stack on map
     const output = self.input_manager.default_seat.focused_output;
-    const node = util.allocator.create(ViewStack(View).Node) catch unreachable;
+    const node = util.gpa.create(ViewStack(View).Node) catch unreachable;
     node.view.init(output, output.current_focused_tags, wlr_xdg_surface);
 }
 
@@ -236,7 +236,7 @@ fn handleNewLayerSurface(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C)
 
     // The layer surface will add itself to the proper list of the output on map
     const output = util.voidCast(Output, wlr_layer_surface.output.*.data.?);
-    const node = util.allocator.create(std.TailQueue(LayerSurface).Node) catch unreachable;
+    const node = util.gpa.create(std.TailQueue(LayerSurface).Node) catch unreachable;
     node.data.init(output, wlr_layer_surface);
 }
 
@@ -248,7 +248,7 @@ fn handleNewXwaylandSurface(listener: ?*c.wl_listener, data: ?*c_void) callconv(
         log.debug(.server, "new unmanaged xwayland surface", .{});
         // The unmanged surface will add itself to the list of unmanaged views
         // in Root when it is mapped.
-        const node = util.allocator.create(std.TailQueue(XwaylandUnmanaged).Node) catch unreachable;
+        const node = util.gpa.create(std.TailQueue(XwaylandUnmanaged).Node) catch unreachable;
         node.data.init(&self.root, wlr_xwayland_surface);
         return;
     }
@@ -261,6 +261,6 @@ fn handleNewXwaylandSurface(listener: ?*c.wl_listener, data: ?*c_void) callconv(
 
     // The View will add itself to the output's view stack on map
     const output = self.input_manager.default_seat.focused_output;
-    const node = util.allocator.create(ViewStack(View).Node) catch unreachable;
+    const node = util.gpa.create(ViewStack(View).Node) catch unreachable;
     node.view.init(output, output.current_focused_tags, wlr_xwayland_surface);
 }
diff --git a/river/StatusManager.zig b/river/StatusManager.zig
index c6de81a..4c789e1 100644
--- a/river/StatusManager.zig
+++ b/river/StatusManager.zig
@@ -93,7 +93,7 @@ fn getRiverOutputStatus(
     const wlr_output = c.wlr_output_from_resource(output_wl_resource) orelse return;
     const output = util.voidCast(Output, wlr_output.*.data.?);
 
-    const node = util.allocator.create(std.SinglyLinkedList(OutputStatus).Node) catch {
+    const node = util.gpa.create(std.SinglyLinkedList(OutputStatus).Node) catch {
         c.wl_client_post_no_memory(wl_client);
         log.crit(.river_status, "out of memory", .{});
         return;
@@ -106,7 +106,7 @@ fn getRiverOutputStatus(
         new_id,
     ) orelse {
         c.wl_client_post_no_memory(wl_client);
-        util.allocator.destroy(node);
+        util.gpa.destroy(node);
         log.crit(.river_status, "out of memory", .{});
         return;
     };
@@ -126,7 +126,7 @@ fn getRiverSeatStatus(
     const wlr_seat_client = c.wlr_seat_client_from_resource(seat_wl_resource) orelse return;
     const seat = util.voidCast(Seat, wlr_seat_client.*.seat.*.data.?);
 
-    const node = util.allocator.create(std.SinglyLinkedList(SeatStatus).Node) catch {
+    const node = util.gpa.create(std.SinglyLinkedList(SeatStatus).Node) catch {
         c.wl_client_post_no_memory(wl_client);
         log.crit(.river_status, "out of memory", .{});
         return;
@@ -139,7 +139,7 @@ fn getRiverSeatStatus(
         new_id,
     ) orelse {
         c.wl_client_post_no_memory(wl_client);
-        util.allocator.destroy(node);
+        util.gpa.destroy(node);
         log.crit(.river_status, "out of memory", .{});
         return;
     };
diff --git a/river/View.zig b/river/View.zig
index 12226ec..ca9bed0 100644
--- a/river/View.zig
+++ b/river/View.zig
@@ -108,7 +108,7 @@ pub fn init(self: *Self, output: *Output, tags: u32, surface: var) void {
 
     self.pending_serial = null;
 
-    self.saved_buffers = std.ArrayList(SavedBuffer).init(util.allocator);
+    self.saved_buffers = std.ArrayList(SavedBuffer).init(util.gpa);
 
     if (@TypeOf(surface) == *c.wlr_xdg_surface) {
         self.impl = .{ .xdg_toplevel = undefined };
@@ -318,5 +318,5 @@ pub fn unmap(self: *Self) void {
 pub fn destroy(self: *const Self) void {
     self.deinit();
     const node = @fieldParentPtr(ViewStack(Self).Node, "view", self);
-    util.allocator.destroy(node);
+    util.gpa.destroy(node);
 }
diff --git a/river/XdgPopup.zig b/river/XdgPopup.zig
index ca172ff..b4e50cd 100644
--- a/river/XdgPopup.zig
+++ b/river/XdgPopup.zig
@@ -67,7 +67,7 @@ fn handleDestroy(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
     c.wl_list_remove(&self.listen_destroy.link);
     c.wl_list_remove(&self.listen_new_popup.link);
 
-    util.allocator.destroy(self);
+    util.gpa.destroy(self);
 }
 
 /// Called when a new xdg popup is requested by the client
@@ -76,6 +76,6 @@ fn handleNewPopup(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
     const wlr_xdg_popup = util.voidCast(c.wlr_xdg_popup, data.?);
 
     // This will free itself on destroy
-    var xdg_popup = util.allocator.create(Self) catch unreachable;
+    var xdg_popup = util.gpa.create(Self) catch unreachable;
     xdg_popup.init(self.output, self.parent_box, wlr_xdg_popup);
 }
diff --git a/river/XdgToplevel.zig b/river/XdgToplevel.zig
index ee9b113..ea8858d 100644
--- a/river/XdgToplevel.zig
+++ b/river/XdgToplevel.zig
@@ -246,6 +246,6 @@ fn handleNewPopup(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
     const wlr_xdg_popup = util.voidCast(c.wlr_xdg_popup, data.?);
 
     // This will free itself on destroy
-    var xdg_popup = util.allocator.create(XdgPopup) catch unreachable;
+    var xdg_popup = util.gpa.create(XdgPopup) catch unreachable;
     xdg_popup.init(self.view.output, &self.view.current_box, wlr_xdg_popup);
 }
diff --git a/river/XwaylandUnmanaged.zig b/river/XwaylandUnmanaged.zig
index fe6f366..2a59e7d 100644
--- a/river/XwaylandUnmanaged.zig
+++ b/river/XwaylandUnmanaged.zig
@@ -92,7 +92,7 @@ fn handleDestroy(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
 
     // Deallocate the node
     const node = @fieldParentPtr(std.TailQueue(Self).Node, "data", self);
-    util.allocator.destroy(node);
+    util.gpa.destroy(node);
 }
 
 /// Called when the xwayland surface is mapped, or ready to display on-screen.
diff --git a/river/main.zig b/river/main.zig
index 0060f8a..01988c2 100644
--- a/river/main.zig
+++ b/river/main.zig
@@ -77,7 +77,7 @@ pub fn main() !void {
 
     if (startup_command) |cmd| {
         const child_args = [_][]const u8{ "/bin/sh", "-c", cmd };
-        const child = try std.ChildProcess.init(&child_args, util.allocator);
+        const child = try std.ChildProcess.init(&child_args, util.gpa);
         defer child.deinit();
         try std.ChildProcess.spawn(child);
     }
diff --git a/river/util.zig b/river/util.zig
index 28eb840..64b4b30 100644
--- a/river/util.zig
+++ b/river/util.zig
@@ -18,7 +18,7 @@
 const std = @import("std");
 
 /// The global general-purpose allocator used throughout river's code
-pub const allocator = std.heap.c_allocator;
+pub const gpa = std.heap.c_allocator;
 
 /// Take a pointer to c_void and cast it to a pointer to T. This function
 /// exists to avoid having the verbosity of the required alignment casts all