From eaaa07bbef3bfdef52495da004183846c105b876 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Mon, 12 Aug 2024 23:03:25 +0200 Subject: ... --- accounts/gkleen@sif/default.nix | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) (limited to 'accounts') diff --git a/accounts/gkleen@sif/default.nix b/accounts/gkleen@sif/default.nix index eea4088a..6b6c7e59 100644 --- a/accounts/gkleen@sif/default.nix +++ b/accounts/gkleen@sif/default.nix @@ -359,7 +359,7 @@ in { output = "eDP-1"; modules-left = [ "hyprland/workspaces" ]; modules-center = [ "hyprland/window" ]; - modules-right = [ "custom/weather" "clock" "privacy" "tray" "pulseaudio" "backlight" "battery" "idle_inhibitor" ]; + modules-right = [ "custom/weather" "custom/keymap" "clock" "privacy" "tray" "pulseaudio" "backlight" "battery" "idle_inhibitor" ]; "custom/weather" = { format = "{}"; @@ -368,6 +368,41 @@ in { exec = "${lib.getExe pkgs.wttrbar} --hide-conditions --custom-indicator \"{ICON} {FeelsLikeC}°\""; return-type = "json"; }; + "custom/keymap" = { + format = "{}"; + tooltip = true; + return-type = "json"; + exec = pkgs.writers.writePython3 "keymap" {} '' + import os + import socket + import re + import subprocess + import json + + + def output(keymap): + short = keymap + if keymap == "English (programmer Dvorak)": + short = "dvp" + elif keymap == "English (US)": + short = "us" + print(json.dumps({'text': short, 'tooltip': keymap}, separators=(',', ':')), flush=True) # noqa: E501 + + + r = subprocess.run(["hyprctl", "devices", "-j"], check=True, stdout=subprocess.PIPE, text=True) # noqa: E501 + for keyboard in json.loads(r.stdout)['keyboards']: + if keyboard['name'] != "at-translated-set-2-keyboard": + continue + output(keyboard['active_keymap']) + + sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) + sock.connect(os.environ["XDG_RUNTIME_DIR"] + "/hypr/" + os.environ["HYPRLAND_INSTANCE_SIGNATURE"] + "/.socket2.sock") # noqa: E501 + expected = re.compile(r'^activelayout>>at-translated-set-2-keyboard,(?P.+)$') # noqa: E501 + for line in sock.makefile(buffering=1, encoding='utf-8'): + if match := expected.match(line): + output(match.group("keymap")) + ''; + }; "hyprland/workspaces" = { all-outputs = true; }; @@ -512,7 +547,7 @@ in { color: @red; } - #custom-weather { + #custom-weather, #custom-keymap { color: @white; opacity: 0.33; } -- cgit v1.2.3