Support basic popups

This commit is contained in:
2023-12-31 01:19:20 +01:00
parent 4cf23a5575
commit 50d5b3ef76
2 changed files with 16 additions and 5 deletions
+1 -1
View File
@@ -28,7 +28,7 @@ pub const Client = struct {
.scene_tree = try server.scene.tree.createSceneXdgSurface(xdg_surface),
};
self.scene_tree.node.data = @intFromPtr(self);
xdg_surface.data = @intFromPtr(self);
xdg_surface.data = @intFromPtr(self.scene_tree);
xdg_surface.surface.events.map.add(&self.map_l);
xdg_surface.surface.events.unmap.add(&self.unmap_l);
+15 -4
View File
@@ -88,13 +88,24 @@ pub const Server = struct {
});
}
fn onNewSurface(self: *Server, surface: *wlr.XdgSurface) void {
switch (surface.role) {
.toplevel => Client.create(self, surface) catch {
fn onNewSurface(self: *Server, xdg_surface: *wlr.XdgSurface) void {
switch (xdg_surface.role) {
.toplevel => Client.create(self, xdg_surface) catch {
std.log.err("Couldn't create a client", .{});
},
.popup => {
// TODO: implement popupus
// These asserts are fine since tinywl.zig doesn't support anything else that can
// make xdg popups (e.g. layer shell).
const parent = wlr.XdgSurface.tryFromWlrSurface(xdg_surface.role_data.popup.?.parent.?) orelse return;
const parent_tree = @as(?*wlr.SceneTree, @ptrFromInt(parent.data)) orelse {
// The xdg surface user data could be left null due to allocation failure.
return;
};
const scene_tree = parent_tree.createSceneXdgSurface(xdg_surface) catch {
std.log.err("failed to allocate xdg popup node", .{});
return;
};
xdg_surface.data = @intFromPtr(scene_tree);
},
.none => unreachable,
}