Skip to content

Accept comma decimal in mode rates (locale-tolerant parsing)#425

Open
singularix-maker wants to merge 2 commits into
phillipberndt:masterfrom
singularix-maker:fix/de-locale-comma-decimal
Open

Accept comma decimal in mode rates (locale-tolerant parsing)#425
singularix-maker wants to merge 2 commits into
phillipberndt:masterfrom
singularix-maker:fix/de-locale-comma-decimal

Conversation

@singularix-maker

Copy link
Copy Markdown

Fixes #424.

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.

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.

This patch:

  1. Extends the two rate patterns to accept [0-9\.,]+.
  2. Normalizes captured rates with .replace(",", ".") so that the value stored in profile config and passed to xrandr --rate stays in the canonical form.

Tested under LANG=de_DE.UTF-8 LC_NUMERIC=de_DE.UTF-8autorandr --detected now exits 0 instead of failing with "12585 bytes left unmatched".

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Parsing XRandR output failed with comma-decimal locales (de_DE, fr_FR, ...)

1 participant