Layout: eliminate "self" naming convention

This commit is contained in:
Isaac Freund 2024-03-14 12:02:32 +01:00
parent dabf7e9e97
commit aadb92dc0b
No known key found for this signature in database
GPG Key ID: 86DED400DDFD7A11
3 changed files with 51 additions and 51 deletions

View File

@ -14,7 +14,7 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
const Self = @This(); const Layout = @This();
const std = @import("std"); const std = @import("std");
const assert = std.debug.assert; const assert = std.debug.assert;
@ -34,29 +34,29 @@ const LayoutDemand = @import("LayoutDemand.zig");
const log = std.log.scoped(.layout); const log = std.log.scoped(.layout);
layout: *river.LayoutV3, layout_v3: *river.LayoutV3,
namespace: []const u8, namespace: []const u8,
output: *Output, output: *Output,
pub fn create(client: *wl.Client, version: u32, id: u32, output: *Output, namespace: []const u8) !void { pub fn create(client: *wl.Client, version: u32, id: u32, output: *Output, namespace: []const u8) !void {
const layout = try river.LayoutV3.create(client, version, id); const layout_v3 = try river.LayoutV3.create(client, version, id);
if (namespaceInUse(namespace, output, client)) { if (namespaceInUse(namespace, output, client)) {
layout.sendNamespaceInUse(); layout_v3.sendNamespaceInUse();
layout.setHandler(?*anyopaque, handleRequestInert, null, null); layout_v3.setHandler(?*anyopaque, handleRequestInert, null, null);
return; return;
} }
const node = try util.gpa.create(std.TailQueue(Self).Node); const node = try util.gpa.create(std.TailQueue(Layout).Node);
errdefer util.gpa.destroy(node); errdefer util.gpa.destroy(node);
node.data = .{ node.data = .{
.layout = layout, .layout_v3 = layout_v3,
.namespace = try util.gpa.dupe(u8, namespace), .namespace = try util.gpa.dupe(u8, namespace),
.output = output, .output = output,
}; };
output.layouts.append(node); output.layouts.append(node);
layout.setHandler(*Self, handleRequest, handleDestroy, &node.data); layout_v3.setHandler(*Layout, handleRequest, handleDestroy, &node.data);
// If the namespace matches that of the output, set the layout as // If the namespace matches that of the output, set the layout as
// the active one of the output and arrange it. // the active one of the output and arrange it.
@ -81,7 +81,7 @@ fn namespaceInUse(namespace: []const u8, output: *Output, client: *wl.Client) bo
// Layouts on other outputs may share the namespace, if they come from the same client. // Layouts on other outputs may share the namespace, if they come from the same client.
while (layout_it) |layout_node| : (layout_it = layout_node.next) { while (layout_it) |layout_node| : (layout_it = layout_node.next) {
if (mem.eql(u8, namespace, layout_node.data.namespace) and if (mem.eql(u8, namespace, layout_node.data.namespace) and
client != layout_node.data.layout.getClient()) return true; client != layout_node.data.layout_v3.getClient()) return true;
} }
} }
} }
@ -90,47 +90,47 @@ fn namespaceInUse(namespace: []const u8, output: *Output, client: *wl.Client) bo
/// This exists to handle layouts that have been rendered inert (due to the /// This exists to handle layouts that have been rendered inert (due to the
/// namespace already being in use) until the client destroys them. /// namespace already being in use) until the client destroys them.
fn handleRequestInert(layout: *river.LayoutV3, request: river.LayoutV3.Request, _: ?*anyopaque) void { fn handleRequestInert(layout_v3: *river.LayoutV3, request: river.LayoutV3.Request, _: ?*anyopaque) void {
if (request == .destroy) layout.destroy(); if (request == .destroy) layout_v3.destroy();
} }
/// Send a layout demand to the client /// Send a layout demand to the client
pub fn startLayoutDemand(self: *Self, views: u32) void { pub fn startLayoutDemand(layout: *Layout, views: u32) void {
log.debug( log.debug(
"starting layout demand '{s}' on output '{s}'", "starting layout demand '{s}' on output '{s}'",
.{ self.namespace, self.output.wlr_output.name }, .{ layout.namespace, layout.output.wlr_output.name },
); );
assert(self.output.inflight.layout_demand == null); assert(layout.output.inflight.layout_demand == null);
self.output.inflight.layout_demand = LayoutDemand.init(self, views) catch { layout.output.inflight.layout_demand = LayoutDemand.init(layout, views) catch {
log.err("failed starting layout demand", .{}); log.err("failed starting layout demand", .{});
return; return;
}; };
self.layout.sendLayoutDemand( layout.layout_v3.sendLayoutDemand(
views, views,
@intCast(self.output.usable_box.width), @intCast(layout.output.usable_box.width),
@intCast(self.output.usable_box.height), @intCast(layout.output.usable_box.height),
self.output.pending.tags, layout.output.pending.tags,
self.output.inflight.layout_demand.?.serial, layout.output.inflight.layout_demand.?.serial,
); );
server.root.inflight_layout_demands += 1; server.root.inflight_layout_demands += 1;
} }
fn handleRequest(layout: *river.LayoutV3, request: river.LayoutV3.Request, self: *Self) void { fn handleRequest(layout_v3: *river.LayoutV3, request: river.LayoutV3.Request, layout: *Layout) void {
switch (request) { switch (request) {
.destroy => layout.destroy(), .destroy => layout_v3.destroy(),
// We receive this event when the client wants to push a view dimension proposal // We receive this event when the client wants to push a view dimension proposal
// to the layout demand matching the serial. // to the layout demand matching the serial.
.push_view_dimensions => |req| { .push_view_dimensions => |req| {
log.debug( log.debug(
"layout '{s}' on output '{s}' pushed view dimensions: {} {} {} {}", "layout '{s}' on output '{s}' pushed view dimensions: {} {} {} {}",
.{ self.namespace, self.output.wlr_output.name, req.x, req.y, req.width, req.height }, .{ layout.namespace, layout.output.wlr_output.name, req.x, req.y, req.width, req.height },
); );
if (self.output.inflight.layout_demand) |*layout_demand| { if (layout.output.inflight.layout_demand) |*layout_demand| {
// We can't raise a protocol error when the serial is old/wrong // We can't raise a protocol error when the serial is old/wrong
// because we do not keep track of old serials server-side. // because we do not keep track of old serials server-side.
// Therefore, simply ignore requests with old/wrong serials. // Therefore, simply ignore requests with old/wrong serials.
@ -149,64 +149,64 @@ fn handleRequest(layout: *river.LayoutV3, request: river.LayoutV3.Request, self:
.commit => |req| { .commit => |req| {
log.debug( log.debug(
"layout '{s}' on output '{s}' commited", "layout '{s}' on output '{s}' commited",
.{ self.namespace, self.output.wlr_output.name }, .{ layout.namespace, layout.output.wlr_output.name },
); );
if (self.output.inflight.layout_demand) |*layout_demand| { if (layout.output.inflight.layout_demand) |*layout_demand| {
// We can't raise a protocol error when the serial is old/wrong // We can't raise a protocol error when the serial is old/wrong
// because we do not keep track of old serials server-side. // because we do not keep track of old serials server-side.
// Therefore, simply ignore requests with old/wrong serials. // Therefore, simply ignore requests with old/wrong serials.
if (layout_demand.serial == req.serial) layout_demand.apply(self); if (layout_demand.serial == req.serial) layout_demand.apply(layout);
} }
const new_name = mem.sliceTo(req.layout_name, 0); const new_name = mem.sliceTo(req.layout_name, 0);
if (self.output.layout_name == null or if (layout.output.layout_name == null or
!mem.eql(u8, self.output.layout_name.?, new_name)) !mem.eql(u8, layout.output.layout_name.?, new_name))
{ {
const owned = util.gpa.dupeZ(u8, new_name) catch { const owned = util.gpa.dupeZ(u8, new_name) catch {
log.err("out of memory", .{}); log.err("out of memory", .{});
return; return;
}; };
if (self.output.layout_name) |name| util.gpa.free(name); if (layout.output.layout_name) |name| util.gpa.free(name);
self.output.layout_name = owned; layout.output.layout_name = owned;
self.output.status.sendLayoutName(self.output); layout.output.status.sendLayoutName(layout.output);
} }
}, },
} }
} }
fn handleDestroy(_: *river.LayoutV3, self: *Self) void { fn handleDestroy(_: *river.LayoutV3, layout: *Layout) void {
self.destroy(); layout.destroy();
} }
pub fn destroy(self: *Self) void { pub fn destroy(layout: *Layout) void {
log.debug( log.debug(
"destroying layout '{s}' on output '{s}'", "destroying layout '{s}' on output '{s}'",
.{ self.namespace, self.output.wlr_output.name }, .{ layout.namespace, layout.output.wlr_output.name },
); );
// Remove layout from the list // Remove layout from the list
const node = @fieldParentPtr(std.TailQueue(Self).Node, "data", self); const node = @fieldParentPtr(std.TailQueue(Layout).Node, "data", layout);
self.output.layouts.remove(node); layout.output.layouts.remove(node);
// If we are the currently active layout of an output, clean up. // If we are the currently active layout of an output, clean up.
if (self.output.layout == self) { if (layout.output.layout == layout) {
self.output.layout = null; layout.output.layout = null;
if (self.output.inflight.layout_demand) |*layout_demand| { if (layout.output.inflight.layout_demand) |*layout_demand| {
layout_demand.deinit(); layout_demand.deinit();
self.output.inflight.layout_demand = null; layout.output.inflight.layout_demand = null;
server.root.notifyLayoutDemandDone(); server.root.notifyLayoutDemandDone();
} }
if (self.output.layout_name) |name| { if (layout.output.layout_name) |name| {
util.gpa.free(name); util.gpa.free(name);
self.output.layout_name = null; layout.output.layout_name = null;
self.output.status.sendLayoutNameClear(self.output); layout.output.status.sendLayoutNameClear(layout.output);
} }
} }
self.layout.setHandler(?*anyopaque, handleRequestInert, null, null); layout.layout_v3.setHandler(?*anyopaque, handleRequestInert, null, null);
util.gpa.free(self.namespace); util.gpa.free(layout.namespace);
util.gpa.destroy(node); util.gpa.destroy(node);
} }

View File

@ -116,7 +116,7 @@ pub fn apply(self: *Self, layout: *Layout) void {
"proposed dimension count ({}) does not match view count ({}), aborting layout demand", "proposed dimension count ({}) does not match view count ({}), aborting layout demand",
.{ -self.views + @as(i32, @intCast(self.view_boxen.len)), self.view_boxen.len }, .{ -self.views + @as(i32, @intCast(self.view_boxen.len)), self.view_boxen.len },
); );
layout.layout.postError( layout.layout_v3.postError(
.count_mismatch, .count_mismatch,
"number of proposed view dimensions must match number of views", "number of proposed view dimensions must match number of views",
); );

View File

@ -77,9 +77,9 @@ pub fn sendLayoutCmd(
if (mem.eql(u8, layout.namespace, target_namespace)) break layout; if (mem.eql(u8, layout.namespace, target_namespace)) break layout;
} else return; } else return;
if (layout.layout.getVersion() >= 2) { if (layout.layout_v3.getVersion() >= 2) {
layout.layout.sendUserCommandTags(output.pending.tags); layout.layout_v3.sendUserCommandTags(output.pending.tags);
} }
layout.layout.sendUserCommand(args[2]); layout.layout_v3.sendUserCommand(args[2]);
if (layout == output.layout) server.root.applyPending(); if (layout == output.layout) server.root.applyPending();
} }