git.lucas.co / cce-compositor
Wayland compositor (wlroots)
git clone https://git.lucas.co/cce-compositor.git

commitc31686e3a159de780eebf39c9d7f5c1b7970e147
parent70734bdeb0
authorIsaac Freund <[email protected]>
date2020-12-05 01:10
screencopy: add workaround for wlroots bug

Currently screencopy's copy_with_damage request is broken for
compositors not submitting damage. As a workaround simply damage
the whole output each frame.

 build.zig        |  1 +
 river/render.zig | 13 +++++++++++++
 2 files changed, 14 insertions(+)

diff --git a/build.zig b/build.zig
index 1baf9a9..5105227 100644
--- a/build.zig
+++ b/build.zig
@@ -124,6 +124,7 @@ fn addServerDeps(exe: *std.build.LibExeObjStep) void {
     exe.linkSystemLibrary("wayland-server");
     exe.linkSystemLibrary("wlroots");
     exe.linkSystemLibrary("xkbcommon");
+    exe.linkSystemLibrary("pixman-1");
 }
 
 fn addProtocolDeps(exe: *std.build.LibExeObjStep, protocol_step: *std.build.Step) void {
diff --git a/river/render.zig b/river/render.zig
index 22a58c1..0326580 100644
--- a/river/render.zig
+++ b/river/render.zig
@@ -124,6 +124,19 @@ pub fn renderOutput(output: *Output) void {
     // Conclude rendering and swap the buffers, showing the final frame
     // on-screen.
     c.wlr_renderer_end(wlr_renderer);
+
+    // TODO(wlroots): remove this with the next release. It is here due to
+    // a wlroots bug in the screencopy damage implementation
+    {
+        var w: c_int = undefined;
+        var h: c_int = undefined;
+        c.wlr_output_transformed_resolution(output.wlr_output, &w, &h);
+        var damage: c.pixman_region32_t = undefined;
+        c.pixman_region32_init(&damage);
+        _ = c.pixman_region32_union_rect(&damage, &damage, 0, 0, @intCast(c_uint, w), @intCast(c_uint, h));
+        c.wlr_output_set_damage(output.wlr_output, &damage);
+    }
+
     // TODO: handle failure
     if (!c.wlr_output_commit(output.wlr_output)) {
         log.err(.render, "wlr_output_commit failed for {}", .{output.wlr_output.name});