From 1dc1ac02bc300313399a9f9c551ace68b23bbbc1 Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Tue, 5 Dec 2023 00:27:36 +0100 Subject: Output: fix regression of initial mode logic This logic that looked pointless to me while doing the wlroots 0.17 upgrade is in fact important as tiosgz helpfully pointed out. It was added back in bc610c8b to address an issue. Hopefully the new comments stop me from trying to break it again :) --- river/Output.zig | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/river/Output.zig b/river/Output.zig index 35b98ea..b996da6 100644 --- a/river/Output.zig +++ b/river/Output.zig @@ -194,19 +194,29 @@ pub fn create(wlr_output: *wlr.Output) !void { if (!wlr_output.initRender(server.allocator, server.renderer)) return error.InitRenderFailed; - var state = wlr.Output.State.init(); - defer state.finish(); - - state.setEnabled(true); - + // If the list of modes for the output is empty or if no mode in the list of modes works, + // we can't enable the output automatically. + // It will stay disabled unless the user configures a custom mode which works. if (wlr_output.preferredMode()) |preferred_mode| { + var state = wlr.Output.State.init(); + defer state.finish(); + state.setMode(preferred_mode); + state.setEnabled(true); + + if (!wlr_output.commitState(&state)) { + // It is important to try other modes if the preferred mode fails + // which is reported to be helpful in practice with e.g. multiple + // high resolution monitors connected through a usb dock. + var it = wlr_output.modes.iterator(.forward); + while (it.next()) |mode| { + if (mode == preferred_mode) continue; + state.setMode(mode); + if (wlr_output.commitState(&state)) break; + } + } } - // Ignore failure here and create the Output anyways. - // It will stay disabled unless the user configures a custom mode which may work. - _ = wlr_output.commitState(&state); - var width: c_int = undefined; var height: c_int = undefined; wlr_output.effectiveResolution(&width, &height); @@ -283,7 +293,7 @@ pub fn create(wlr_output: *wlr.Output) !void { output.active_link.init(); server.root.all_outputs.append(output); - output.handleEnable(); + output.handleEnableDisable(); } pub fn layerSurfaceTree(self: Self, layer: zwlr.LayerShellV1.Layer) *wlr.SceneTree { @@ -390,7 +400,7 @@ fn handleRequestState(listener: *wl.Listener(*wlr.Output.event.RequestState), ev } if (event.state.committed.enabled) { - output.handleEnable(); + output.handleEnableDisable(); } if (event.state.committed.mode) { @@ -401,7 +411,7 @@ fn handleRequestState(listener: *wl.Listener(*wlr.Output.event.RequestState), ev } } -fn handleEnable(output: *Self) void { +fn handleEnableDisable(output: *Self) void { // We can't assert the current state of normal_content/locked_content // here as this output may be newly created. if (output.wlr_output.enabled) { -- cgit v1.2.3