From 51df6231f3f81d98f7a2a5888ea7b8aece01fbb5 Mon Sep 17 00:00:00 2001 From: Shinyzenith Date: Tue, 1 Aug 2023 15:18:11 +0530 Subject: [PATCH] [scenefx] rounded corners and opacity Signed-off-by: Shinyzenith --- .gitmodules | 7 +++---- build.zig | 1 + deps/zig-wlroots | 2 +- next/Config.zig | 4 ++++ next/desktop/Output.zig | 33 +++++++++++++++++++++++++++++++++ 5 files changed, 42 insertions(+), 5 deletions(-) diff --git a/.gitmodules b/.gitmodules index 68ef718..17f032f 100644 --- a/.gitmodules +++ b/.gitmodules @@ -14,10 +14,6 @@ path = deps/zig-clap url = https://github.com/Hejsil/zig-clap ignore = dirty -[submodule "deps/zig-wlroots"] - path = deps/zig-wlroots - url = https://github.com/swaywm/zig-wlroots.git - ignore = dirty [submodule "deps/zig-pixman"] path = deps/zig-pixman url = https://github.com/ifreund/zig-pixman @@ -25,3 +21,6 @@ path = deps/scenefx url = https://github.com/wlrfx/scenefx ignore = dirty +[submodule "deps/zig-wlroots"] + path = deps/zig-wlroots + url = https://github.com/shinyzenith/zig-wlr diff --git a/build.zig b/build.zig index a36aedd..0c7b955 100644 --- a/build.zig +++ b/build.zig @@ -100,6 +100,7 @@ pub fn build(builder: *std.build.Builder) !void { exe.linkSystemLibrary("wlroots"); exe.linkSystemLibrary("xkbcommon"); exe.addObjectFile(std.fmt.comptimePrint("{s}/build/libscenefx.so.{d}", .{ scenefx_path, new_so_version })); + exe.addIncludePath(std.fmt.comptimePrint("{s}/include/wlr", .{scenefx_path})); } exe.install(); diff --git a/deps/zig-wlroots b/deps/zig-wlroots index 18ccc0a..16a01ff 160000 --- a/deps/zig-wlroots +++ b/deps/zig-wlroots @@ -1 +1 @@ -Subproject commit 18ccc0aef22fa4def45dd43bf9e9fc3728bbece4 +Subproject commit 16a01ff2c24f4cab2c21ef85ddd37735ed993c4e diff --git a/next/Config.zig b/next/Config.zig index fcfae00..e480a3c 100644 --- a/next/Config.zig +++ b/next/Config.zig @@ -33,6 +33,10 @@ repeat_delay: i32 = 300, border_width: u8 = 2, +//TODO: make these configurable +toplevel_corner_radius: c_int = 20, +toplevel_opacity: f32 = 1, // Ranges from 0 to 1 + pub fn init() Self { log.debug("Initialized compositor config", .{}); const self = .{}; diff --git a/next/desktop/Output.zig b/next/desktop/Output.zig index 9dd926e..7820b4e 100644 --- a/next/desktop/Output.zig +++ b/next/desktop/Output.zig @@ -101,6 +101,36 @@ pub fn init(self: *Self, wlr_output: *wlr.Output) !void { } } +fn configure_node_decoration(self: *Self, node: *wlr.SceneNode) void { + if (!node.enabled) { + return; + } + + if (node.type == .buffer) { + const scene_buffer = wlr.SceneBuffer.fromNode(node); + const scene_surface = wlr.SceneSurface.fromBuffer(scene_buffer) orelse return; + + var xdg_surface: *wlr.XdgSurface = undefined; + if (wlr.Surface.isXdgSurface(scene_surface.surface)) { + xdg_surface = wlr.XdgSurface.fromWlrSurface(scene_surface.surface) orelse return; + } + + if (xdg_surface.role == .toplevel) { + scene_buffer.setOpacity(self.server.config.toplevel_opacity); + + if (!wlr.Surface.isSubsurface(xdg_surface.surface)) { + scene_buffer.setCornerRadius(self.server.config.toplevel_corner_radius); + } + } + } else if (node.type == .tree) { + const tree = @fieldParentPtr(wlr.SceneTree, "node", node); + var it = tree.children.safeIterator(.forward); + while (it.next()) |scene_node| { + configure_node_decoration(self, scene_node); + } + } +} + pub fn init_wallpaper_rendering(self: *Self) !void { // We do some cleanup first. const wallpaper_path = allocator.dupe(u8, self.wallpaper_path.?) catch return error.OOM; @@ -164,6 +194,9 @@ fn handleFrame(listener: *wl.Listener(*wlr.Output), _: *wlr.Output) void { // Ge // Get the scene output with respect to the wlr.Output object that's being passed. const scene_output = self.server.wlr_scene.getSceneOutput(self.wlr_output).?; + // Pass decoration data to the scene nodes. + self.configure_node_decoration(&scene_output.scene.tree.node); + // Commit the output to the scene. _ = scene_output.commit();