From 904b623b848430bfde22ce3ac4fb0a618c8e1450 Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Thu, 14 Mar 2024 12:21:21 +0100 Subject: [PATCH] XwaylandView: eliminate "self" naming convention --- river/XwaylandView.zig | 190 ++++++++++++++++++++--------------------- 1 file changed, 95 insertions(+), 95 deletions(-) diff --git a/river/XwaylandView.zig b/river/XwaylandView.zig index 52d0d12..57bcb58 100644 --- a/river/XwaylandView.zig +++ b/river/XwaylandView.zig @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -const Self = @This(); +const XwaylandView = @This(); const std = @import("std"); const assert = std.debug.assert; @@ -66,133 +66,133 @@ pub fn create(xwayland_surface: *wlr.XwaylandSurface) error{OutOfMemory}!void { } }); errdefer view.destroy(); - const self = &view.impl.xwayland_view; - self.view = view; + const xwayland_view = &view.impl.xwayland_view; + xwayland_view.view = view; // Add listeners that are active over the view's entire lifetime - xwayland_surface.events.destroy.add(&self.destroy); - xwayland_surface.events.associate.add(&self.associate); - xwayland_surface.events.dissociate.add(&self.dissociate); - xwayland_surface.events.request_configure.add(&self.request_configure); - xwayland_surface.events.set_override_redirect.add(&self.set_override_redirect); + xwayland_surface.events.destroy.add(&xwayland_view.destroy); + xwayland_surface.events.associate.add(&xwayland_view.associate); + xwayland_surface.events.dissociate.add(&xwayland_view.dissociate); + xwayland_surface.events.request_configure.add(&xwayland_view.request_configure); + xwayland_surface.events.set_override_redirect.add(&xwayland_view.set_override_redirect); if (xwayland_surface.surface) |surface| { - handleAssociate(&self.associate); + handleAssociate(&xwayland_view.associate); if (surface.mapped) { - handleMap(&self.map); + handleMap(&xwayland_view.map); } } } /// Always returns false as we do not care about frame perfection for Xwayland views. -pub fn configure(self: Self) bool { - const output = self.view.inflight.output orelse return false; +pub fn configure(xwayland_view: XwaylandView) bool { + const output = xwayland_view.view.inflight.output orelse return false; var output_box: wlr.Box = undefined; server.root.output_layout.getBox(output.wlr_output, &output_box); - const inflight = &self.view.inflight; - const current = &self.view.current; + const inflight = &xwayland_view.view.inflight; + const current = &xwayland_view.view.current; - if (self.xwayland_surface.x == inflight.box.x + output_box.x and - self.xwayland_surface.y == inflight.box.y + output_box.y and - self.xwayland_surface.width == inflight.box.width and - self.xwayland_surface.height == inflight.box.height and + if (xwayland_view.xwayland_surface.x == inflight.box.x + output_box.x and + xwayland_view.xwayland_surface.y == inflight.box.y + output_box.y and + xwayland_view.xwayland_surface.width == inflight.box.width and + xwayland_view.xwayland_surface.height == inflight.box.height and (inflight.focus != 0) == (current.focus != 0) and - (output.inflight.fullscreen == self.view) == - (current.output != null and current.output.?.current.fullscreen == self.view)) + (output.inflight.fullscreen == xwayland_view.view) == + (current.output != null and current.output.?.current.fullscreen == xwayland_view.view)) { return false; } - self.xwayland_surface.configure( + xwayland_view.xwayland_surface.configure( @intCast(inflight.box.x + output_box.x), @intCast(inflight.box.y + output_box.y), @intCast(inflight.box.width), @intCast(inflight.box.height), ); - self.setActivated(inflight.focus != 0); + xwayland_view.setActivated(inflight.focus != 0); - self.xwayland_surface.setFullscreen(output.inflight.fullscreen == self.view); + xwayland_view.xwayland_surface.setFullscreen(output.inflight.fullscreen == xwayland_view.view); return false; } -pub fn rootSurface(self: Self) *wlr.Surface { - return self.xwayland_surface.surface.?; +pub fn rootSurface(xwayland_view: XwaylandView) *wlr.Surface { + return xwayland_view.xwayland_surface.surface.?; } /// Close the view. This will lead to the unmap and destroy events being sent -pub fn close(self: Self) void { - self.xwayland_surface.close(); +pub fn close(xwayland_view: XwaylandView) void { + xwayland_view.xwayland_surface.close(); } -fn setActivated(self: Self, activated: bool) void { +fn setActivated(xwayland_view: XwaylandView, activated: bool) void { // See comment on handleRequestMinimize() for details - if (activated and self.xwayland_surface.minimized) { - self.xwayland_surface.setMinimized(false); + if (activated and xwayland_view.xwayland_surface.minimized) { + xwayland_view.xwayland_surface.setMinimized(false); } - self.xwayland_surface.activate(activated); + xwayland_view.xwayland_surface.activate(activated); if (activated) { - self.xwayland_surface.restack(null, .above); + xwayland_view.xwayland_surface.restack(null, .above); } } /// Get the current title of the xwayland surface if any. -pub fn getTitle(self: Self) ?[*:0]const u8 { - return self.xwayland_surface.title; +pub fn getTitle(xwayland_view: XwaylandView) ?[*:0]const u8 { + return xwayland_view.xwayland_surface.title; } /// X11 clients don't have an app_id but the class serves a similar role. /// Get the current class of the xwayland surface if any. -pub fn getAppId(self: Self) ?[*:0]const u8 { - return self.xwayland_surface.class; +pub fn getAppId(xwayland_view: XwaylandView) ?[*:0]const u8 { + return xwayland_view.xwayland_surface.class; } fn handleDestroy(listener: *wl.Listener(void)) void { - const self = @fieldParentPtr(Self, "destroy", listener); + const xwayland_view = @fieldParentPtr(XwaylandView, "destroy", listener); // Remove listeners that are active for the entire lifetime of the view - self.destroy.link.remove(); - self.associate.link.remove(); - self.dissociate.link.remove(); - self.request_configure.link.remove(); - self.set_override_redirect.link.remove(); + xwayland_view.destroy.link.remove(); + xwayland_view.associate.link.remove(); + xwayland_view.dissociate.link.remove(); + xwayland_view.request_configure.link.remove(); + xwayland_view.set_override_redirect.link.remove(); - const view = self.view; + const view = xwayland_view.view; view.impl = .none; view.destroy(); } fn handleAssociate(listener: *wl.Listener(void)) void { - const self = @fieldParentPtr(Self, "associate", listener); + const xwayland_view = @fieldParentPtr(XwaylandView, "associate", listener); - self.xwayland_surface.surface.?.events.map.add(&self.map); - self.xwayland_surface.surface.?.events.unmap.add(&self.unmap); + xwayland_view.xwayland_surface.surface.?.events.map.add(&xwayland_view.map); + xwayland_view.xwayland_surface.surface.?.events.unmap.add(&xwayland_view.unmap); } fn handleDissociate(listener: *wl.Listener(void)) void { - const self = @fieldParentPtr(Self, "dissociate", listener); - self.map.link.remove(); - self.unmap.link.remove(); + const xwayland_view = @fieldParentPtr(XwaylandView, "dissociate", listener); + xwayland_view.map.link.remove(); + xwayland_view.unmap.link.remove(); } pub fn handleMap(listener: *wl.Listener(void)) void { - const self = @fieldParentPtr(Self, "map", listener); - const view = self.view; + const xwayland_view = @fieldParentPtr(XwaylandView, "map", listener); + const view = xwayland_view.view; - const xwayland_surface = self.xwayland_surface; + const xwayland_surface = xwayland_view.xwayland_surface; const surface = xwayland_surface.surface.?; surface.data = @intFromPtr(&view.tree.node); // Add listeners that are only active while mapped - xwayland_surface.events.set_title.add(&self.set_title); - xwayland_surface.events.set_class.add(&self.set_class); - xwayland_surface.events.set_decorations.add(&self.set_decorations); - xwayland_surface.events.request_fullscreen.add(&self.request_fullscreen); - xwayland_surface.events.request_minimize.add(&self.request_minimize); + xwayland_surface.events.set_title.add(&xwayland_view.set_title); + xwayland_surface.events.set_class.add(&xwayland_view.set_class); + xwayland_surface.events.set_decorations.add(&xwayland_view.set_decorations); + xwayland_surface.events.request_fullscreen.add(&xwayland_view.request_fullscreen); + xwayland_surface.events.request_minimize.add(&xwayland_view.request_minimize); - self.surface_tree = view.surface_tree.createSceneSubsurfaceTree(surface) catch { + xwayland_view.surface_tree = view.surface_tree.createSceneSubsurfaceTree(surface) catch { log.err("out of memory", .{}); surface.resource.getClient().postNoMemory(); return; @@ -201,20 +201,20 @@ pub fn handleMap(listener: *wl.Listener(void)) void { view.pending.box = .{ .x = 0, .y = 0, - .width = self.xwayland_surface.width, - .height = self.xwayland_surface.height, + .width = xwayland_view.xwayland_surface.width, + .height = xwayland_view.xwayland_surface.height, }; view.inflight.box = view.pending.box; view.current.box = view.pending.box; // A value of -1 seems to indicate being unset for these size hints. - const has_fixed_size = if (self.xwayland_surface.size_hints) |size_hints| + const has_fixed_size = if (xwayland_view.xwayland_surface.size_hints) |size_hints| size_hints.min_width > 0 and size_hints.min_height > 0 and (size_hints.min_width == size_hints.max_width or size_hints.min_height == size_hints.max_height) else false; - if (self.xwayland_surface.parent != null or has_fixed_size) { + if (xwayland_view.xwayland_surface.parent != null or has_fixed_size) { // If the toplevel has a parent or has a fixed size make it float by default. // This will be overwritten in View.map() if the view is matched by a rule. view.pending.float = true; @@ -232,49 +232,49 @@ pub fn handleMap(listener: *wl.Listener(void)) void { } fn handleUnmap(listener: *wl.Listener(void)) void { - const self = @fieldParentPtr(Self, "unmap", listener); + const xwayland_view = @fieldParentPtr(XwaylandView, "unmap", listener); - self.xwayland_surface.surface.?.data = 0; + xwayland_view.xwayland_surface.surface.?.data = 0; // Remove listeners that are only active while mapped - self.set_title.link.remove(); - self.set_class.link.remove(); - self.request_fullscreen.link.remove(); - self.request_minimize.link.remove(); + xwayland_view.set_title.link.remove(); + xwayland_view.set_class.link.remove(); + xwayland_view.request_fullscreen.link.remove(); + xwayland_view.request_minimize.link.remove(); - self.view.unmap(); + xwayland_view.view.unmap(); // Don't destroy the surface tree until after View.unmap() has a chance // to save buffers for frame perfection. - self.surface_tree.?.node.destroy(); - self.surface_tree = null; + xwayland_view.surface_tree.?.node.destroy(); + xwayland_view.surface_tree = null; } fn handleRequestConfigure( listener: *wl.Listener(*wlr.XwaylandSurface.event.Configure), event: *wlr.XwaylandSurface.event.Configure, ) void { - const self = @fieldParentPtr(Self, "request_configure", listener); + const xwayland_view = @fieldParentPtr(XwaylandView, "request_configure", listener); // If unmapped, let the client do whatever it wants - if (self.xwayland_surface.surface == null or - !self.xwayland_surface.surface.?.mapped) + if (xwayland_view.xwayland_surface.surface == null or + !xwayland_view.xwayland_surface.surface.?.mapped) { - self.xwayland_surface.configure(event.x, event.y, event.width, event.height); + xwayland_view.xwayland_surface.configure(event.x, event.y, event.width, event.height); return; } // Allow xwayland views to set their own dimensions (but not position) if floating - if (self.view.pending.float) { - self.view.pending.box.width = event.width; - self.view.pending.box.height = event.height; + if (xwayland_view.view.pending.float) { + xwayland_view.view.pending.box.width = event.width; + xwayland_view.view.pending.box.height = event.height; } server.root.applyPending(); } fn handleSetOverrideRedirect(listener: *wl.Listener(void)) void { - const self = @fieldParentPtr(Self, "set_override_redirect", listener); - const xwayland_surface = self.xwayland_surface; + const xwayland_view = @fieldParentPtr(XwaylandView, "set_override_redirect", listener); + const xwayland_surface = xwayland_view.xwayland_surface; log.debug("xwayland surface set override redirect", .{}); @@ -282,11 +282,11 @@ fn handleSetOverrideRedirect(listener: *wl.Listener(void)) void { if (xwayland_surface.surface) |surface| { if (surface.mapped) { - handleUnmap(&self.unmap); + handleUnmap(&xwayland_view.unmap); } - handleDissociate(&self.dissociate); + handleDissociate(&xwayland_view.dissociate); } - handleDestroy(&self.destroy); + handleDestroy(&xwayland_view.destroy); XwaylandOverrideRedirect.create(xwayland_surface) catch { log.err("out of memory", .{}); @@ -295,21 +295,21 @@ fn handleSetOverrideRedirect(listener: *wl.Listener(void)) void { } fn handleSetTitle(listener: *wl.Listener(void)) void { - const self = @fieldParentPtr(Self, "set_title", listener); - self.view.notifyTitle(); + const xwayland_view = @fieldParentPtr(XwaylandView, "set_title", listener); + xwayland_view.view.notifyTitle(); } fn handleSetClass(listener: *wl.Listener(void)) void { - const self = @fieldParentPtr(Self, "set_class", listener); - self.view.notifyAppId(); + const xwayland_view = @fieldParentPtr(XwaylandView, "set_class", listener); + xwayland_view.view.notifyAppId(); } fn handleSetDecorations(listener: *wl.Listener(void)) void { - const self = @fieldParentPtr(Self, "set_decorations", listener); - const view = self.view; + const xwayland_view = @fieldParentPtr(XwaylandView, "set_decorations", listener); + const view = xwayland_view.view; const ssd = server.config.rules.ssd.match(view) orelse - !self.xwayland_surface.decorations.no_border; + !xwayland_view.xwayland_surface.decorations.no_border; if (view.pending.ssd != ssd) { view.pending.ssd = ssd; @@ -318,9 +318,9 @@ fn handleSetDecorations(listener: *wl.Listener(void)) void { } fn handleRequestFullscreen(listener: *wl.Listener(void)) void { - const self = @fieldParentPtr(Self, "request_fullscreen", listener); - if (self.view.pending.fullscreen != self.xwayland_surface.fullscreen) { - self.view.pending.fullscreen = self.xwayland_surface.fullscreen; + const xwayland_view = @fieldParentPtr(XwaylandView, "request_fullscreen", listener); + if (xwayland_view.view.pending.fullscreen != xwayland_view.xwayland_surface.fullscreen) { + xwayland_view.view.pending.fullscreen = xwayland_view.xwayland_surface.fullscreen; server.root.applyPending(); } } @@ -333,6 +333,6 @@ fn handleRequestMinimize( listener: *wl.Listener(*wlr.XwaylandSurface.event.Minimize), event: *wlr.XwaylandSurface.event.Minimize, ) void { - const self = @fieldParentPtr(Self, "request_minimize", listener); - self.xwayland_surface.setMinimized(event.minimize); + const xwayland_view = @fieldParentPtr(XwaylandView, "request_minimize", listener); + xwayland_view.xwayland_surface.setMinimized(event.minimize); }