diff --git a/src/Backends/WaylandBackend.cpp b/src/Backends/WaylandBackend.cpp index 40164ba..1b85e63 100644 --- a/src/Backends/WaylandBackend.cpp +++ b/src/Backends/WaylandBackend.cpp @@ -1698,6 +1698,46 @@ namespace gamescope } } + static bool NestedRefreshFollowsHost() + { + static const bool s_bFollow = [] + { + const char *pszFollow = getenv( "GAMESCOPE_NESTED_REFRESH_FOLLOWS_HOST" ); + return pszFollow && atoi( pszFollow ) != 0; + }(); + return s_bFollow; + } + + static bool HostRefreshChanged( int32_t nRefreshmHz, uint64_t ulPresentedNs ) + { + static int32_t s_nPendingmHz = 0; + static uint64_t s_ulPendingSinceNs = 0; + if ( !nRefreshmHz || nRefreshmHz == g_nOutputRefresh ) + { + s_nPendingmHz = 0; + return false; + } + if ( !NestedRefreshFollowsHost() ) + return true; + if ( nRefreshmHz != s_nPendingmHz ) + { + s_nPendingmHz = nRefreshmHz; + s_ulPendingSinceNs = ulPresentedNs; + } + if ( ulPresentedNs - s_ulPendingSinceNs >= 300'000'000ul ) + return true; + force_repaint(); + return false; + } + + static void FollowHostRefresh( int32_t nRefreshmHz ) + { + if ( !NestedRefreshFollowsHost() || !g_nNestedRefresh || g_nNestedRefresh == nRefreshmHz ) + return; + xdg_log.infof( "Nested refresh follows the host: %.3fhz", ConvertmHzToHz( (float) nRefreshmHz ) ); + g_nNestedRefresh = nRefreshmHz; + } + void CWaylandPlane::UpdateVRRRefreshRate() { if ( m_pParent ) @@ -1724,6 +1764,7 @@ namespace gamescope // TODO(strategy): We should pick the largest refresh rate. xdg_log.infof( "Changed refresh to: %.3fhz", ConvertmHzToHz( (float) nLargestRefreshRateMhz ) ); g_nOutputRefresh = nLargestRefreshRateMhz; + FollowHostRefresh( nLargestRefreshRateMhz ); } } @@ -1794,10 +1835,11 @@ namespace gamescope if ( uRefreshCycle ) { int32_t nRefresh = RefreshCycleTomHz( uRefreshCycle ); - if ( nRefresh && nRefresh != g_nOutputRefresh ) + if ( HostRefreshChanged( nRefresh, ulTime ) ) { xdg_log.infof( "Changed refresh to: %.3fhz", ConvertmHzToHz( (float) nRefresh ) ); g_nOutputRefresh = nRefresh; + FollowHostRefresh( nRefresh ); } m_pConnector->SetHostCompositorIsCurrentlyVRR( false ); @@ -2636,6 +2678,8 @@ namespace gamescope } void CWaylandBackend::Wayland_Output_Mode( wl_output *pOutput, uint32_t uFlags, int32_t nWidth, int32_t nHeight, int32_t nRefresh ) { + if ( NestedRefreshFollowsHost() && m_pOutputs[ pOutput ].nRefresh != nRefresh ) + force_repaint(); m_pOutputs[ pOutput ].nRefresh = nRefresh; } void CWaylandBackend::Wayland_Output_Done( wl_output *pOutput ) diff --git a/src/steamcompmgr.cpp b/src/steamcompmgr.cpp index 6c9299d..5fb9086 100644 --- a/src/steamcompmgr.cpp +++ b/src/steamcompmgr.cpp @@ -9254,6 +9254,14 @@ void update_vrr_atoms(xwayland_ctx_t *root_ctx, bool force, bool* needs_flush = g_nCurrentRefreshRate_CachedValue = g_nOutputRefresh; if (needs_flush) *needs_flush = true; + + if ( !force ) + { + wlserver_lock(); + for ( const auto &control : wlserver.gamescope_controls ) + wlserver_send_gamescope_control( control ); + wlserver_unlock(); + } } // Don't update this in-sync with DRM vrr usage.