popsUlfr / SDH-PauseGames

Decky Loader Plugin for Steam Deck to Pause and Resume games
GNU General Public License v3.0
76 stars 8 forks source link

Opening the settings of any game resumes the last running game with the "Also on overlay" #5

Closed popsUlfr closed 1 year ago

popsUlfr commented 1 year ago

SteamClient.System.UI.RegisterForFocusChangeEvents() for some reason when opening a popup menu or settings for another game it would callback with an object pertaining to the last running game. So, this leads to the game resuming when navigating menus on any game in case the "Also on overlay" is enabled kinda breaking the point of the feature.

@therealpaulgg If you have a bit of time it would be interesting to have a second perspective/opinion on this (or at least another test that this behaviour is not limited to myself). But don't worry I'll surely figure something out by myself.

So basically when hitting the STEAM button with the "Also on overlay" feature enabled, the game gets paused. Appid is 769, pid is that of the game. Now navigating to another game the appid stays 769 but the pid becomes that of the steamwebhelper. If you click on the cog for a game's properties, the appid stays 769 but for some reason the pid and strExeName become that of the last running game. So the game gets resumed while navigating through the property menus even for other games.

Thinking about the best way to work around this.

It also happens in the Steam Stable Client, weird that I missed that in the rounds of testing.

popsUlfr commented 1 year ago
diff --git a/src/backend.ts b/src/backend.ts
index 176f775..cb8de7f 100644
--- a/src/backend.ts
+++ b/src/backend.ts
@@ -353,6 +353,7 @@ export function setupFocusChangeHandler(): () => void {
         )
           return;
         lastPid = fce.focusedApp.pid;
+        if (fce.focusedApp.appid === 769 && lastAppid === 769) return;
         lastAppid = fce.focusedApp.appid;

         if (!(await loadSettings()).autoPause) return;

Can't get more simple than that, seems to work well.

Hmm if you press QAM and then STEAM the game does not pause.

popsUlfr commented 1 year ago
diff --git a/src/backend.ts b/src/backend.ts
index 176f775..6e49e75 100644
--- a/src/backend.ts
+++ b/src/backend.ts
@@ -349,10 +349,17 @@ export function setupFocusChangeHandler(): () => void {
         // skip if we already got such an event before
         if (
           fce.focusedApp.pid === lastPid &&
-          fce.focusedApp.appid === lastAppid
+          fce.focusedApp.appid === lastAppid &&
+          !(validKeyEvent?.eKey === 0)
         )
           return;
         lastPid = fce.focusedApp.pid;
+        if (
+          fce.focusedApp.appid === 769 &&
+          lastAppid === 769 &&
+          !(validKeyEvent?.eKey === 0)
+        )
+          return;
         lastAppid = fce.focusedApp.appid;

         if (!(await loadSettings()).autoPause) return;

Ok this seems to cover the cases and works well :)

popsUlfr commented 1 year ago

I pushed v0.4.1, it should be working as expected now.