feat(waybar): show the layout indicator only when the layout is ambiguous (#109)
All checks were successful
Check / eval (push) Successful in 3m27s
All checks were successful
Check / eval (push) Successful in 3m27s
The indicator answers "which layout am I typing in?", so it is worth bar space exactly when that question has more than one answer. It was gated on a per-device override merely *existing*, which is the trap this box walked into: the junk rows a keyboard's extra HID collections leave behind are all remembered at the session layout, so they added no second answer and still raised an indicator that could only ever show one value. Gate on layouts rather than devices, and read the runtime-remembered settings.keyboard.devices alongside the declared option — the new-keyboard watcher writes those without a rebuild and they only graduate into keyboard.devices later, so a bar reading the option alone was wrong for exactly as long as the memory was fresh, which is when it matters most. keyboard.layouts is now excluded on purpose: hyprland.nix keeps it as the pool the picker offers first and deliberately never merges it into kb_layout, so listing candidates cannot make the current layout ambiguous. A device actually using one of them still does. All four whole-swaps list the module unconditionally, so a single-layout setup saw on a swapped bar what the generated bar hides — the parity rule was already broken. Filter a swap through the same answer instead of asking four hand-written files to re-derive it. Logic is pure in modules/home/waybar-language.nix, matching monitor-rules / dock-audio-rules; checks.waybar-language unit-tests both halves against boreal's real swap, including a fixture-drift guard so the parity assertion cannot pass vacuously. Verified V2: new check passes, docking-ux and theme-wholeswap still pass, `nix flake check` is clean, and the live config's generated bar now resolves modules-right without hyprland/language on its single-layout default. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
53
flake.nix
53
flake.nix
@@ -876,6 +876,59 @@
|
||||
in
|
||||
assert ok; pkgs.runCommand "nomarchy-display-profiles" { } "touch $out";
|
||||
|
||||
# The layout indicator's gate, and the parity of a whole-swap bar
|
||||
# with the generated one. Both halves are pure — the interesting
|
||||
# inputs (a fresh runtime memory, junk device rows) are awkward to
|
||||
# stage in a VM and trivial to state here.
|
||||
waybar-language =
|
||||
let
|
||||
inherit (nixpkgs) lib;
|
||||
langLib = import ./modules/home/waybar-language.nix { inherit lib; };
|
||||
expect = cond: msg: lib.assertMsg cond "waybar-language: ${msg}";
|
||||
swap = builtins.fromJSON (builtins.readFile ./themes/boreal/waybar.jsonc);
|
||||
gatedOff = langLib.gate false swap;
|
||||
inSwap = bar: lib.any
|
||||
(n: builtins.isList bar.${n} && lib.elem "hyprland/language" bar.${n})
|
||||
(lib.filter (lib.hasPrefix "modules-") (lib.attrNames bar));
|
||||
ok =
|
||||
expect (! langLib.show { layout = "us"; })
|
||||
"a plain single-layout session must not show the indicator"
|
||||
&& expect (langLib.show { layout = "us,pt"; })
|
||||
"two session layouts must show the indicator"
|
||||
&& expect (langLib.show {
|
||||
layout = "us";
|
||||
devices.dell-kb.layout = "pt";
|
||||
})
|
||||
"a declared per-device override must show the indicator"
|
||||
&& expect (langLib.show {
|
||||
layout = "us";
|
||||
remembered."by-tech-gaming-keyboard" = "pt";
|
||||
})
|
||||
"a freshly remembered device must show the indicator before it graduates"
|
||||
&& expect (! langLib.show {
|
||||
layout = "us";
|
||||
remembered = {
|
||||
"generic-benq-gw2790qt" = "us";
|
||||
"by-tech-gaming-keyboard-consumer-control" = "us";
|
||||
};
|
||||
})
|
||||
"devices remembered at the session layout add no second answer"
|
||||
&& expect (! langLib.show { layout = "us"; devices.dell-kb.layout = "us"; })
|
||||
"a declared override at the session layout adds no second answer"
|
||||
# The pool is picker candidates only (hyprland.nix never
|
||||
# merges it into kb_layout), so it cannot raise the indicator
|
||||
# by itself — a device actually using one of them does.
|
||||
&& expect (! langLib.show { layout = "us"; })
|
||||
"the candidate pool alone must not show the indicator"
|
||||
&& expect (inSwap swap)
|
||||
"fixture drift: boreal's whole-swap no longer lists the language module"
|
||||
&& expect (! inSwap gatedOff)
|
||||
"a whole-swap must hide the module wherever the generated bar does"
|
||||
&& expect (langLib.gate true swap == swap)
|
||||
"gating on must leave a whole-swap untouched";
|
||||
in
|
||||
assert ok; pkgs.runCommand "nomarchy-waybar-language" { } "touch $out";
|
||||
|
||||
# Docking artifact guard: default/no-profile Home Manager output
|
||||
# must still launch both hotplug watchers, put Rofi on the focused
|
||||
# monitor, expose the manual keyboard picker, and never ship the
|
||||
|
||||
Reference in New Issue
Block a user