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 :)
This commit is contained in:
Isaac Freund 2023-12-05 00:27:36 +01:00
parent 6bfaf62cef
commit 1dc1ac02bc
No known key found for this signature in database
GPG Key ID: 86DED400DDFD7A11

View File

@ -194,18 +194,28 @@ pub fn create(wlr_output: *wlr.Output) !void {
if (!wlr_output.initRender(server.allocator, server.renderer)) return error.InitRenderFailed; if (!wlr_output.initRender(server.allocator, server.renderer)) return error.InitRenderFailed;
var state = wlr.Output.State.init(); // If the list of modes for the output is empty or if no mode in the list of modes works,
defer state.finish(); // we can't enable the output automatically.
// It will stay disabled unless the user configures a custom mode which works.
state.setEnabled(true);
if (wlr_output.preferredMode()) |preferred_mode| { if (wlr_output.preferredMode()) |preferred_mode| {
state.setMode(preferred_mode); var state = wlr.Output.State.init();
} defer state.finish();
// Ignore failure here and create the Output anyways. state.setMode(preferred_mode);
// It will stay disabled unless the user configures a custom mode which may work. state.setEnabled(true);
_ = wlr_output.commitState(&state);
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;
}
}
}
var width: c_int = undefined; var width: c_int = undefined;
var height: c_int = undefined; var height: c_int = undefined;
@ -283,7 +293,7 @@ pub fn create(wlr_output: *wlr.Output) !void {
output.active_link.init(); output.active_link.init();
server.root.all_outputs.append(output); server.root.all_outputs.append(output);
output.handleEnable(); output.handleEnableDisable();
} }
pub fn layerSurfaceTree(self: Self, layer: zwlr.LayerShellV1.Layer) *wlr.SceneTree { 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) { if (event.state.committed.enabled) {
output.handleEnable(); output.handleEnableDisable();
} }
if (event.state.committed.mode) { 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 // We can't assert the current state of normal_content/locked_content
// here as this output may be newly created. // here as this output may be newly created.
if (output.wlr_output.enabled) { if (output.wlr_output.enabled) {