aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIsaac Freund <mail@isaacfreund.com>2023-12-05 00:27:36 +0100
committerIsaac Freund <mail@isaacfreund.com>2023-12-05 00:27:36 +0100
commit1dc1ac02bc300313399a9f9c551ace68b23bbbc1 (patch)
treed2561090cf41fc5f1d4487ae6f92f28a302e0f04
parent6bfaf62cef0061782e9a6dc6fb7072226f44be4e (diff)
downloadriver-1dc1ac02bc300313399a9f9c551ace68b23bbbc1.tar.gz
river-1dc1ac02bc300313399a9f9c551ace68b23bbbc1.tar.xz
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 :)
-rw-r--r--river/Output.zig34
1 files 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) {