From 272d01f6b142afe76155cda923753db7fd8d8342 Mon Sep 17 00:00:00 2001 From: Utkarsh Dalal Date: Sun, 15 Nov 2026 18:54:22 +0530 Subject: [PATCH] android: GAMENATIVE_ROOT_DESKTOP switches A26, A33 and A48 off on wine's root desktop The three patches exist only for wine's virtual desktop, where the game's window is nested in one desktop window. With GAMENATIVE_ROOT_DESKTOP=1 the guest runs on wine's root desktop instead: A26 keeps upstream's app id, A33 never blanks and A48 never sends its bring-to-front request. Unset or any other value keeps today's behavior, so one binary serves both launch modes. --- android/README.md | 17 +++++++++ .../gamescope/0026-A26-uniform-app-id.patch | 30 +++++++++++++--- ...3-A33-blank-while-game-window-absent.patch | 36 ++++++++++++------- ...A48-bring-nested-app-window-to-front.patch | 14 ++++++-- 4 files changed, 77 insertions(+), 20 deletions(-) diff --git a/android/README.md b/android/README.md index 0ee5ea048..d21bc2da1 100644 --- a/android/README.md +++ b/android/README.md @@ -55,6 +55,23 @@ fixed member mtimes, `--sort=name` order, `uid/gid 0` — so identical inputs rebuild to byte-identical `.tzst` bytes. The dated filename is a name only; it does not enter the archive. +## Wine's root desktop: `GAMENATIVE_ROOT_DESKTOP` + +The app launches a game either inside Wine's virtual desktop +(`explorer /desktop=shell,WxH`, one top-level X window with the game nested in +it) or on Wine's root desktop (`explorer /desktop=root`, each game window a +managed top-level X window, as upstream gamescope expects). Three patches exist +only for the virtual desktop. The app sets `GAMENATIVE_ROOT_DESKTOP` in +gamescope's environment, and gamescope reads it once at startup: + +| value | effect | +|---|---| +| unset, `0` or anything else | virtual desktop: A26, A33 and A48 act as described in their headers | +| `1` | root desktop: A26 leaves upstream's app id (the X window id), A33 never blanks, A48 never sends its bring-to-front request | + +Under `1` the uniform app id is gone, so a `gamescope_control` performance-stats +request for that id matches no window. + ## Related projects This tree is only the display server. The pieces it stages but does not build: diff --git a/android/patches/gamescope/0026-A26-uniform-app-id.patch b/android/patches/gamescope/0026-A26-uniform-app-id.patch index d7c3ed826..19aad0553 100644 --- a/android/patches/gamescope/0026-A26-uniform-app-id.patch +++ b/android/patches/gamescope/0026-A26-uniform-app-id.patch @@ -1,6 +1,15 @@ +A26 — one uniform app id for every window + +GAMENATIVE_ROOT_DESKTOP=1 (wine's root desktop, set by the app) turns the +override off: both sites keep upstream's appID = X window id. The helper +that reads the variable lives here so that A33 and A48 can use it too. +Unset or any other value keeps the uniform id. + +diff --git a/src/steamcompmgr.cpp b/src/steamcompmgr.cpp +index 8eb47a4..cd305bb 100644 --- a/src/steamcompmgr.cpp +++ b/src/steamcompmgr.cpp -@@ -1547,6 +1547,18 @@ +@@ -1547,6 +1547,29 @@ bool steamcompmgr_window_should_refresh_switch( steamcompmgr_win_t *w ) #define SCREEN_SCALE_PROP "STEAM_SCREEN_SCALE" #define SCREEN_MAGNIFICATION_PROP "STEAM_SCREEN_MAGNIFICATION" @@ -15,25 +24,36 @@ +// with no cross-process channel and no file I/O. The app side (GameNative +// GameNativeDrm.GAMESCOPE_APP_ID) must use the same value. +static constexpr uint32_t kGameNativeUniformAppId = 1; ++ ++// GameNative: GAMENATIVE_ROOT_DESKTOP=1 says the guest runs on wine's root ++// desktop (explorer /desktop=root): every game window is a managed top-level X ++// window, as upstream expects. The patches written for wine's virtual desktop ++// (this uniform app id, A33's blank, A48's bring-to-front) then stand down. ++// Unset or any other value keeps them active. Read once, at startup. ++static const bool g_bGameNativeRootDesktop = [] ++{ ++ const char *pszRootDesktop = getenv( "GAMENATIVE_ROOT_DESKTOP" ); ++ return pszRootDesktop != nullptr && strcmp( pszRootDesktop, "1" ) == 0; ++}(); + #define TRANSLUCENT 0x00000000 #define OPAQUE 0xffffffff -@@ -5841,7 +5853,7 @@ +@@ -5817,7 +5840,7 @@ map_win(xwayland_ctx_t* ctx, Window id, unsigned long sequence) } else { - w->appID = w->xwayland().id; -+ w->appID = kGameNativeUniformAppId; ++ w->appID = g_bGameNativeRootDesktop ? w->xwayland().id : kGameNativeUniformAppId; } if ( w->isSteamLegacyBigPicture ) -@@ -6072,7 +6084,7 @@ +@@ -6048,7 +6071,7 @@ add_win(xwayland_ctx_t *ctx, Window id, Window prev, unsigned long sequence) } else { - new_win->appID = id; -+ new_win->appID = kGameNativeUniformAppId; ++ new_win->appID = g_bGameNativeRootDesktop ? id : kGameNativeUniformAppId; } if ( new_win->isExternalOverlay ) diff --git a/android/patches/gamescope/0033-A33-blank-while-game-window-absent.patch b/android/patches/gamescope/0033-A33-blank-while-game-window-absent.patch index 9c3adc210..0b4593c33 100644 --- a/android/patches/gamescope/0033-A33-blank-while-game-window-absent.patch +++ b/android/patches/gamescope/0033-A33-blank-while-game-window-absent.patch @@ -42,6 +42,14 @@ desktop does when the game's window goes away, and what a recreate does not do. The blind's one-shot log line states the stamped id and the newest done commit id at every transition, so the panel evidence can be tied to the comparison. +GAMENATIVE_ROOT_DESKTOP=1 (wine's root desktop, read in A26) switches the +blank off: there is no virtual desktop window to hide, so neither the +startup/absence blind nor the reaper-end blank is raised, no per-window +state is stamped and no extra frame is painted at shutdown. The log line +states root_desktop= so a session shows which mode it ran in. The blank +texture's output-size extent (rendervulkan.cpp) is not switched; it is not a +blank by itself. Unset or any other value keeps all of the above. + diff --git a/src/rendervulkan.cpp b/src/rendervulkan.cpp index 54e4efc..f3f914a 100644 --- a/src/rendervulkan.cpp @@ -64,10 +72,10 @@ index 54e4efc..f3f914a 100644 return vulkan_create_flat_texture( width, height, 0, 0, 0, 0 ); } diff --git a/src/steamcompmgr.cpp b/src/steamcompmgr.cpp -index 2dfdd7f..e9ec9a7 100644 +index ee14377..65307ae 100644 --- a/src/steamcompmgr.cpp +++ b/src/steamcompmgr.cpp -@@ -3131,6 +3131,125 @@ gamescope::ConVar cv_paint_external_overlay_plane{ "paint_external_overlay +@@ -3142,6 +3142,125 @@ gamescope::ConVar cv_paint_external_overlay_plane{ "paint_external_overlay gamescope::ConVar cv_paint_cursor_plane{ "paint_cursor_plane", true }; gamescope::ConVar cv_paint_mura_plane{ "paint_mura_plane", true }; @@ -193,7 +201,7 @@ index 2dfdd7f..e9ec9a7 100644 static void paint_all( global_focus_t *pFocus, bool async ) { -@@ -3170,6 +3289,40 @@ paint_all( global_focus_t *pFocus, bool async ) +@@ -3181,6 +3300,42 @@ paint_all( global_focus_t *pFocus, bool async ) // Decide the fit target once so the window planes and the cursor plane agree. fit = override; @@ -201,16 +209,18 @@ index 2dfdd7f..e9ec9a7 100644 + // that is left to composite, so the frame is a black plane in place of + // every window. This round the same blind is raised earlier -- whenever the + // game's window is gone while the session is still alive -- so the desktop -+ // blue is not what the panel is left holding at either transition. -+ bool bSessionBlank = g_bSessionEndBlank || session_game_window_absent( w ); ++ // blue is not what the panel is left holding at either transition. On ++ // wine's root desktop there is no desktop window to hide: never blank. ++ bool bSessionBlank = !g_bGameNativeRootDesktop && ( g_bSessionEndBlank || session_game_window_absent( w ) ); + + // One-shot stated outcome, raised on every change of the blind's state. + static int s_nLastBlankState = -1; + if ( ( bSessionBlank ? 1 : 0 ) != s_nLastBlankState ) + { + s_nLastBlankState = bSessionBlank ? 1 : 0; -+ s_SessionBlankLogScope.infof( "blank=%d reaper=%d window=%s override_bound=%d saw_game_window=%d bound_commit=%lu gap_commit=%lu last_done_commit=%lu", ++ s_SessionBlankLogScope.infof( "blank=%d root_desktop=%d reaper=%d window=%s override_bound=%d saw_game_window=%d bound_commit=%lu gap_commit=%lu last_done_commit=%lu", + s_nLastBlankState, ++ g_bGameNativeRootDesktop ? 1 : 0, + g_bSessionEndBlank ? 1 : 0, + w ? "present" : "none", + ( w && w->type == steamcompmgr_win_type_t::XWAYLAND && w->xwayland().surface.override_surface != nullptr ) ? 1 : 0, @@ -234,7 +244,7 @@ index 2dfdd7f..e9ec9a7 100644 if (++frameCounter == 300) { currentFrameRate = 300 * 1000.0f / (currentTime - lastSampledFrameTime); -@@ -3201,7 +3354,11 @@ paint_all( global_focus_t *pFocus, bool async ) +@@ -3212,7 +3367,11 @@ paint_all( global_focus_t *pFocus, bool async ) // find the video underlay and put it up first in the scenegraph if ( cv_paint_primary_plane ) { @@ -247,18 +257,20 @@ index 2dfdd7f..e9ec9a7 100644 { if ( w->isSteamStreamingClient == true ) { -@@ -9464,6 +9621,10 @@ void LaunchNestedChildren( char **ppPrimaryChildArgv ) +@@ -9475,6 +9634,12 @@ void LaunchNestedChildren( char **ppPrimaryChildArgv ) gamescope::Process::WaitForChild( nPrimaryChildPid ); s_LaunchLogScope.infof( "Primary child shut down!" ); + // The reaper has ended the session: the compositor's only remaining -+ // client is wine's desktop window, so hold the output black. -+ g_bSessionEndBlank = true; ++ // client is wine's desktop window, so hold the output black. On ++ // wine's root desktop there is none, and no blank is raised. ++ if ( !g_bGameNativeRootDesktop ) ++ g_bSessionEndBlank = true; + if ( cv_shutdown_on_primary_child_death ) ShutdownGamescope(); }); -@@ -10057,6 +10218,14 @@ steamcompmgr_main(int argc, char **argv) +@@ -10068,6 +10233,14 @@ steamcompmgr_main(int argc, char **argv) if ( g_bRun == false ) { @@ -274,7 +286,7 @@ index 2dfdd7f..e9ec9a7 100644 } diff --git a/src/steamcompmgr_shared.hpp b/src/steamcompmgr_shared.hpp -index c344d10..c8d8da5 100644 +index c344d10..23bd2d4 100644 --- a/src/steamcompmgr_shared.hpp +++ b/src/steamcompmgr_shared.hpp @@ -161,6 +161,25 @@ struct steamcompmgr_win_t { diff --git a/android/patches/gamescope/0047-A48-bring-nested-app-window-to-front.patch b/android/patches/gamescope/0047-A48-bring-nested-app-window-to-front.patch index 964992a4a..571ac84b0 100644 --- a/android/patches/gamescope/0047-A48-bring-nested-app-window-to-front.patch +++ b/android/patches/gamescope/0047-A48-bring-nested-app-window-to-front.patch @@ -23,8 +23,13 @@ Verified on the Odin 3: sent at map time the game goes live (pad, keyboard, continuous XInput polling); sent after the game has hidden its window it does nothing, so the map event is the only usable trigger. +GAMENATIVE_ROOT_DESKTOP=1 (wine's root desktop, read in A26) switches the +request off: each game window is then a managed top-level window that the +compositor maps and focuses itself, so no nested map sends anything. Unset +or any other value keeps the request. + diff --git a/src/steamcompmgr.cpp b/src/steamcompmgr.cpp -index 5f4f19c..adafff0 100644 +index 65307ae..726f2ef 100644 --- a/src/steamcompmgr.cpp +++ b/src/steamcompmgr.cpp @@ -68,6 +68,7 @@ @@ -35,7 +40,7 @@ index 5f4f19c..adafff0 100644 #include #include #include -@@ -5919,6 +5920,46 @@ handle_desktop_window(steamcompmgr_win_t *w) +@@ -5968,6 +5969,49 @@ handle_desktop_window(steamcompmgr_win_t *w) } } @@ -64,6 +69,9 @@ index 5f4f19c..adafff0 100644 + +static void gn_activate_nested_app_window( xwayland_ctx_t *ctx, Window window ) +{ ++ // Wine's root desktop maps game windows as managed top-level windows. ++ if ( g_bGameNativeRootDesktop ) ++ return; + XClassHint hint = {}; + if ( !XGetClassHint( ctx->dpy, window, &hint ) ) + return; @@ -82,7 +90,7 @@ index 5f4f19c..adafff0 100644 static void map_win(xwayland_ctx_t* ctx, Window id, unsigned long sequence) { -@@ -8788,6 +8829,8 @@ void xwayland_ctx_t::Dispatch() +@@ -8837,6 +8881,8 @@ void xwayland_ctx_t::Dispatch() if (w && w->xwayland().id == ev.xmap.window) map_win(ctx, ev.xmap.window, ev.xmap.serial);