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

commit4cd3b978403a52107a3d77e63db3667f3e67a5eb
parent10a107fc34
authortiosgz <[email protected]>
date2022-07-10 08:57
Output: retry other modes if preferred fails

In cases like multiple hi-res monitors connected through a USB dock, the
preferred mode can fail to work. Such an output was then ignored by river,
which made it impossible to even set another mode manually.

Sway has been reported to solve this issue, so let's employ their solution
and fall back to another mode if possible.

 river/Output.zig | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/river/Output.zig b/river/Output.zig
index 0cc86c2..ac69dd7 100644
--- a/river/Output.zig
+++ b/river/Output.zig
@@ -105,10 +105,21 @@ pub fn init(self: *Self, wlr_output: *wlr.Output) !void {
     // refresh rate), and each monitor supports only a specific set of modes. We
     // just pick the monitor's preferred mode, a more sophisticated compositor
     // would let the user configure it.
-    if (wlr_output.preferredMode()) |mode| {
-        wlr_output.setMode(mode);
+    if (wlr_output.preferredMode()) |preferred_mode| {
+        wlr_output.setMode(preferred_mode);
         wlr_output.enable(true);
-        try wlr_output.commit();
+        wlr_output.commit() catch |err| {
+            var it = wlr_output.modes.iterator(.forward);
+            while (it.next()) |mode| {
+                if (mode == preferred_mode) continue;
+                wlr_output.setMode(mode);
+                wlr_output.commit() catch continue;
+                // This mode works, use it
+                break;
+            } else {
+                return err;
+            }
+        };
     }
 
     self.* = .{