From 7d63f8c47f263fdba46e7f6cf1df0c7eeae4612b Mon Sep 17 00:00:00 2001 From: Eamonn Rea Date: Wed, 28 Aug 2024 23:16:31 +0100 Subject: [PATCH 1/6] GameScope: Fix blank `GSSHWRES` and `GSINTRES` displaying '`x`' --- steamtinkerlaunch | 85 +++++++++++++++++++++++++++++++---------------- 1 file changed, 57 insertions(+), 28 deletions(-) diff --git a/steamtinkerlaunch b/steamtinkerlaunch index 8114d210..9983cc83 100755 --- a/steamtinkerlaunch +++ b/steamtinkerlaunch @@ -7,7 +7,7 @@ PREFIX="/usr" PROGNAME="SteamTinkerLaunch" NICEPROGNAME="Steam Tinker Launch" -PROGVERS="v14.0.20240831-1" +PROGVERS="v14.0.20240829-1 (gamescope-use-getgamescopearg-for-gsshwres-gsintres)" PROGCMD="${0##*/}" PROGINTERNALPROTNAME="Proton-stl" SHOSTL="stl" @@ -11294,41 +11294,70 @@ function setGameScopeVars { ARGTYPE="${6,,}" # e.g. "chk", "cb", etc (matches Yad widget types mostly) # Set values for undefined arguments - if [ -z "$VAR" ]; then - if grep -qw "$FLAG" <<< "$ARGS"; then - if [[ $ARGTYPE =~ "cb" ]] || [[ $ARGTYPE =~ "num" ]]; then - # Get the value given to the argument as the enabled/selected value, e.g. get '2' from '-U 2' if we passed '-U' - tr ' ' '\n' <<< "$ARGS" | grep -wA1 "$FLAG" | tail -n1 - elif [[ $ARGTYPE =~ "path" ]] || [[ $ARGTYPE =~ "txt" ]]; then - # Get value given to arguments with two dashes, like `--` - echo "$ARGS" | sed 's:--:\n--:g' | grep -wA1 "$FLAG" | sed "s:${UNESCAPED_FLAG}::g;s:-:\n-:g" | head -n1 | xargs - else - echo "$TRUEVAL" - fi + if [ -n "$VAR" ]; then + return + fi + + # If the flag is not in the args string, return the default value for display purposes + if ! grep -qw "$FLAG" <<< "$ARGS"; then + echo "$DEFVAL" + return + fi + + if [[ $ARGTYPE =~ "cb" ]] || [[ $ARGTYPE =~ "num" ]]; then + # Get the value given to the argument as the enabled/selected value, e.g. get '2' from '-U 2' if we passed '-U' + # If the value does not contain only numbers (with or without decimals) then this will be blank and we return the default value 'DEFVAL' + # + # If we get passed an invalid GameScope commandline argument where a flag that is supposed to be followed by a NUMBER is not, + # we could end up returning the next argument, e.g. `-s -f` would return `-s` if we didn't include the `grep -P` + # Using the `grep -P` we filter out potential garbage returned by the rest of the parsing. + # + # We are most likely to encounter problems without this `grep -P` when it comes to the `GSINTRES` and `GSSHWRES`, + # as if these are blank we end up displaying 'x'. + # + # For comboboxes that can display text, we will just have to assume we are passed a valid string, as freetext comboboxes could contain + # anything and we cannot/should not try to assume what is valid for them in this way. + # This logic only exists to filter out non-numerical values for flags which expect to be given a numerical argument + # + # For more background, see: https://github.com/sonic2kk/steamtinkerlaunch/pull/1152#issuecomment-2316286429 + GSPARSEDARGVAL="$( tr ' ' '\n' <<< "$ARGS" | grep -wA1 "$FLAG" | tail -n1 )" + + # Don't validate parsed value for combobox, this is free-text and could be anything + if ! [[ $ARGTYPE =~ "num" ]]; then + echo "$GSPARSEDARGVAL" + return + fi + + # If we expect our flag to be followed by a numerical value (either integer or decimal), we need to make sure we actually return + # a numerical value, so the `grep` will ensure this + GSPARSEDARGNUMVAL="$( echo "${GSPARSEDARGVAL}" | grep -P "^([\d]+)(?:\.([\d]{1,2}?))?$" )" + if [ -n "${GSPARSEDARGNUMVAL}" ]; then + echo "$GSPARSEDARGNUMVAL" else echo "$DEFVAL" fi + elif [[ $ARGTYPE =~ "path" ]] || [[ $ARGTYPE =~ "txt" ]]; then + # Get value given to arguments with two dashes, like `--` + echo "$ARGS" | sed 's:--:\n--:g' | grep -wA1 "$FLAG" | sed "s:${UNESCAPED_FLAG}::g;s:-:\n-:g" | head -n1 | xargs + else + echo "$TRUEVAL" fi } function getGameScopeGeneralOpts { - # GameScope Show Resolution (corresponds to -W, -H options, uppercase) -- Actual GameScope window size -- Dropdown - if [ -z "$GSSHWRES" ]; then - if ! grep -qw "\-W" <<< "$GAMESCOPE_ARGS" || ! grep -qw "\-H" <<< "$GAMESCOPE_ARGS"; then - GSSHWRES="1280x720" - else - GSSHWRES="$(tr ' ' '\n' <<< "$GAMESCOPE_ARGS" | grep -wA1 "\-W" | tail -n1)x$(tr ' ' '\n' <<< "$GAMESCOPE_ARGS" | grep -wA1 "\-H" | tail -n1)" - fi - fi + # GameScope Show Resolution (corresponds to -W, -H options, uppercase) -- Actual GameScope window size (defaults to 1280x720) -- Dropdown + # Although this is a combobox, we still use "num" as the `getGameScopeArg` type because we want numeric validation + GSSHOWRESARGWIDTH="$( getGameScopeArg "$GAMESCOPE_ARGS" "-W" "$GSSHOWRESARGWIDTH" "" "1280" "num")" + GSSHOWRESARGHEIGHT="$( getGameScopeArg "$GAMESCOPE_ARGS" "-H" "$GSSHOWRESARGHEIGHT" "" "720" "num")" - # GameScope Internal Resolution (corresponds to -w, -h options, lowercase) -- Resolution that games see -- Dropdown - if [ -z "$GSINTRES" ]; then - if ! grep -qw "\-w" <<< "$GAMESCOPE_ARGS" || ! grep -qw "\-h" <<< "$GAMESCOPE_ARGS"; then - GSINTRES="1280x720" - else - GSINTRES="$(tr ' ' '\n' <<< "$GAMESCOPE_ARGS" | grep -wA1 "\-w" | tail -n1)x$(tr ' ' '\n' <<< "$GAMESCOPE_ARGS" | grep -wA1 "\-h" | tail -n1)" - fi - fi + GSSHWRES="${GSSHOWRESARGWIDTH}x${GSSHOWRESARGHEIGHT}" + + # GameScope Internal Resolution (corresponds to -w, -h options, lowercase) -- Resolution that games see (defaults to 1280x720) -- Dropdown + # Although this is a combobox, we still use "num" as the `getGameScopeArg` type because we want numeric validation + GSINTRESARGWIDTH="$( getGameScopeArg "$GAMESCOPE_ARGS" "-W" "$GSINTRESARGWIDTH" "" "1280" "num")" + GSINTRESARGHEIGHT="$( getGameScopeArg "$GAMESCOPE_ARGS" "-H" "$GSINTRESARGHEIGHT" "" "720" "num")" + + GSINTRES="${GSINTRESARGWIDTH}x${GSINTRESARGHEIGHT}" # Default internal resolution to $NON ('none') if blank -- Ensures we don't pass invalid resolution to GameScope if [ -z "$GSINTRES" ]; then GSINTRES="$NON"; fi From 7ef170f13ad03169238eb262d3ed4d3fc058c301 Mon Sep 17 00:00:00 2001 From: Eamonn Rea Date: Wed, 28 Aug 2024 23:57:22 +0100 Subject: [PATCH 2/6] move comment to more relevant location --- steamtinkerlaunch | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/steamtinkerlaunch b/steamtinkerlaunch index 9983cc83..758ed188 100755 --- a/steamtinkerlaunch +++ b/steamtinkerlaunch @@ -7,7 +7,7 @@ PREFIX="/usr" PROGNAME="SteamTinkerLaunch" NICEPROGNAME="Steam Tinker Launch" -PROGVERS="v14.0.20240829-1 (gamescope-use-getgamescopearg-for-gsshwres-gsintres)" +PROGVERS="v14.0.20240829-2 (gamescope-use-getgamescopearg-for-gsshwres-gsintres)" PROGCMD="${0##*/}" PROGINTERNALPROTNAME="Proton-stl" SHOSTL="stl" @@ -11307,7 +11307,14 @@ function setGameScopeVars { if [[ $ARGTYPE =~ "cb" ]] || [[ $ARGTYPE =~ "num" ]]; then # Get the value given to the argument as the enabled/selected value, e.g. get '2' from '-U 2' if we passed '-U' # If the value does not contain only numbers (with or without decimals) then this will be blank and we return the default value 'DEFVAL' - # + GSPARSEDARGVAL="$( tr ' ' '\n' <<< "$ARGS" | grep -wA1 "$FLAG" | tail -n1 )" + + # Don't validate parsed value for combobox, this is free-text and could be anything + if ! [[ $ARGTYPE =~ "num" ]]; then + echo "$GSPARSEDARGVAL" + return + fi + # If we get passed an invalid GameScope commandline argument where a flag that is supposed to be followed by a NUMBER is not, # we could end up returning the next argument, e.g. `-s -f` would return `-s` if we didn't include the `grep -P` # Using the `grep -P` we filter out potential garbage returned by the rest of the parsing. @@ -11320,16 +11327,6 @@ function setGameScopeVars { # This logic only exists to filter out non-numerical values for flags which expect to be given a numerical argument # # For more background, see: https://github.com/sonic2kk/steamtinkerlaunch/pull/1152#issuecomment-2316286429 - GSPARSEDARGVAL="$( tr ' ' '\n' <<< "$ARGS" | grep -wA1 "$FLAG" | tail -n1 )" - - # Don't validate parsed value for combobox, this is free-text and could be anything - if ! [[ $ARGTYPE =~ "num" ]]; then - echo "$GSPARSEDARGVAL" - return - fi - - # If we expect our flag to be followed by a numerical value (either integer or decimal), we need to make sure we actually return - # a numerical value, so the `grep` will ensure this GSPARSEDARGNUMVAL="$( echo "${GSPARSEDARGVAL}" | grep -P "^([\d]+)(?:\.([\d]{1,2}?))?$" )" if [ -n "${GSPARSEDARGNUMVAL}" ]; then echo "$GSPARSEDARGNUMVAL" From 134d5ebc1a7c19462e6610997fec40cc048de732 Mon Sep 17 00:00:00 2001 From: Eamonn Rea Date: Thu, 29 Aug 2024 23:45:27 +0100 Subject: [PATCH 3/6] GameScope: Only add internal and show resolution if width and height values are valid --- steamtinkerlaunch | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/steamtinkerlaunch b/steamtinkerlaunch index 758ed188..0aa68a94 100755 --- a/steamtinkerlaunch +++ b/steamtinkerlaunch @@ -7,7 +7,7 @@ PREFIX="/usr" PROGNAME="SteamTinkerLaunch" NICEPROGNAME="Steam Tinker Launch" -PROGVERS="v14.0.20240829-2 (gamescope-use-getgamescopearg-for-gsshwres-gsintres)" +PROGVERS="v14.0.20240829-3 (gamescope-use-getgamescopearg-for-gsshwres-gsintres)" PROGCMD="${0##*/}" PROGINTERNALPROTNAME="Proton-stl" SHOSTL="stl" @@ -11825,19 +11825,25 @@ function GameScopeGui { # Build the GameScope arguments string unset GAMESCOPE_ARGS + GAMESCOPE_ARGS="" + + # Internal width/height (-w, -h) broken out from string like '1280x720' + # NOTE: In future if `GSINTW` is blank but `GSINTH` is set, we could calculate a corresponding 16:9 width like GameScope does GSINTW1="${GSINTRES%x*}" GSINTW="${GSINTW1%%-*}" GSINTH1="${GSINTRES#*x}" GSINTH="${GSINTH1%%-*}" - GAMESCOPE_ARGS="-w ${GSINTW} -h ${GSINTH}" + # Show width/height (-W, -H) broken out from string like '1280x720' + # NOTE: In future if `GSINTW` is blank but `GSINTH` is set, we could calculate a corresponding 16:9 width like GameScope does GSSHWW1="${GSSHWRES%x*}" GSSHWW="${GSSHWW1%%-*}" GSSHWH1="${GSSHWRES#*x}" GSSHWH="${GSSHWH1%%-*}" - GAMESCOPE_ARGS="${GAMESCOPE_ARGS} -W ${GSSHWW} -H ${GSSHWH}" ### GENERAL OPTIONS ### + if [ -n "$GSINTW" ] && [ -n "$GSINTH" ] ; then GAMESCOPE_ARGS="${GAMESCOPE_ARGS} -w ${GSINTW} -h ${GSINTH}"; fi + if [ -n "$GSSHWW" ] && [ -n "$GSSHWH" ] ; then GAMESCOPE_ARGS="${GAMESCOPE_ARGS} -W ${GSSHWW} -H ${GSSHWH}"; fi if [ "$GSFLR" -eq "$GSFLR" ] 2>/dev/null ; then GAMESCOPE_ARGS="${GAMESCOPE_ARGS} -r ${GSFLR}"; fi if [ "$GSFLU" -eq "$GSFLU" ] 2>/dev/null ; then GAMESCOPE_ARGS="${GAMESCOPE_ARGS} -o ${GSFLU}"; fi if [ "$GSFS" == "TRUE" ] ; then GAMESCOPE_ARGS="${GAMESCOPE_ARGS} -f"; fi From 0ea43d642c95f9259e50ba8440287b12c7c03d19 Mon Sep 17 00:00:00 2001 From: Eamonn Rea Date: Sat, 31 Aug 2024 04:37:19 +0100 Subject: [PATCH 4/6] GameScope: Remove trailing whitespace from GAMESCOPE_ARGS string Now that GAMESCOPE_ARGS is not guaranteed to have any values, GAMESCOPE_ARGS can be blank when appending flags, so we should remove trailing whitespaces. This should be purely cosmetic. --- steamtinkerlaunch | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/steamtinkerlaunch b/steamtinkerlaunch index 0aa68a94..96c5c46a 100755 --- a/steamtinkerlaunch +++ b/steamtinkerlaunch @@ -7,7 +7,7 @@ PREFIX="/usr" PROGNAME="SteamTinkerLaunch" NICEPROGNAME="Steam Tinker Launch" -PROGVERS="v14.0.20240829-3 (gamescope-use-getgamescopearg-for-gsshwres-gsintres)" +PROGVERS="v14.0.20240831-1 (gamescope-use-getgamescopearg-for-gsshwres-gsintres)" PROGCMD="${0##*/}" PROGINTERNALPROTNAME="Proton-stl" SHOSTL="stl" @@ -11985,7 +11985,8 @@ function GameScopeGui { if [ "$GSHDLS" == "TRUE" ] ; then GAMESCOPE_ARGS="${GAMESCOPE_ARGS} --headless"; fi ### ADVANCED OPTIONS END ### - GAMESCOPE_ARGS="${GAMESCOPE_ARGS} --" + # Remove trailing whitespace and append '--' + GAMESCOPE_ARGS="${GAMESCOPE_ARGS# } --" writelog "INFO" "${FUNCNAME[0]} - Saving configured GAMESCOPE_ARGS '$GAMESCOPE_ARGS' into '$STLGAMECFG'" touch "$FUPDATE" From 758711a7ce1c3f8f085851078dfeace849078840 Mon Sep 17 00:00:00 2001 From: Eamonn Rea Date: Sat, 31 Aug 2024 04:43:33 +0100 Subject: [PATCH 5/6] GameScope: Correct GSINTRES width and height parsing Messed up the casing, jeez... I need more coffee. --- steamtinkerlaunch | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/steamtinkerlaunch b/steamtinkerlaunch index 96c5c46a..d53b7116 100755 --- a/steamtinkerlaunch +++ b/steamtinkerlaunch @@ -11351,8 +11351,8 @@ function setGameScopeVars { # GameScope Internal Resolution (corresponds to -w, -h options, lowercase) -- Resolution that games see (defaults to 1280x720) -- Dropdown # Although this is a combobox, we still use "num" as the `getGameScopeArg` type because we want numeric validation - GSINTRESARGWIDTH="$( getGameScopeArg "$GAMESCOPE_ARGS" "-W" "$GSINTRESARGWIDTH" "" "1280" "num")" - GSINTRESARGHEIGHT="$( getGameScopeArg "$GAMESCOPE_ARGS" "-H" "$GSINTRESARGHEIGHT" "" "720" "num")" + GSINTRESARGWIDTH="$( getGameScopeArg "$GAMESCOPE_ARGS" "-w" "$GSINTRESARGWIDTH" "" "1280" "num")" + GSINTRESARGHEIGHT="$( getGameScopeArg "$GAMESCOPE_ARGS" "-h" "$GSINTRESARGHEIGHT" "" "720" "num")" GSINTRES="${GSINTRESARGWIDTH}x${GSINTRESARGHEIGHT}" From 5e3602c37077f09a4e913bd58a2863da02c1a964 Mon Sep 17 00:00:00 2001 From: Eamonn Rea Date: Tue, 3 Sep 2024 22:40:39 +0100 Subject: [PATCH 6/6] version bump --- steamtinkerlaunch | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/steamtinkerlaunch b/steamtinkerlaunch index d53b7116..d2290226 100755 --- a/steamtinkerlaunch +++ b/steamtinkerlaunch @@ -7,7 +7,7 @@ PREFIX="/usr" PROGNAME="SteamTinkerLaunch" NICEPROGNAME="Steam Tinker Launch" -PROGVERS="v14.0.20240831-1 (gamescope-use-getgamescopearg-for-gsshwres-gsintres)" +PROGVERS="v14.0.20240903-1" PROGCMD="${0##*/}" PROGINTERNALPROTNAME="Proton-stl" SHOSTL="stl"