Output: fix initial commit for wayland backend

Also add some more logging
This commit is contained in:
Isaac Freund 2023-12-05 11:02:17 +01:00
parent d207e08dab
commit deb671bec8
No known key found for this signature in database
GPG Key ID: 86DED400DDFD7A11

View File

@ -195,25 +195,44 @@ 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;
// If the list of modes for the output is empty or if no mode in the list of modes works, // If no standard mode for the output works we can't enable the output automatically.
// we can't enable the output automatically.
// It will stay disabled unless the user configures a custom mode which works. // It will stay disabled unless the user configures a custom mode which works.
if (wlr_output.preferredMode()) |preferred_mode| { //
// For the Wayland backend, the list of modes will be empty and it is possible to
// enable the output without setting a mode.
{
var state = wlr.Output.State.init(); var state = wlr.Output.State.init();
defer state.finish(); defer state.finish();
state.setMode(preferred_mode);
state.setEnabled(true); state.setEnabled(true);
if (wlr_output.preferredMode()) |preferred_mode| {
state.setMode(preferred_mode);
}
if (!wlr_output.commitState(&state)) { if (!wlr_output.commitState(&state)) {
log.err("initial output commit with preferred mode failed, trying all modes", .{});
// It is important to try other modes if the preferred mode fails // It is important to try other modes if the preferred mode fails
// which is reported to be helpful in practice with e.g. multiple // which is reported to be helpful in practice with e.g. multiple
// high resolution monitors connected through a usb dock. // high resolution monitors connected through a usb dock.
var it = wlr_output.modes.iterator(.forward); var it = wlr_output.modes.iterator(.forward);
while (it.next()) |mode| { while (it.next()) |mode| {
if (mode == preferred_mode) continue;
state.setMode(mode); state.setMode(mode);
if (wlr_output.commitState(&state)) break; if (wlr_output.commitState(&state)) {
log.info("initial output commit succeeded with mode {}x{}@{}mHz", .{
mode.width,
mode.height,
mode.refresh,
});
break;
} else {
log.err("initial output commit failed with mode {}x{}@{}mHz", .{
mode.width,
mode.height,
mode.refresh,
});
}
} }
} }
} }