Accept comma decimal in mode rates (locale-tolerant parsing)#425
Open
singularix-maker wants to merge 2 commits into
Open
Accept comma decimal in mode rates (locale-tolerant parsing)#425singularix-maker wants to merge 2 commits into
singularix-maker wants to merge 2 commits into
Conversation
Under locales that use a comma as decimal separator (de_DE, fr_FR,
sv_SE, ...) `xrandr --verbose` prints mode rates like `90,00Hz`.
The regex `(?P<rate>[0-9\.]+)Hz` does not match, and parsing fails
entirely with "Parsing XRandR output failed, N bytes left unmatched".
Setting `Environment=LC_ALL=C` in the systemd unit does not help
because `fork_child_autorandr` clears the environment and inherits
the user's session locale before invoking xrandr.
This patch:
1. Extends the two `rate` patterns to accept `[0-9\.,]+`.
2. Normalizes captured rates with `.replace(",", ".")` so the value
stored in profile config and passed to `xrandr --rate` stays in
the canonical form.
xrandr's option parser is locale-aware for floats: under locales like
de_DE.UTF-8 it rejects dot decimals (`--gamma 1.0`, `--rate 165.00`)
with "invalid argument" and only accepts comma (`--gamma 1,0`).
After the previous commit normalized stored rates to dot notation,
autorandr's apply step would invoke xrandr with arguments xrandr
itself cannot parse under non-C locales, e.g.:
Failed to apply profile 'docked' (line 1019):
Command failed: xrandr --fb 1920x1080 --output eDP-1 --off
--output DP-3-2 --crtc 0 --gamma 1.0 --mode 1920x1080
--pos 0x0 --primary --rate 165.00 ...
Force `LC_ALL=C` for the xrandr subprocess in `call_and_retry` (the
choke point for all xrandr apply calls). Postswitch/preswitch
script hooks use their own subprocess.call and are unaffected.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #424.
Under locales that use a comma as decimal separator (de_DE, fr_FR, sv_SE, ...)
xrandr --verboseprints mode rates like90,00Hz. The regex(?P<rate>[0-9\.]+)Hzdoes not match, and parsing fails entirely.Setting
Environment=LC_ALL=Cin the systemd unit does not help becausefork_child_autorandrclears the environment and inherits the user's session locale.This patch:
ratepatterns to accept[0-9\.,]+..replace(",", ".")so that the value stored in profile config and passed toxrandr --ratestays in the canonical form.Tested under
LANG=de_DE.UTF-8 LC_NUMERIC=de_DE.UTF-8—autorandr --detectednow exits 0 instead of failing with "12585 bytes left unmatched".