XwaylandOverrideRedirect: eliminate "self" naming convention

This commit is contained in:
Isaac Freund 2024-03-14 12:29:49 +01:00
parent 28f30b2571
commit 693a2b0dda
No known key found for this signature in database
GPG Key ID: 86DED400DDFD7A11
7 changed files with 82 additions and 73 deletions

View File

@ -402,7 +402,7 @@ fn updateKeyboardFocus(cursor: Cursor, result: Root.AtResult) void {
assert(server.lock_manager.state != .unlocked); assert(server.lock_manager.state != .unlocked);
cursor.seat.setFocusRaw(.{ .lock_surface = lock_surface }); cursor.seat.setFocusRaw(.{ .lock_surface = lock_surface });
}, },
.xwayland_override_redirect => |override_redirect| { .override_redirect => |override_redirect| {
assert(server.lock_manager.state != .locked); assert(server.lock_manager.state != .locked);
override_redirect.focusIfDesired(); override_redirect.focusIfDesired();
}, },
@ -1009,7 +1009,7 @@ fn updateFocusFollowsCursorTarget(cursor: *Cursor) void {
.layer_surface, .lock_surface => { .layer_surface, .lock_surface => {
cursor.focus_follows_cursor_target = null; cursor.focus_follows_cursor_target = null;
}, },
.xwayland_override_redirect => { .override_redirect => {
assert(build_options.xwayland); assert(build_options.xwayland);
assert(server.xwayland != null); assert(server.xwayland != null);
cursor.focus_follows_cursor_target = null; cursor.focus_follows_cursor_target = null;
@ -1139,11 +1139,11 @@ fn warp(cursor: *Cursor) void {
.width = view.current.box.width, .width = view.current.box.width,
.height = view.current.box.height, .height = view.current.box.height,
}, },
.xwayland_override_redirect => |or_window| wlr.Box{ .override_redirect => |override_redirect| wlr.Box{
.x = or_window.xwayland_surface.x, .x = override_redirect.xwayland_surface.x,
.y = or_window.xwayland_surface.y, .y = override_redirect.xwayland_surface.y,
.width = or_window.xwayland_surface.width, .width = override_redirect.xwayland_surface.width,
.height = or_window.xwayland_surface.height, .height = override_redirect.xwayland_surface.height,
}, },
}, },
}; };

View File

@ -51,7 +51,7 @@ pub fn idleInhibitCheckActive(self: *Self) void {
break; break;
} }
}, },
.lock_surface, .xwayland_override_redirect => { .lock_surface, .override_redirect => {
inhibited = true; inhibited = true;
break; break;
}, },

View File

