2023-01-29 03:03:41 -08:00
|
|
|
// This file is part of river, a dynamic tiling wayland compositor.
|
|
|
|
//
|
|
|
|
// Copyright 2023 The River Developers
|
|
|
|
//
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, version 3.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
const SceneNodeData = @This();
|
|
|
|
|
|
|
|
const build_options = @import("build_options");
|
|
|
|
const wlr = @import("wlroots");
|
|
|
|
const wl = @import("wayland").server.wl;
|
|
|
|
|
|
|
|
const util = @import("util.zig");
|
|
|
|
|
2023-02-11 03:23:07 -08:00
|
|
|
const LayerSurface = @import("LayerSurface.zig");
|
2023-01-31 06:47:19 -08:00
|
|
|
const LockSurface = @import("LockSurface.zig");
|
2023-01-29 03:03:41 -08:00
|
|
|
const View = @import("View.zig");
|
2023-02-20 09:01:24 -08:00
|
|
|
const XwaylandOverrideRedirect = @import("XwaylandOverrideRedirect.zig");
|
2023-01-29 03:03:41 -08:00
|
|
|
|
|
|
|
const Data = union(enum) {
|
|
|
|
view: *View,
|
2023-01-31 06:47:19 -08:00
|
|
|
lock_surface: *LockSurface,
|
2023-02-11 03:23:07 -08:00
|
|
|
layer_surface: *LayerSurface,
|
2023-02-20 09:01:24 -08:00
|
|
|
xwayland_override_redirect: if (build_options.xwayland) *XwaylandOverrideRedirect else noreturn,
|
2023-01-29 03:03:41 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
node: *wlr.SceneNode,
|
|
|
|
data: Data,
|
|
|
|
destroy: wl.Listener(void) = wl.Listener(void).init(handleDestroy),
|
|
|
|
|
|
|
|
pub fn attach(node: *wlr.SceneNode, data: Data) error{OutOfMemory}!void {
|
|
|
|
const scene_node_data = try util.gpa.create(SceneNodeData);
|
|
|
|
|
|
|
|
scene_node_data.* = .{
|
|
|
|
.node = node,
|
|
|
|
.data = data,
|
|
|
|
};
|
|
|
|
node.data = @ptrToInt(scene_node_data);
|
|
|
|
|
|
|
|
node.events.destroy.add(&scene_node_data.destroy);
|
|
|
|
}
|
|
|
|
|
2023-02-24 10:28:37 -08:00
|
|
|
pub fn get(node: *wlr.SceneNode) ?*SceneNodeData {
|
|
|
|
var it: ?*wlr.SceneNode = node;
|
|
|
|
while (it) |n| : (it = n.parent) {
|
|
|
|
if (@intToPtr(?*SceneNodeData, n.data)) |scene_node_data| {
|
|
|
|
return scene_node_data;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2023-01-29 03:03:41 -08:00
|
|
|
fn handleDestroy(listener: *wl.Listener(void)) void {
|
|
|
|
const scene_node_data = @fieldParentPtr(SceneNodeData, "destroy", listener);
|
|
|
|
|
|
|
|
scene_node_data.destroy.link.remove();
|
|
|
|
scene_node_data.node.data = 0;
|
|
|
|
|
|
|
|
util.gpa.destroy(scene_node_data);
|
|
|
|
}
|