GameScope: Use -wA1
in getGameScopeArg to avoid overlap when switches and flags start with the same letter
#1027
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
This PR fixes
getGameScopeArg
by making sure when we match a flag, we match using-w
, so that switches and flags starting with the same letter or having a similar pattern are not matched incorrectly, i.e. make sure-r
and--rt
are matched separately. This also includes cases where the switch might appear in another word, for example--enable-hdr
might match-h
.Problem
We use
setGameScopeVars
to parse theGAMESCOPE_ARGS
string. This will pull out a1
/0
for checkbox values if the flag exists (e.g. return1
to enable the fullscreen checkbox if-f
is present in the string). It can also be used to pull out values for flags that have parameters, such as2
in--fsr-sharpness 2
.However, there was an oversight. When
grep
ing, in one place for getting the width/height, we use-wA1
to get the value, but ingetGameScopeArg
which mirrors a lot of that logic, we don't use-w
. The-w
ensures we match whole words, i.e. make sure-r
and--rt
are not treated as the same! This oversight led to us potentially matching, for example, the Realtime Scheduling checkbox switch--rt
as having an argument when really it should control a checkbox, because grep assumes that it's the same as-r
which is a flag for the focused game framerate limit!If
--rt
was at the end of the string, when trying to get the value for-r
, it meant it would think--
was its value if--rt
was enabled. TheGAMESCOPE_ARGS
are not being parsed correctly!Solution
The solution seems to work as simply as just using
-w
ingrep -wA1
. This will need more testing though!The following debug code should demonstrate the impact of this change:
Before this PR:
--rt
returns1
(correct)-r
returns--
(incorrect, and if you were to move it up by one, it would return--force-grab-cursor
-- it takes the value in front of it incorrectly).After this PR:
--rt
returns1
(correct)-r
returns144
(correct, it takes the value in front of-r
only and not--rt
).