@ -97,7 +97,7 @@ fn handleLock(listener: *wl.Listener(*wlr.SessionLockV1), lock: *wlr.SessionLock
manager.state = .waiting_for_lock_surfaces; manager.state = .waiting_for_lock_surfaces;
if (build_options.xwayland) { 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 { manager.lock_surfaces_timer.timerUpdate(200) catch {
@ -207,7 +207,7 @@ fn handleUnlock(listener: *wl.Listener(void)) void {
} }
if (build_options.xwayland) { if (build_options.xwayland) {
server.root.layers.xwayland_override_redirect.node.setEnabled(true); server.root.layers.override_redirect.node.setEnabled(true);
} }
{ {

View File

@ -49,7 +49,7 @@ layers: struct {
/// Xwayland override redirect windows are a legacy wart that decide where /// Xwayland override redirect windows are a legacy wart that decide where
/// to place themselves in layout coordinates. Unfortunately this is how /// to place themselves in layout coordinates. Unfortunately this is how
/// X11 decided to make dropdown menus and the like possible. /// 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. /// 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); hidden_tree.node.setEnabled(false);
const outputs = try interactive_content.createSceneTree(); 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); _ = try wlr.XdgOutputManagerV1.create(server.wl_server, output_layout);
@ -143,7 +143,7 @@ pub fn init(root: *Root) !void {
.drag_icons = drag_icons, .drag_icons = drag_icons,
.layers = .{ .layers = .{
.outputs = outputs, .outputs = outputs,
.xwayland_override_redirect = xwayland_override_redirect, .override_redirect = override_redirect,
}, },
.hidden = .{ .hidden = .{
.tree = hidden_tree, .tree = hidden_tree,

View File

@ -31,7 +31,7 @@ pub const Data = union(enum) {
view: *View, view: *View,
lock_surface: *LockSurface, lock_surface: *LockSurface,
layer_surface: *LayerSurface, 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, node: *wlr.SceneNode,

View File

@ -49,7 +49,7 @@ const log = std.log.scoped(.seat);
pub const FocusTarget = union(enum) { pub const FocusTarget = union(enum) {
view: *View, view: *View,
xwayland_override_redirect: if (build_options.xwayland) *XwaylandOverrideRedirect else noreturn, override_redirect: if (build_options.xwayland) *XwaylandOverrideRedirect else noreturn,
layer: *LayerSurface, layer: *LayerSurface,
lock_surface: *LockSurface, lock_surface: *LockSurface,
none: void, none: void,
@ -57,7 +57,7 @@ pub const FocusTarget = union(enum) {
pub fn surface(target: FocusTarget) ?*wlr.Surface { pub fn surface(target: FocusTarget) ?*wlr.Surface {
return switch (target) { return switch (target) {
.view => |view| view.rootSurface(), .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, .layer => |layer| layer.wlr_layer_surface.surface,
.lock_surface => |lock_surface| lock_surface.wlr_lock_surface.surface, .lock_surface => |lock_surface| lock_surface.wlr_lock_surface.surface,
.none => null, .none => null,
@ -238,7 +238,7 @@ pub fn setFocusRaw(seat: *Seat, new_focus: FocusTarget) void {
.layer => |layer_surface| { .layer => |layer_surface| {
layer_surface.destroyPopups(); layer_surface.destroyPopups();
}, },
.xwayland_override_redirect, .lock_surface, .none => {}, .override_redirect, .lock_surface, .none => {},
} }
// Set the new focus // Set the new focus
@ -254,7 +254,7 @@ pub fn setFocusRaw(seat: *Seat, new_focus: FocusTarget) void {
assert(seat.focused_output == target_layer.output); assert(seat.focused_output == target_layer.output);
}, },
.lock_surface => assert(server.lock_manager.state != .unlocked), .lock_surface => assert(server.lock_manager.state != .unlocked),
.xwayland_override_redirect, .none => {}, .override_redirect, .none => {},
} }
seat.focused = new_focus; seat.focused = new_focus;

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 XwaylandOverrideRedirect = @This();
const std = @import("std"); const std = @import("std");
const assert = std.debug.assert; 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), set_geometry: wl.Listener(void) = wl.Listener(void).init(handleSetGeometry),
pub fn create(xwayland_surface: *wlr.XwaylandSurface) error{OutOfMemory}!void { pub fn create(xwayland_surface: *wlr.XwaylandSurface) error{OutOfMemory}!void {
const self = try util.gpa.create(Self); const override_redirect = try util.gpa.create(XwaylandOverrideRedirect);
errdefer util.gpa.destroy(self); 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.request_configure.add(&override_redirect.request_configure);
xwayland_surface.events.destroy.add(&self.destroy); xwayland_surface.events.destroy.add(&override_redirect.destroy);
xwayland_surface.events.set_override_redirect.add(&self.set_override_redirect); xwayland_surface.events.set_override_redirect.add(&override_redirect.set_override_redirect);
xwayland_surface.events.associate.add(&self.associate); xwayland_surface.events.associate.add(&override_redirect.associate);
xwayland_surface.events.dissociate.add(&self.dissociate); xwayland_surface.events.dissociate.add(&override_redirect.dissociate);
if (xwayland_surface.surface) |surface| { if (xwayland_surface.surface) |surface| {
handleAssociate(&self.associate); handleAssociate(&override_redirect.associate);
if (surface.mapped) { if (surface.mapped) {
handleMap(&self.map); handleMap(&override_redirect.map);
} }
} }
} }
@ -78,59 +78,65 @@ fn handleRequestConfigure(
} }
fn handleDestroy(listener: *wl.Listener(void)) void { 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(); override_redirect.request_configure.link.remove();
self.destroy.link.remove(); override_redirect.destroy.link.remove();
self.associate.link.remove(); override_redirect.associate.link.remove();
self.dissociate.link.remove(); override_redirect.dissociate.link.remove();
self.set_override_redirect.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 { 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); override_redirect.xwayland_surface.surface.?.events.map.add(&override_redirect.map);
self.xwayland_surface.surface.?.events.unmap.add(&self.unmap); override_redirect.xwayland_surface.surface.?.events.unmap.add(&override_redirect.unmap);
} }
fn handleDissociate(listener: *wl.Listener(void)) void { fn handleDissociate(listener: *wl.Listener(void)) void {
const self = @fieldParentPtr(Self, "dissociate", listener); const override_redirect = @fieldParentPtr(XwaylandOverrideRedirect, "dissociate", listener);
self.map.link.remove(); override_redirect.map.link.remove();
self.unmap.link.remove(); override_redirect.unmap.link.remove();
} }
pub fn handleMap(listener: *wl.Listener(void)) void { 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", .{}); 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 { fn mapImpl(override_redirect: *XwaylandOverrideRedirect) error{OutOfMemory}!void {
const surface = self.xwayland_surface.surface.?; const surface = override_redirect.xwayland_surface.surface.?;
self.surface_tree = try server.root.layers.xwayland_override_redirect.createSceneSubsurfaceTree(surface); override_redirect.surface_tree =
try SceneNodeData.attach(&self.surface_tree.?.node, .{ .xwayland_override_redirect = self }); 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 (server.lock_manager.state != .unlocked) return;
if (self.xwayland_surface.overrideRedirectWantsFocus() and if (override_redirect.xwayland_surface.overrideRedirectWantsFocus() and
self.xwayland_surface.icccmInputModel() != .none) override_redirect.xwayland_surface.icccmInputModel() != .none)
{ {
const seat = server.input_manager.defaultSeat(); const seat = server.input_manager.defaultSeat();
// Keep the parent top-level Xwayland view of any override redirect surface // 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. // their parent window.
if (seat.focused == .view and if (seat.focused == .view and
seat.focused.view.impl == .xwayland_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 { } else {
seat.setFocusRaw(.{ .xwayland_override_redirect = self }); seat.setFocusRaw(.{ .override_redirect = override_redirect });
} }
} }
} }
fn handleUnmap(listener: *wl.Listener(void)) void { 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; override_redirect.xwayland_surface.surface.?.data = 0;
self.surface_tree.?.node.destroy(); override_redirect.surface_tree.?.node.destroy();
self.surface_tree = null; override_redirect.surface_tree = null;
// If the unmapped surface is currently focused, pass keyboard focus // If the unmapped surface is currently focused, pass keyboard focus
// to the most appropriate surface. // 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) { while (seat_it) |seat_node| : (seat_it = seat_node.next) {
const seat = &seat_node.data; const seat = &seat_node.data;
if (seat.focused == .view and seat.focused.view.impl == .xwayland_view and 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.focused.view.impl.xwayland_view.xwayland_surface.pid == override_redirect.xwayland_surface.pid and
seat.wlr_seat.keyboard_state.focused_surface == self.xwayland_surface.surface) seat.wlr_seat.keyboard_state.focused_surface == override_redirect.xwayland_surface.surface)
{ {
seat.keyboardEnterOrLeave(seat.focused.view.rootSurface()); seat.keyboardEnterOrLeave(seat.focused.view.rootSurface());
} }
@ -174,14 +180,17 @@ fn handleUnmap(listener: *wl.Listener(void)) void {
} }
fn handleSetGeometry(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 { fn handleSetOverrideRedirect(listener: *wl.Listener(void)) void {
const self = @fieldParentPtr(Self, "set_override_redirect", listener); const override_redirect = @fieldParentPtr(XwaylandOverrideRedirect, "set_override_redirect", listener);
const xwayland_surface = self.xwayland_surface; const xwayland_surface = override_redirect.xwayland_surface;
log.debug("xwayland surface unset override redirect", .{}); log.debug("xwayland surface unset override redirect", .{});
@ -189,11 +198,11 @@ fn handleSetOverrideRedirect(listener: *wl.Listener(void)) void {
if (xwayland_surface.surface) |surface| { if (xwayland_surface.surface) |surface| {
if (surface.mapped) { 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 { XwaylandView.create(xwayland_surface) catch {
log.err("out of memory", .{}); log.err("out of memory", .{});