From 693a2b0dda40cd408a684187e1cc28614a9e8bb9 Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Thu, 14 Mar 2024 12:29:49 +0100 Subject: [PATCH] XwaylandOverrideRedirect: eliminate "self" naming convention --- river/Cursor.zig | 14 ++-- river/IdleInhibitorManager.zig | 2 +- river/LockManager.zig | 4 +- river/Root.zig | 6 +- river/SceneNodeData.zig | 2 +- river/Seat.zig | 8 +- river/XwaylandOverrideRedirect.zig | 119 ++++++++++++++++------------- 7 files changed, 82 insertions(+), 73 deletions(-) diff --git a/river/Cursor.zig b/river/Cursor.zig index 5e89934..cb1973e 100644 --- a/river/Cursor.zig +++ b/river/Cursor.zig @@ -402,7 +402,7 @@ fn updateKeyboardFocus(cursor: Cursor, result: Root.AtResult) void { assert(server.lock_manager.state != .unlocked); cursor.seat.setFocusRaw(.{ .lock_surface = lock_surface }); }, - .xwayland_override_redirect => |override_redirect| { + .override_redirect => |override_redirect| { assert(server.lock_manager.state != .locked); override_redirect.focusIfDesired(); }, @@ -1009,7 +1009,7 @@ fn updateFocusFollowsCursorTarget(cursor: *Cursor) void { .layer_surface, .lock_surface => { cursor.focus_follows_cursor_target = null; }, - .xwayland_override_redirect => { + .override_redirect => { assert(build_options.xwayland); assert(server.xwayland != null); cursor.focus_follows_cursor_target = null; @@ -1139,11 +1139,11 @@ fn warp(cursor: *Cursor) void { .width = view.current.box.width, .height = view.current.box.height, }, - .xwayland_override_redirect => |or_window| wlr.Box{ - .x = or_window.xwayland_surface.x, - .y = or_window.xwayland_surface.y, - .width = or_window.xwayland_surface.width, - .height = or_window.xwayland_surface.height, + .override_redirect => |override_redirect| wlr.Box{ + .x = override_redirect.xwayland_surface.x, + .y = override_redirect.xwayland_surface.y, + .width = override_redirect.xwayland_surface.width, + .height = override_redirect.xwayland_surface.height, }, }, }; diff --git a/river/IdleInhibitorManager.zig b/river/IdleInhibitorManager.zig index ec7614d..cefdaea 100644 --- a/river/IdleInhibitorManager.zig +++ b/river/IdleInhibitorManager.zig @@ -51,7 +51,7 @@ pub fn idleInhibitCheckActive(self: *Self) void { break; } }, - .lock_surface, .xwayland_override_redirect => { + .lock_surface, .override_redirect => { inhibited = true; break; }, diff --git a/river/LockManager.zig b/river/LockManager.zig index ae5db2c..670a379 100644 --- a/river/LockManager.zig +++ b/river/LockManager.zig @@ -97,7 +97,7 @@ fn handleLock(listener: *wl.Listener(*wlr.SessionLockV1), lock: *wlr.SessionLock manager.state = .waiting_for_lock_surfaces; if (build_options.xwayland) { - server.root.layers.xwayland_override_redirect.node.setEnabled(false); + server.root.layers.override_redirect.node.setEnabled(false); } manager.lock_surfaces_timer.timerUpdate(200) catch { @@ -207,7 +207,7 @@ fn handleUnlock(listener: *wl.Listener(void)) void { } if (build_options.xwayland) { - server.root.layers.xwayland_override_redirect.node.setEnabled(true); + server.root.layers.override_redirect.node.setEnabled(true); } { diff --git a/river/Root.zig b/river/Root.zig index 7301659..1840951 100644 --- a/river/Root.zig +++ b/river/Root.zig @@ -49,7 +49,7 @@ layers: struct { /// Xwayland override redirect windows are a legacy wart that decide where /// to place themselves in layout coordinates. Unfortunately this is how /// X11 decided to make dropdown menus and the like possible. - xwayland_override_redirect: if (build_options.xwayland) *wlr.SceneTree else void, + override_redirect: if (build_options.xwayland) *wlr.SceneTree else void, }, /// This is kind of like an imaginary output where views start and end their life. @@ -126,7 +126,7 @@ pub fn init(root: *Root) !void { hidden_tree.node.setEnabled(false); const outputs = try interactive_content.createSceneTree(); - const xwayland_override_redirect = if (build_options.xwayland) try interactive_content.createSceneTree(); + const override_redirect = if (build_options.xwayland) try interactive_content.createSceneTree(); _ = try wlr.XdgOutputManagerV1.create(server.wl_server, output_layout); @@ -143,7 +143,7 @@ pub fn init(root: *Root) !void { .drag_icons = drag_icons, .layers = .{ .outputs = outputs, - .xwayland_override_redirect = xwayland_override_redirect, + .override_redirect = override_redirect, }, .hidden = .{ .tree = hidden_tree, diff --git a/river/SceneNodeData.zig b/river/SceneNodeData.zig index fa079c1..45568c9 100644 --- a/river/SceneNodeData.zig +++ b/river/SceneNodeData.zig @@ -31,7 +31,7 @@ pub const Data = union(enum) { view: *View, lock_surface: *LockSurface, layer_surface: *LayerSurface, - xwayland_override_redirect: if (build_options.xwayland) *XwaylandOverrideRedirect else noreturn, + override_redirect: if (build_options.xwayland) *XwaylandOverrideRedirect else noreturn, }; node: *wlr.SceneNode, diff --git a/river/Seat.zig b/river/Seat.zig index 4ebcec5..8751aa7 100644 --- a/river/Seat.zig +++ b/river/Seat.zig @@ -49,7 +49,7 @@ const log = std.log.scoped(.seat); pub const FocusTarget = union(enum) { view: *View, - xwayland_override_redirect: if (build_options.xwayland) *XwaylandOverrideRedirect else noreturn, + override_redirect: if (build_options.xwayland) *XwaylandOverrideRedirect else noreturn, layer: *LayerSurface, lock_surface: *LockSurface, none: void, @@ -57,7 +57,7 @@ pub const FocusTarget = union(enum) { pub fn surface(target: FocusTarget) ?*wlr.Surface { return switch (target) { .view => |view| view.rootSurface(), - .xwayland_override_redirect => |xwayland_or| xwayland_or.xwayland_surface.surface, + .override_redirect => |override_redirect| override_redirect.xwayland_surface.surface, .layer => |layer| layer.wlr_layer_surface.surface, .lock_surface => |lock_surface| lock_surface.wlr_lock_surface.surface, .none => null, @@ -238,7 +238,7 @@ pub fn setFocusRaw(seat: *Seat, new_focus: FocusTarget) void { .layer => |layer_surface| { layer_surface.destroyPopups(); }, - .xwayland_override_redirect, .lock_surface, .none => {}, + .override_redirect, .lock_surface, .none => {}, } // Set the new focus @@ -254,7 +254,7 @@ pub fn setFocusRaw(seat: *Seat, new_focus: FocusTarget) void { assert(seat.focused_output == target_layer.output); }, .lock_surface => assert(server.lock_manager.state != .unlocked), - .xwayland_override_redirect, .none => {}, + .override_redirect, .none => {}, } seat.focused = new_focus; diff --git a/river/XwaylandOverrideRedirect.zig b/river/XwaylandOverrideRedirect.zig index c5f67fd..8a05548 100644 --- a/river/XwaylandOverrideRedirect.zig +++ b/river/XwaylandOverrideRedirect.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 XwaylandOverrideRedirect = @This(); const std = @import("std"); const assert = std.debug.assert; @@ -50,22 +50,22 @@ unmap: wl.Listener(void) = wl.Listener(void).init(handleUnmap), set_geometry: wl.Listener(void) = wl.Listener(void).init(handleSetGeometry), pub fn create(xwayland_surface: *wlr.XwaylandSurface) error{OutOfMemory}!void { - const self = try util.gpa.create(Self); - errdefer util.gpa.destroy(self); + const override_redirect = try util.gpa.create(XwaylandOverrideRedirect); + errdefer util.gpa.destroy(override_redirect); - self.* = .{ .xwayland_surface = xwayland_surface }; + override_redirect.* = .{ .xwayland_surface = xwayland_surface }; - xwayland_surface.events.request_configure.add(&self.request_configure); - xwayland_surface.events.destroy.add(&self.destroy); - xwayland_surface.events.set_override_redirect.add(&self.set_override_redirect); + xwayland_surface.events.request_configure.add(&override_redirect.request_configure); + xwayland_surface.events.destroy.add(&override_redirect.destroy); + xwayland_surface.events.set_override_redirect.add(&override_redirect.set_override_redirect); - xwayland_surface.events.associate.add(&self.associate); - xwayland_surface.events.dissociate.add(&self.dissociate); + xwayland_surface.events.associate.add(&override_redirect.associate); + xwayland_surface.events.dissociate.add(&override_redirect.dissociate); if (xwayland_surface.surface) |surface| { - handleAssociate(&self.associate); + handleAssociate(&override_redirect.associate); if (surface.mapped) { - handleMap(&self.map); + handleMap(&override_redirect.map); } } } @@ -78,59 +78,65 @@ fn handleRequestConfigure( } fn handleDestroy(listener: *wl.Listener(void)) void { - const self = @fieldParentPtr(Self, "destroy", listener); + const override_redirect = @fieldParentPtr(XwaylandOverrideRedirect, "destroy", listener); - self.request_configure.link.remove(); - self.destroy.link.remove(); - self.associate.link.remove(); - self.dissociate.link.remove(); - self.set_override_redirect.link.remove(); + override_redirect.request_configure.link.remove(); + override_redirect.destroy.link.remove(); + override_redirect.associate.link.remove(); + override_redirect.dissociate.link.remove(); + override_redirect.set_override_redirect.link.remove(); - util.gpa.destroy(self); + util.gpa.destroy(override_redirect); } fn handleAssociate(listener: *wl.Listener(void)) void { - const self = @fieldParentPtr(Self, "associate", listener); + const override_redirect = @fieldParentPtr(XwaylandOverrideRedirect, "associate", listener); - self.xwayland_surface.surface.?.events.map.add(&self.map); - self.xwayland_surface.surface.?.events.unmap.add(&self.unmap); + override_redirect.xwayland_surface.surface.?.events.map.add(&override_redirect.map); + override_redirect.xwayland_surface.surface.?.events.unmap.add(&override_redirect.unmap); } fn handleDissociate(listener: *wl.Listener(void)) void { - const self = @fieldParentPtr(Self, "dissociate", listener); + const override_redirect = @fieldParentPtr(XwaylandOverrideRedirect, "dissociate", listener); - self.map.link.remove(); - self.unmap.link.remove(); + override_redirect.map.link.remove(); + override_redirect.unmap.link.remove(); } pub fn handleMap(listener: *wl.Listener(void)) void { - const self = @fieldParentPtr(Self, "map", listener); + const override_redirect = @fieldParentPtr(XwaylandOverrideRedirect, "map", listener); - self.mapImpl() catch { + override_redirect.mapImpl() catch { log.err("out of memory", .{}); - self.xwayland_surface.surface.?.resource.getClient().postNoMemory(); + override_redirect.xwayland_surface.surface.?.resource.getClient().postNoMemory(); }; } -fn mapImpl(self: *Self) error{OutOfMemory}!void { - const surface = self.xwayland_surface.surface.?; - self.surface_tree = try server.root.layers.xwayland_override_redirect.createSceneSubsurfaceTree(surface); - try SceneNodeData.attach(&self.surface_tree.?.node, .{ .xwayland_override_redirect = self }); +fn mapImpl(override_redirect: *XwaylandOverrideRedirect) error{OutOfMemory}!void { + const surface = override_redirect.xwayland_surface.surface.?; + override_redirect.surface_tree = + try server.root.layers.override_redirect.createSceneSubsurfaceTree(surface); + try SceneNodeData.attach(&override_redirect.surface_tree.?.node, .{ + .override_redirect = override_redirect, + }); - surface.data = @intFromPtr(&self.surface_tree.?.node); + surface.data = @intFromPtr(&override_redirect.surface_tree.?.node); - self.surface_tree.?.node.setPosition(self.xwayland_surface.x, self.xwayland_surface.y); + override_redirect.surface_tree.?.node.setPosition( + override_redirect.xwayland_surface.x, + override_redirect.xwayland_surface.y, + ); - self.xwayland_surface.events.set_geometry.add(&self.set_geometry); + override_redirect.xwayland_surface.events.set_geometry.add(&override_redirect.set_geometry); - self.focusIfDesired(); + override_redirect.focusIfDesired(); } -pub fn focusIfDesired(self: *Self) void { +pub fn focusIfDesired(override_redirect: *XwaylandOverrideRedirect) void { if (server.lock_manager.state != .unlocked) return; - if (self.xwayland_surface.overrideRedirectWantsFocus() and - self.xwayland_surface.icccmInputModel() != .none) + if (override_redirect.xwayland_surface.overrideRedirectWantsFocus() and + override_redirect.xwayland_surface.icccmInputModel() != .none) { const seat = server.input_manager.defaultSeat(); // Keep the parent top-level Xwayland view of any override redirect surface @@ -139,23 +145,23 @@ pub fn focusIfDesired(self: *Self) void { // their parent window. if (seat.focused == .view and seat.focused.view.impl == .xwayland_view and - seat.focused.view.impl.xwayland_view.xwayland_surface.pid == self.xwayland_surface.pid) + seat.focused.view.impl.xwayland_view.xwayland_surface.pid == override_redirect.xwayland_surface.pid) { - seat.keyboardEnterOrLeave(self.xwayland_surface.surface); + seat.keyboardEnterOrLeave(override_redirect.xwayland_surface.surface); } else { - seat.setFocusRaw(.{ .xwayland_override_redirect = self }); + seat.setFocusRaw(.{ .override_redirect = override_redirect }); } } } fn handleUnmap(listener: *wl.Listener(void)) void { - const self = @fieldParentPtr(Self, "unmap", listener); + const override_redirect = @fieldParentPtr(XwaylandOverrideRedirect, "unmap", listener); - self.set_geometry.link.remove(); + override_redirect.set_geometry.link.remove(); - self.xwayland_surface.surface.?.data = 0; - self.surface_tree.?.node.destroy(); - self.surface_tree = null; + override_redirect.xwayland_surface.surface.?.data = 0; + override_redirect.surface_tree.?.node.destroy(); + override_redirect.surface_tree = null; // If the unmapped surface is currently focused, pass keyboard focus // to the most appropriate surface. @@ -163,8 +169,8 @@ fn handleUnmap(listener: *wl.Listener(void)) void { while (seat_it) |seat_node| : (seat_it = seat_node.next) { const seat = &seat_node.data; if (seat.focused == .view and seat.focused.view.impl == .xwayland_view and - seat.focused.view.impl.xwayland_view.xwayland_surface.pid == self.xwayland_surface.pid and - seat.wlr_seat.keyboard_state.focused_surface == self.xwayland_surface.surface) + seat.focused.view.impl.xwayland_view.xwayland_surface.pid == override_redirect.xwayland_surface.pid and + seat.wlr_seat.keyboard_state.focused_surface == override_redirect.xwayland_surface.surface) { seat.keyboardEnterOrLeave(seat.focused.view.rootSurface()); } @@ -174,14 +180,17 @@ fn handleUnmap(listener: *wl.Listener(void)) void { } fn handleSetGeometry(listener: *wl.Listener(void)) void { - const self = @fieldParentPtr(Self, "set_geometry", listener); + const override_redirect = @fieldParentPtr(XwaylandOverrideRedirect, "set_geometry", listener); - self.surface_tree.?.node.setPosition(self.xwayland_surface.x, self.xwayland_surface.y); + override_redirect.surface_tree.?.node.setPosition( + override_redirect.xwayland_surface.x, + override_redirect.xwayland_surface.y, + ); } fn handleSetOverrideRedirect(listener: *wl.Listener(void)) void { - const self = @fieldParentPtr(Self, "set_override_redirect", listener); - const xwayland_surface = self.xwayland_surface; + const override_redirect = @fieldParentPtr(XwaylandOverrideRedirect, "set_override_redirect", listener); + const xwayland_surface = override_redirect.xwayland_surface; log.debug("xwayland surface unset override redirect", .{}); @@ -189,11 +198,11 @@ fn handleSetOverrideRedirect(listener: *wl.Listener(void)) void { if (xwayland_surface.surface) |surface| { if (surface.mapped) { - handleUnmap(&self.unmap); + handleUnmap(&override_redirect.unmap); } - handleDissociate(&self.dissociate); + handleDissociate(&override_redirect.dissociate); } - handleDestroy(&self.destroy); + handleDestroy(&override_redirect.destroy); XwaylandView.create(xwayland_surface) catch { log.err("out of memory", .{});