Skip to content

Commit

Permalink
[scenefx] rounded corners and opacity
Browse files Browse the repository at this point in the history
Signed-off-by: Shinyzenith <[email protected]>
  • Loading branch information
Shinyzenith committed Aug 3, 2023
1 parent 0cc9389 commit 51df623
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 5 deletions.
7 changes: 3 additions & 4 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@
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
[submodule "deps/scenefx"]
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
1 change: 1 addition & 0 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
2 changes: 1 addition & 1 deletion deps/zig-wlroots
4 changes: 4 additions & 0 deletions next/Config.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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 = .{};
Expand Down
33 changes: 33 additions & 0 deletions next/desktop/Output.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();

Expand Down

0 comments on commit 51df623

Please sign in to comment.