From f45eabe7650d47973197416f4d4f56b0d15e2aa5 Mon Sep 17 00:00:00 2001 From: Attila Fidan Date: Sun, 3 Nov 2024 00:48:36 +0000 Subject: [PATCH] WaylandBackend: Re-map toplevel upon becoming visible When becoming invisible, a NULL buffer is attached to the toplevel's surface which unmaps it. The compositor resets their state and the surface may also be considered unconfigured. Upon becoming visible, the surface must be re-mapped using the same process during initialization (commit without a buffer and wait for configure) before we begin attaching an actual buffer. The default properties should also be recovered. Fixes: https://github.com/ValveSoftware/gamescope/issues/1456 Fixes: https://github.com/ValveSoftware/gamescope/issues/1451 (probably) Fixes: https://github.com/ValveSoftware/gamescope/issues/1488 (probably) Fixes: https://github.com/ValveSoftware/gamescope/issues/1533 --- src/Backends/WaylandBackend.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/Backends/WaylandBackend.cpp b/src/Backends/WaylandBackend.cpp index c53bf14df1..16e7ee1458 100644 --- a/src/Backends/WaylandBackend.cpp +++ b/src/Backends/WaylandBackend.cpp @@ -1925,6 +1925,29 @@ namespace gamescope return; m_bVisible = bVisible; + + // Surface must be re-mapped before using it again, and default + // properties should be recovered as the compositor resets the state + if (m_bVisible) + { + assert( !m_Planes[0].GetCurrentState() ); + wl_surface_commit( m_Planes[0].GetSurface() ); + wl_display_roundtrip( m_pDisplay ); + + libdecor_frame_set_title( m_Planes[0].GetFrame(), "Gamescope" ); + libdecor_frame_set_app_id( m_Planes[0].GetFrame(), "gamescope" ); + + g_nOutputWidth = g_nPreferredOutputWidth; + g_nOutputHeight = g_nPreferredOutputHeight; + if ( g_nOutputHeight == 0 ) + g_nOutputHeight = 720; + if ( g_nOutputWidth == 0 ) + g_nOutputWidth = g_nOutputHeight * 16 / 9; + + m_Planes[0].CommitLibDecor( nullptr ); + wl_display_roundtrip( m_pDisplay ); + } + force_repaint(); } void CWaylandBackend::SetTitle( std::shared_ptr pAppTitle )