Skip to content

Commit e9eb1e9

Browse files
authored
Made fix-wm-class.sh run as long as game is running. (#50)
* fix-wm-class.sh now runs while reaper process is running In order to move away from the per game sleep method, I have made it so that fix-wm-class.sh now runs as long as the reaper wrapper process is still running. Should work in 99.9% of cases, tested with UNDERTALE and Pillars. * Removed commented out code * fix-wm-class.sh now monitors processes, and stops running once the process is ended. It extracts the last parameter as the Window Class, so the usasge needs to be fix-wm-class.sh %command% "WM_CLASS". Additionally, it works with gamemoderun, from what little testing I did. However, gamemoderun needs to go before everything else: gamemoderun fix-wm-class.sh %command% "WM_CLASS". Will work on the python script to fix that next. * Updated sif.py. It now: Finds all instances of %command% in an existing launch option array, and removes them. Strips out any excess whitespace and stores the launch options. Instead of appending to the existing options, the options are now overridden, with any existing options (barring %command%) going before fix-wm-class.sh. This is to facilitate the usage of things like mangohod or gamemoderun. for instance, say a game's launch options are currently gamemoderun %command%. Upon running sif.py, the new command will be gamemoderun PATH_TO_SIF/fix-wm-class.sh %command% WM_CLASS; Tested witn UNDERTALE and Pillars of Eternity. I do not know if it will work with WM_CLASS_ALT games, as at the moment fix-wm-class treats the very last argument it receives as WM_CLASS regardless of anything else. * Removed logging. * Removed logging, take 2 (I missed one) * Updated sif.py. WIP on fix-wm-class.sh I've fixed sif.py to account for the new launch options. I don't know much about regexes, so it *might* be a bit hacky, feel free to change it to be more optimal. However, I am still struggling with fix-wm-class.sh. It turns out, if you surround %command% with quotes, steam automatically inserts 'single quotes' around some of the arguments, breaking the %command%. Double quoting makes it even more nested. Regardless, fix-wm-class.sh now works with Undertale... But not with Pillars of Eternity. The game simply never launches. I suspect the spaces in the folder's name are responsible, so I tried launching it without removing the single quotes it generated. That did not change anything. Interestingly, Steam thinks POE is running without the single quote in args; otherwise, it instantly closes. Finally, I have to launch with $@. "$@" causes neither Undertale nor PoE to launch. Need advice. * Implemented suggestions on fix-wm-class.sh. Should work now. One potential issue, any command line arguments after %command% will be stripped away along with everything after fix-wm-class.sh when running SIF. I can also see a scenario where, say a game runs like: `gamemoderun %command% --some-arg` SIF, if fix-window-class has never been run before, will likely put `gamemoderun --some-arg fix-wm-class.sh %command%` I think this will not work. That said, I don't have enough experience with regexes to fix this, and it's a bit beyond the scope of this change, I think. I believe we should merge this, and handle that behavior in another PR potentially? Alternatively I can try to make it work if pointed in the right direction. For now, I added a message to the users to double check their launch options (which I think they should do anyway): `print("\n * - added fix to game launch options. Please double check to ensure your launch options are correct.")` * Changed double check message.
1 parent e169fce commit e9eb1e9

File tree

2 files changed

+39
-10
lines changed

2 files changed

+39
-10
lines changed

fix-wm-class.sh

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
1-
#!/bin/sh
2-
WM_CLASS="$([ "$2" ] && echo "$2" || echo "$1")"
3-
xdotool search --sync --name "$1" set_window --classname "$WM_CLASS" --class "$WM_CLASS" %@
1+
#!/usr/bin/env sh
2+
3+
LOG_FILE="/tmp/steam_watcher.log"
4+
5+
WM_NAME=$1
6+
echo "WM_NAME: $WM_NAME" > $LOG_FILE
7+
shift
8+
WM_NAME_ALT=$1
9+
echo "WM_NAME_ALT: $WM_NAME_ALT" >> $LOG_FILE
10+
shift
11+
12+
WM_CLASS=$WM_NAME_ALT
13+
14+
echo "Starting process: $@" >> $LOG_FILE
15+
"$@" &
16+
17+
PID=$!
18+
echo "Process ID: $PID" >> $LOG_FILE
19+
20+
while kill -0 $PID 2> /dev/null; do
21+
xdotool search --sync --name "$WM_NAME" set_window --classname "$WM_CLASS" --class "$WM_CLASS" %@
22+
echo "Process still running: $(date)" >> $LOG_FILE
23+
sleep 1
24+
done
25+
exit 0

sif.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -202,18 +202,24 @@ def fix_launch_option(app_id, wm_name, wm_name_alt=""):
202202
app = apps[app_id]
203203
if "LaunchOptions" not in app.keys():
204204
app["LaunchOptions"] = ""
205-
app["LaunchOptions"] = sub("&\\s/.*fix-wm-class\\.sh.*?;", "", app["LaunchOptions"])
205+
app["LaunchOptions"] = sub("\\s/.*fix-wm-class\\.sh.*?;", "", app["LaunchOptions"])
206+
app["LaunchOptions"] = sub("%command%", "", app["LaunchOptions"])
207+
launch_options = app["LaunchOptions"].strip()
206208
script = str(WM_CLASS_FIXER_SCRIPT)
207209
if wm_name_alt:
208-
app["LaunchOptions"] += '& %s "%s" "%s";' % (
210+
app["LaunchOptions"] = '%s %s "%s" "%s" %%command%%;' % (
211+
launch_options,
209212
script,
210213
wm_name,
211214
wm_name_alt,
212215
)
213-
elif wm_name == "Pillars of Eternity":
214-
app["LaunchOptions"] += '& sleep 5 && %s "%s";' % (script, wm_name)
215216
else:
216-
app["LaunchOptions"] += '& %s "%s";' % (script, wm_name)
217+
app["LaunchOptions"] = '%s %s "%s" "%s" %%command%%;' % (
218+
launch_options,
219+
script,
220+
wm_name,
221+
wm_name,
222+
)
217223
vdf.dump(loaded, open(conf_file, "w"), pretty=True)
218224

219225

@@ -231,7 +237,8 @@ def restore_launch_options():
231237
for app_id in apps.keys():
232238
app = apps[app_id]
233239
if "LaunchOptions" in app.keys():
234-
app["LaunchOptions"] = sub("&\\s/.*fix-wm-class\\.sh.*?;", "", app["LaunchOptions"])
240+
app["LaunchOptions"] = sub("\\s/.*fix-wm-class\\.sh.*?;", " %command%", app["LaunchOptions"])
241+
app["LaunchOptions"] = app["LaunchOptions"].strip()
235242
vdf.dump(loaded, open(conf_file, "w"), pretty=True)
236243

237244

@@ -717,7 +724,7 @@ def quit_handler(_, __):
717724
if steam_detected:
718725
print_warning("\nSome games couldn't be fixed due to running Steam.\nExit Steam and try it again.")
719726
else:
720-
print("\n * - added fix to game launch options")
727+
print("\n * - added fix to game launch options. Double check your launch options just in case.")
721728

722729
if options.pretend:
723730
print_warning("\nNo changes were made because --pretend option was used.")

0 commit comments

Comments
 (0)