aboutsummaryrefslogtreecommitdiffstats
path: root/bin/wb-lang
blob: 4e846b6ddfbcc3110298ddd006df8f646e2cf685 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env bash
# Keyboard layout, as a flag.
# Copyright (C) 2026 Danilo M. <danix@danix.xyz>
# Licensed under the GNU General Public License v2 only.
#
# waybar's hyprland/language module styles as #language and nothing else: it
# has no per-language CSS class, so a flag cannot be selected by a selector.
# format-<lang> exists but takes text, not a path. So the flag arrives the
# same way every other icon on this bar does, through an `image` module.
#
#     wb-lang        # print "$path\n$tooltip" for the image module
#
# The images live next to this bar's config: the icon theme ships 13 flags and
# Italian is not among them, and it has no hamburger at all.
set -euo pipefail

flags="$HOME/.config/waybar-udt"

# hyprctl names the layout in full ("Italian", "English (US)"), which is what
# the keymap reports; match on that rather than on the short code, because the
# short code is not in this output.
layout="$(hyprctl devices -j 2>/dev/null \
    | python3 -c 'import json,sys
try:
    d = json.load(sys.stdin)
except Exception:
    sys.exit(0)
for k in d.get("keyboards", []):
    if k.get("name") == "2.4g-dongle":
        print(k.get("active_keymap", ""))
        break' 2>/dev/null || true)"

# Italian gets its flag; English gets the hamburger, which is what the stock
# bar showed for it. Not a national flag on purpose: the layout is "us" but
# the joke predates this bar, so restoring it matters more than consistency.
case "$layout" in
Italian*) flag="flag-it.svg"; name="Italian" ;;
English*) flag="burger.svg";  name="English" ;;
"")       flag="flag-it.svg"; name="unknown" ;;
*)        flag="burger.svg";  name="$layout" ;;
esac

if [[ ! -r "$flags/$flag" ]]; then
	echo "wb-lang: missing $flags/$flag" >&2
	exit 1
fi

echo "$flags/$flag"
echo "Layout: $name"