From bc610c8b829904335298bde38dc9d8bc44a67aec Mon Sep 17 00:00:00 2001 From: tiosgz Date: Sun, 10 Jul 2022 08:57:53 +0000 Subject: [PATCH] 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.* = .{