Xwayland: handle override redirect state changes

This commit is contained in:
Isaac Freund
2022-05-29 15:16:48 +02:00
parent 8a8dd9ff65
commit 6ef97eea24
4 changed files with 84 additions and 13 deletions

View File

@ -17,16 +17,22 @@
const Self = @This();
const std = @import("std");
const assert = std.debug.assert;
const math = std.math;
const wlr = @import("wlroots");
const wl = @import("wayland").server.wl;
const server = &@import("main.zig").server;
const util = @import("util.zig");
const Box = @import("Box.zig");
const View = @import("View.zig");
const ViewStack = @import("view_stack.zig").ViewStack;
const XdgPopup = @import("XdgPopup.zig");
const XwaylandUnmanaged = @import("XwaylandUnmanaged.zig");
const log = std.log.scoped(.xwayland);
/// The view this xwayland view implements
view: *View,
@ -45,6 +51,8 @@ map: wl.Listener(*wlr.XwaylandSurface) = wl.Listener(*wlr.XwaylandSurface).init(
unmap: wl.Listener(*wlr.XwaylandSurface) = wl.Listener(*wlr.XwaylandSurface).init(handleUnmap),
request_configure: wl.Listener(*wlr.XwaylandSurface.event.Configure) =
wl.Listener(*wlr.XwaylandSurface.event.Configure).init(handleRequestConfigure),
set_override_redirect: wl.Listener(*wlr.XwaylandSurface) =
wl.Listener(*wlr.XwaylandSurface).init(handleSetOverrideRedirect),
// Listeners that are only active while the view is mapped
commit: wl.Listener(*wlr.Surface) = wl.Listener(*wlr.Surface).init(handleCommit),
@ -176,7 +184,7 @@ fn handleDestroy(listener: *wl.Listener(*wlr.XwaylandSurface), _: *wlr.XwaylandS
}
/// Called when the xwayland surface is mapped, or ready to display on-screen.
fn handleMap(listener: *wl.Listener(*wlr.XwaylandSurface), xwayland_surface: *wlr.XwaylandSurface) void {
pub fn handleMap(listener: *wl.Listener(*wlr.XwaylandSurface), xwayland_surface: *wlr.XwaylandSurface) void {
const self = @fieldParentPtr(Self, "map", listener);
const view = self.view;
@ -223,7 +231,7 @@ fn handleMap(listener: *wl.Listener(*wlr.XwaylandSurface), xwayland_surface: *wl
}
view.map() catch {
std.log.err("out of memory", .{});
log.err("out of memory", .{});
surface.resource.getClient().postNoMemory();
};
}
@ -262,6 +270,32 @@ fn handleRequestConfigure(
self.configure();
}
fn handleSetOverrideRedirect(
listener: *wl.Listener(*wlr.XwaylandSurface),
xwayland_surface: *wlr.XwaylandSurface,
) void {
const self = @fieldParentPtr(Self, "set_override_redirect", listener);
log.debug("xwayland surface set override redirect, switching to unmanaged", .{});
assert(xwayland_surface.override_redirect);
if (xwayland_surface.mapped) handleUnmap(&self.unmap, xwayland_surface);
handleDestroy(&self.destroy, xwayland_surface);
// The unmanged surface will add itself to the list of unmanaged views
// in Root when it is mapped.
const node = util.gpa.create(std.TailQueue(XwaylandUnmanaged).Node) catch {
log.err("out of memory", .{});
return;
};
node.data.init(xwayland_surface);
if (xwayland_surface.mapped) {
XwaylandUnmanaged.handleMap(&node.data.map, xwayland_surface);
}
}
fn handleCommit(listener: *wl.Listener(*wlr.Surface), surface: *wlr.Surface) void {
const self = @fieldParentPtr(Self, "commit", listener);