From 418fa2f06ed9f91386c099798222efd280ad8139 Mon Sep 17 00:00:00 2001 From: Zach Denton Date: Tue, 19 May 2026 01:35:17 +0200 Subject: [PATCH] platform/linux/wayland: use the current wl_output mode wl_output.mode is emitted for every advertised mode, not just the active one. The current code overwrites viewport.width and viewport.height on every mode event, which can leave Sunshine latched to a supported mode instead of the current mode. When that happens, wlgrab sees every captured frame as a size mismatch and reinitializes endlessly. Track the compositor's current mode explicitly and only fall back to the first advertised mode until a current one is seen. Signed-off-by: Zach Denton --- src/platform/linux/wayland.cpp | 20 +++++++++++++++++--- src/platform/linux/wayland.h | 1 + 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/platform/linux/wayland.cpp b/src/platform/linux/wayland.cpp index f933606189d..4b64c062dc6 100644 --- a/src/platform/linux/wayland.cpp +++ b/src/platform/linux/wayland.cpp @@ -156,10 +156,24 @@ namespace wl { std::int32_t height, std::int32_t refresh ) { - viewport.width = width; - viewport.height = height; - BOOST_LOG(info) << "[wayland] Resolution: "sv << width << 'x' << height; + + // wl_output.mode is emitted for every advertised mode. Capture sizing must + // follow the compositor's current mode, otherwise we can latch onto a stale + // supported mode and force endless reinit from frame-size mismatches. + if (flags & WL_OUTPUT_MODE_CURRENT) { + viewport.width = width; + viewport.height = height; + has_current_mode = true; + return; + } + + // Keep a conservative fallback for compositors that may omit the current + // bit during early enumeration, but never overwrite a known current mode. + if (!has_current_mode && viewport.width == 0 && viewport.height == 0) { + viewport.width = width; + viewport.height = height; + } } void monitor_t::listen(zxdg_output_manager_v1 *output_manager) { diff --git a/src/platform/linux/wayland.h b/src/platform/linux/wayland.h index 286c247bb52..00966c4d7f0 100644 --- a/src/platform/linux/wayland.h +++ b/src/platform/linux/wayland.h @@ -127,6 +127,7 @@ namespace wl { std::string name; std::string description; platf::touch_port_t viewport; + bool has_current_mode {false}; wl_output_listener wl_listener; zxdg_output_v1_listener xdg_listener; };