From 12d8e25a2767c9fb34c8198d4db2f6b1c6c3b967 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Thu, 16 Jan 2025 11:15:01 +0100 Subject: ... --- accounts/gkleen@sif/niri/waybar.nix | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) (limited to 'accounts/gkleen@sif/niri/waybar.nix') diff --git a/accounts/gkleen@sif/niri/waybar.nix b/accounts/gkleen@sif/niri/waybar.nix index 1c328ea6..5ee483a7 100644 --- a/accounts/gkleen@sif/niri/waybar.nix +++ b/accounts/gkleen@sif/niri/waybar.nix @@ -24,7 +24,7 @@ modules-center = [ "niri/window" ]; modules-right = [ # "custom/worktime" "custom/worktime-today" "custom/weather" - # "custom/keymap" + "custom/keymap" "privacy" "tray" "wireplumber" "backlight" "battery" "idle_inhibitor" "clock" ]; "custom/weather" = { @@ -41,8 +41,6 @@ exec = pkgs.writers.writePython3 "keymap" {} '' import os import socket - import re - import subprocess import json @@ -55,20 +53,20 @@ 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']) + keyboard_layouts = [] 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 + sock.connect(os.environ["NIRI_SOCKET"]) + sock.send(b"\"EventStream\"\n") for line in sock.makefile(buffering=1, encoding='utf-8'): - if match := expected.match(line): - output(match.group("keymap")) + if line_json := json.loads(line): + if "KeyboardLayoutsChanged" in line_json: + keyboard_layouts = line_json["KeyboardLayoutsChanged"]["keyboard_layouts"]["names"] # noqa: E501 + output(keyboard_layouts[line_json["KeyboardLayoutsChanged"]["keyboard_layouts"]["current_idx"]]) # noqa: E501 + if "KeyboardLayoutSwitched" in line_json: + output(keyboard_layouts[line_json["KeyboardLayoutSwitched"]["idx"]]) # noqa: E501 ''; - on-click = "hyprctl switchxkblayout at-translated-set-2-keyboard next"; + on-click = "niri msg action switch-layout next"; }; "custom/worktime" = { interval = 60; -- cgit v1.2.3