From caace67d796311ab57a51f549debba5a5b5797bd Mon Sep 17 00:00:00 2001 From: Eamonn Rea Date: Sun, 9 Jun 2024 04:57:38 +0100 Subject: [PATCH 1/3] misc: Flatten getGameWindowPID Remove a bunch of nesting for readibility. Needs tested to make sure it still works." --- steamtinkerlaunch | 130 ++++++++++++++++++++++++---------------------- 1 file changed, 67 insertions(+), 63 deletions(-) diff --git a/steamtinkerlaunch b/steamtinkerlaunch index 71c2b1bb..d55d593e 100755 --- a/steamtinkerlaunch +++ b/steamtinkerlaunch @@ -7674,75 +7674,79 @@ function getGameWinNameFromXid { function getGameWindowPID { if [ "$MO2MODE" == "gui" ]; then writelog "SKIP" "${FUNCNAME[0]} - Skipping check for window pid, because MO2MODE is '$MO2MODE'" - else - if [ -n "$GAMEWINPID" ]; then - writelog "SKIP" "${FUNCNAME[0]} - Already have the GAMEWINPID '$GAMEWINPID'" - echo "$GAMEWINPID" - else - MAXWAIT=20 - COUNTER=0 - TESTPID="$NON" - WASCLOSED=0 + fi - touch "$PIDLOCK" + if [ -n "$GAMEWINPID" ]; then + writelog "SKIP" "${FUNCNAME[0]} - Already have the GAMEWINPID '$GAMEWINPID'" + echo "$GAMEWINPID" - while [ "$COUNTER" -lt "$MAXWAIT" ]; do - if [ -f "$CLOSETMP" ]; then - writelog "WAIT" "${FUNCNAME[0]} - ${PROGNAME,,} is just closing - leaving loop" - WASCLOSED=1 - break - fi - TESTPID="$("$XDO" getactivewindow getwindowpid)" - SYMCWD="$(readlink "/proc/$TESTPID/cwd")" - SYMEXE="$(readlink "/proc/$TESTPID/exe")" - - if [ -n "$TESTPID" ]; then - if [ -n "$HAVPA" ]; then - writelog "WAIT" "${FUNCNAME[0]} - Found PID '$TESTPID' for game 'HAVPA' '$HAVPA' - leaving loop" - FOUNDWIN="$YES" - break; - elif [ -n "$EXECUTABLE" ] && [ "$EXECUTABLE" == "$(cat "/proc/$TESTPID/comm")" ]; then - writelog "WAIT" "${FUNCNAME[0]} - Found PID '$TESTPID' for game 'EXECUTABLE' '$EXECUTABLE' - leaving loop" - FOUNDWIN="$YES" - break; - elif [ -n "$GE" ] && [ "$GE" == "$(cut -d '.' -f1 < "/proc/$TESTPID/comm")" ]; then - writelog "WAIT" "${FUNCNAME[0]} - Found PID '$TESTPID' for game executable 'GE' '$GE' - leaving loop" - FOUNDWIN="$YES" - break; - else - # might not even be required anymore - maybe remove later: - if [[ "$SYMCWD" == "$EFD" ]] && [[ "$SYMEXE" != *"$YAD"* ]]; then - writelog "WAIT" "${FUNCNAME[0]} - Found PID '$TESTPID' for CWD '$SYMCWD' with EXE '$SYMEXE' - leaving loop" - FOUNDWIN="$YES" - break; - fi - if [ -n "$STEAM_COMPAT_CLIENT_INSTALL_PATH" ] && [[ "$SYMCWD" == "$STEAM_COMPAT_CLIENT_INSTALL_PATH" ]] && [[ "$SYMEXE" != *"$YAD"* ]]; then - writelog "WAIT" "${FUNCNAME[0]} - Found PID '$TESTPID' for STEAM_COMPAT_CLIENT_INSTALL_PATH '$SYMCWD' with EXE '$SYMEXE' - leaving loop" - FOUNDWIN="$YES" - break; - fi - fi - fi - writelog "WAIT" "${FUNCNAME[0]} - Sec $COUNTER/$MAXWAIT Game Window with pwd '$EFD' not yet in front" - COUNTER=$((COUNTER+1)) - sleep 1 - done + return + fi + + MAXWAIT=20 + COUNTER=0 + TESTPID="$NON" + WASCLOSED=0 - rm "$PIDLOCK" 2>/dev/null + touch "$PIDLOCK" - if [ "$FOUNDWIN" == "$YES" ]; then - if [ "$TESTPID" == "$NON" ]; then - writelog "SKIP" "${FUNCNAME[0]} - FAIL - Found PID returned but it is empty: '$TESTPID'" - fi - writelog "INFO" "${FUNCNAME[0]} - Found PID '$TESTPID' for running exe '$(readlink "/proc/$TESTPID/exe")'" - echo "$TESTPID" - else - if [ "$WASCLOSED" -eq 0 ]; then - writelog "SKIP" "${FUNCNAME[0]} - ERROR - timeout waiting for '$EFD' window" - echo "$NON" - fi + while [ "$COUNTER" -lt "$MAXWAIT" ]; do + if [ -f "$CLOSETMP" ]; then + writelog "WAIT" "${FUNCNAME[0]} - ${PROGNAME,,} is just closing - leaving loop" + WASCLOSED=1 + break + fi + TESTPID="$("$XDO" getactivewindow getwindowpid)" + SYMCWD="$(readlink "/proc/$TESTPID/cwd")" + SYMEXE="$(readlink "/proc/$TESTPID/exe")" + + if [ -z "$TESTPID" ]; then + continue + fi + + if [ -n "$HAVPA" ]; then + writelog "WAIT" "${FUNCNAME[0]} - Found PID '$TESTPID' for game 'HAVPA' '$HAVPA' - leaving loop" + FOUNDWIN="$YES" + break; + elif [ -n "$EXECUTABLE" ] && [ "$EXECUTABLE" == "$(cat "/proc/$TESTPID/comm")" ]; then + writelog "WAIT" "${FUNCNAME[0]} - Found PID '$TESTPID' for game 'EXECUTABLE' '$EXECUTABLE' - leaving loop" + FOUNDWIN="$YES" + break; + elif [ -n "$GE" ] && [ "$GE" == "$(cut -d '.' -f1 < "/proc/$TESTPID/comm")" ]; then + writelog "WAIT" "${FUNCNAME[0]} - Found PID '$TESTPID' for game executable 'GE' '$GE' - leaving loop" + FOUNDWIN="$YES" + break; + else + # might not even be required anymore - maybe remove later: + if [[ "$SYMCWD" == "$EFD" ]] && [[ "$SYMEXE" != *"$YAD"* ]]; then + writelog "WAIT" "${FUNCNAME[0]} - Found PID '$TESTPID' for CWD '$SYMCWD' with EXE '$SYMEXE' - leaving loop" + FOUNDWIN="$YES" + break; + fi + if [ -n "$STEAM_COMPAT_CLIENT_INSTALL_PATH" ] && [[ "$SYMCWD" == "$STEAM_COMPAT_CLIENT_INSTALL_PATH" ]] && [[ "$SYMEXE" != *"$YAD"* ]]; then + writelog "WAIT" "${FUNCNAME[0]} - Found PID '$TESTPID' for STEAM_COMPAT_CLIENT_INSTALL_PATH '$SYMCWD' with EXE '$SYMEXE' - leaving loop" + FOUNDWIN="$YES" + break; fi fi + + writelog "WAIT" "${FUNCNAME[0]} - Sec $COUNTER/$MAXWAIT Game Window with pwd '$EFD' not yet in front" + COUNTER=$((COUNTER+1)) + sleep 1 + done + + rm "$PIDLOCK" 2>/dev/null + + if [ "$FOUNDWIN" == "$YES" ]; then + if [ "$TESTPID" == "$NON" ]; then + writelog "SKIP" "${FUNCNAME[0]} - FAIL - Found PID returned but it is empty: '$TESTPID'" + fi + + writelog "INFO" "${FUNCNAME[0]} - Found PID '$TESTPID' for running exe '$(readlink "/proc/$TESTPID/exe")'" + echo "$TESTPID" + elif [ "$WASCLOSED" -eq 0 ]; then + writelog "SKIP" "${FUNCNAME[0]} - ERROR - timeout waiting for '$EFD' window" + echo "$NON" fi } From 1f9dab3f611c2772af8ac094ba47d63ab4006d72 Mon Sep 17 00:00:00 2001 From: Eamonn Rea Date: Wed, 12 Jun 2024 21:32:27 +0100 Subject: [PATCH 2/3] version change --- steamtinkerlaunch | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/steamtinkerlaunch b/steamtinkerlaunch index d55d593e..027434ab 100755 --- a/steamtinkerlaunch +++ b/steamtinkerlaunch @@ -7,7 +7,7 @@ PREFIX="/usr" PROGNAME="SteamTinkerLaunch" NICEPROGNAME="Steam Tinker Launch" -PROGVERS="v14.0.20240609-3" +PROGVERS="v14.0.20240612-1 (refactor-getgamewindowpix)" PROGCMD="${0##*/}" PROGINTERNALPROTNAME="Proton-stl" SHOSTL="stl" From 603df7207ff2cac4af2bba5afcc8ca178e715f13 Mon Sep 17 00:00:00 2001 From: Eamonn Rea Date: Wed, 12 Jun 2024 21:37:17 +0100 Subject: [PATCH 3/3] version bump --- steamtinkerlaunch | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/steamtinkerlaunch b/steamtinkerlaunch index 027434ab..532141b7 100755 --- a/steamtinkerlaunch +++ b/steamtinkerlaunch @@ -7,7 +7,7 @@ PREFIX="/usr" PROGNAME="SteamTinkerLaunch" NICEPROGNAME="Steam Tinker Launch" -PROGVERS="v14.0.20240612-1 (refactor-getgamewindowpix)" +PROGVERS="v14.0.20240612-1" PROGCMD="${0##*/}" PROGINTERNALPROTNAME="Proton-stl" SHOSTL="stl"