diff options
Diffstat (limited to 'accounts/gkleen@sif')
| -rw-r--r-- | accounts/gkleen@sif/niri/waybar.nix | 24 |
1 files changed, 11 insertions, 13 deletions
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 @@ | |||
| 24 | modules-center = [ "niri/window" ]; | 24 | modules-center = [ "niri/window" ]; |
| 25 | modules-right = [ # "custom/worktime" "custom/worktime-today" | 25 | modules-right = [ # "custom/worktime" "custom/worktime-today" |
| 26 | "custom/weather" | 26 | "custom/weather" |
| 27 | # "custom/keymap" | 27 | "custom/keymap" |
| 28 | "privacy" "tray" "wireplumber" "backlight" "battery" "idle_inhibitor" "clock" ]; | 28 | "privacy" "tray" "wireplumber" "backlight" "battery" "idle_inhibitor" "clock" ]; |
| 29 | 29 | ||
| 30 | "custom/weather" = { | 30 | "custom/weather" = { |
| @@ -41,8 +41,6 @@ | |||
| 41 | exec = pkgs.writers.writePython3 "keymap" {} '' | 41 | exec = pkgs.writers.writePython3 "keymap" {} '' |
| 42 | import os | 42 | import os |
| 43 | import socket | 43 | import socket |
| 44 | import re | ||
| 45 | import subprocess | ||
| 46 | import json | 44 | import json |
| 47 | 45 | ||
| 48 | 46 | ||
| @@ -55,20 +53,20 @@ | |||
| 55 | print(json.dumps({'text': short, 'tooltip': keymap}, separators=(',', ':')), flush=True) # noqa: E501 | 53 | print(json.dumps({'text': short, 'tooltip': keymap}, separators=(',', ':')), flush=True) # noqa: E501 |
| 56 | 54 | ||
| 57 | 55 | ||
| 58 | r = subprocess.run(["hyprctl", "devices", "-j"], check=True, stdout=subprocess.PIPE, text=True) # noqa: E501 | 56 | keyboard_layouts = [] |
| 59 | for keyboard in json.loads(r.stdout)['keyboards']: | ||
| 60 | if keyboard['name'] != "at-translated-set-2-keyboard": | ||
| 61 | continue | ||
| 62 | output(keyboard['active_keymap']) | ||
| 63 | 57 | ||
| 64 | sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) | 58 | sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) |
| 65 | sock.connect(os.environ["XDG_RUNTIME_DIR"] + "/hypr/" + os.environ["HYPRLAND_INSTANCE_SIGNATURE"] + "/.socket2.sock") # noqa: E501 | 59 | sock.connect(os.environ["NIRI_SOCKET"]) |
| 66 | expected = re.compile(r'^activelayout>>at-translated-set-2-keyboard,(?P<keymap>.+)$') # noqa: E501 | 60 | sock.send(b"\"EventStream\"\n") |
| 67 | for line in sock.makefile(buffering=1, encoding='utf-8'): | 61 | for line in sock.makefile(buffering=1, encoding='utf-8'): |
| 68 | if match := expected.match(line): | 62 | if line_json := json.loads(line): |
| 69 | output(match.group("keymap")) | 63 | if "KeyboardLayoutsChanged" in line_json: |
| 64 | keyboard_layouts = line_json["KeyboardLayoutsChanged"]["keyboard_layouts"]["names"] # noqa: E501 | ||
| 65 | output(keyboard_layouts[line_json["KeyboardLayoutsChanged"]["keyboard_layouts"]["current_idx"]]) # noqa: E501 | ||
| 66 | if "KeyboardLayoutSwitched" in line_json: | ||
| 67 | output(keyboard_layouts[line_json["KeyboardLayoutSwitched"]["idx"]]) # noqa: E501 | ||
| 70 | ''; | 68 | ''; |
| 71 | on-click = "hyprctl switchxkblayout at-translated-set-2-keyboard next"; | 69 | on-click = "niri msg action switch-layout next"; |
| 72 | }; | 70 | }; |
| 73 | "custom/worktime" = { | 71 | "custom/worktime" = { |
| 74 | interval = 60; | 72 | interval = 60; |
