From 602bdfaee55bfa6968b9520f81f66c3331a6b54a Mon Sep 17 00:00:00 2001
From: Simon McVittie <smcv@collabora.com>
Date: Mon, 7 Sep 2020 15:37:02 +0100
Subject: [PATCH] wrap: Parse app ID from $STEAM_COMPAT_APP_ID

Recent versions of Steam set this when running setup commands in the
context of a particular app, so that the setup commands can find their
home directory if unsharing $HOME.

Signed-off-by: Simon McVittie <smcv@collabora.com>
---
 man/wrap.1.md |  1 -
 src/wrap.c    | 12 ++++++++++--
 2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/man/wrap.1.md b/man/wrap.1.md
index 29ffe7624..bb93c14e6 100644
--- a/man/wrap.1.md
+++ b/man/wrap.1.md
@@ -253,7 +253,6 @@ The following environment variables (among others) are read by
 
 `STEAM_COMPAT_APP_ID` (integer)
 :   Equivalent to `--steam-app-id="$STEAM_COMPAT_APP_ID"`.
-    (Not used yet, but should be.)
 
 `STEAM_COMPAT_APP_LIBRARY_PATH` (path)
 :   (Not used yet, but should be.)
diff --git a/src/wrap.c b/src/wrap.c
index 9e13320e6..3cb5534c5 100644
--- a/src/wrap.c
+++ b/src/wrap.c
@@ -814,7 +814,8 @@ static GOptionEntry options[] =
   { "steam-app-id", '\0',
     G_OPTION_FLAG_NONE, G_OPTION_ARG_STRING, &opt_steam_app_id,
     "Make --unshare-home use ~/.var/app/com.steampowered.AppN "
-    "as home directory. [Default: $SteamAppId]", "N" },
+    "as home directory. [Default: $STEAM_COMPAT_APP_ID or $SteamAppId]",
+    "N" },
   { "gc-runtimes", '\0',
     G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, &opt_gc_runtimes,
     "If using --copy-runtime-into, garbage-collect old temporary "
@@ -881,7 +882,7 @@ static GOptionEntry options[] =
   { "unshare-home", '\0',
     G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, opt_share_home_cb,
     "Use an app-specific home directory chosen according to --home, "
-    "--freedesktop-app-id, --steam-app-id or $SteamAppId. "
+    "--freedesktop-app-id, --steam-app-id or $STEAM_COMPAT_APP_ID. "
     "[Default if $PRESSURE_VESSEL_HOME is set or "
     "$PRESSURE_VESSEL_SHARE_HOME is 0]",
     NULL },
@@ -1240,6 +1241,13 @@ main (int argc,
       opt_fake_home = g_build_filename (home, ".var", "app",
                                         opt_freedesktop_app_id, NULL);
     }
+  else if (g_getenv ("STEAM_COMPAT_APP_ID") != NULL)
+    {
+      opt_freedesktop_app_id = g_strdup_printf ("com.steampowered.App%s",
+                                                g_getenv ("STEAM_COMPAT_APP_ID"));
+      opt_fake_home = g_build_filename (home, ".var", "app",
+                                        opt_freedesktop_app_id, NULL);
+    }
   else if (g_getenv ("SteamAppId") != NULL)
     {
       opt_freedesktop_app_id = g_strdup_printf ("com.steampowered.App%s",
-- 
GitLab