diff options
Diffstat (limited to 'accounts/gkleen@sif/niri/mako.nix')
| -rw-r--r-- | accounts/gkleen@sif/niri/mako.nix | 118 |
1 files changed, 90 insertions, 28 deletions
diff --git a/accounts/gkleen@sif/niri/mako.nix b/accounts/gkleen@sif/niri/mako.nix index 8abf14d8..3d246d96 100644 --- a/accounts/gkleen@sif/niri/mako.nix +++ b/accounts/gkleen@sif/niri/mako.nix | |||
| @@ -1,34 +1,40 @@ | |||
| 1 | { config, lib, ... }: | 1 | { config, lib, pkgs, ... }: |
| 2 | { | 2 | { |
| 3 | config = { | 3 | config = lib.mkIf false { |
| 4 | services.mako = { | 4 | services.mako = { |
| 5 | enable = true; | 5 | enable = true; |
| 6 | font = "Fira Sans 10"; | 6 | settings = { |
| 7 | format = "<i>%s</i>\\n%b"; | 7 | font = "Fira Sans 10"; |
| 8 | margin = "2"; | 8 | format = "<i>%s</i>\\n%b"; |
| 9 | maxVisible = -1; | 9 | margin = "2"; |
| 10 | backgroundColor = "#000000dd"; | 10 | max-visible = -1; |
| 11 | progressColor = "source #223544ff"; | 11 | background-color = "#000000dd"; |
| 12 | width = 384; | 12 | progress-color = "source #223544ff"; |
| 13 | extraConfig = '' | 13 | width = 384; |
| 14 | outer-margin=1 | 14 | outer-margin = 1; |
| 15 | max-history=100 | 15 | max-history = 100; |
| 16 | 16 | max-icon-size = 48; | |
| 17 | [grouped] | 17 | |
| 18 | format=<b>(%g)</b> <i>%s</i>\n%b | 18 | grouped.format = "<b>(%g)</b> <i>%s</i>\\n%b"; |
| 19 | 19 | "urgency=low".text-color = "#999999ff"; | |
| 20 | [urgency=low] | 20 | "urgency=critical".background-color = "#900000dd"; |
| 21 | text-color=#999999ff | 21 | "app-name=Element".group-by = "summary"; |
| 22 | 22 | "app-name=poweralertd" = { | |
| 23 | [urgency=critical] | 23 | history = false; |
| 24 | background-color=#900000dd | 24 | ignore-timeout = true; |
| 25 | 25 | default-timeout = 2000; | |
| 26 | [app-name=Element] | 26 | }; |
| 27 | group-by=summary | 27 | "app-name=worktime".history = false; |
| 28 | 28 | "mode=silent".invisible = true; | |
| 29 | [mode=silent] | 29 | }; |
| 30 | invisible=1 | 30 | package = pkgs.symlinkJoin { |
| 31 | ''; | 31 | name = "${pkgs.mako.name}-wrapped"; |
| 32 | paths = with pkgs; [ mako ]; | ||
| 33 | inherit (pkgs.mako) meta; | ||
| 34 | postBuild = '' | ||
| 35 | rm -r $out/share/dbus-1 | ||
| 36 | ''; | ||
| 37 | }; | ||
| 32 | }; | 38 | }; |
| 33 | systemd.user.services.mako = { | 39 | systemd.user.services.mako = { |
| 34 | Unit = { | 40 | Unit = { |
| @@ -46,5 +52,61 @@ | |||
| 46 | Restart = "always"; | 52 | Restart = "always"; |
| 47 | }; | 53 | }; |
| 48 | }; | 54 | }; |
| 55 | |||
| 56 | systemd.user.services.mako-follows-focus = { | ||
| 57 | Unit = { | ||
| 58 | BindsTo = [ "niri.service" "mako.service" ]; | ||
| 59 | After = [ "niri.service" "mako.service" ]; | ||
| 60 | }; | ||
| 61 | Service = { | ||
| 62 | Type = "simple"; | ||
| 63 | Restart = "always"; | ||
| 64 | ExecStart = pkgs.writers.writePython3 "mako-follows-focus" { | ||
| 65 | libraries = with pkgs.python3Packages; []; | ||
| 66 | } '' | ||
| 67 | import os | ||
| 68 | import socket | ||
| 69 | import json | ||
| 70 | import subprocess | ||
| 71 | |||
| 72 | |||
| 73 | current_output = None | ||
| 74 | workspaces = [] | ||
| 75 | |||
| 76 | |||
| 77 | def output_changed(new_output): | ||
| 78 | global current_output | ||
| 79 | |||
| 80 | if current_output == new_output: | ||
| 81 | return | ||
| 82 | |||
| 83 | current_output = new_output | ||
| 84 | subprocess.run(["makoctl", "reload"]) | ||
| 85 | |||
| 86 | |||
| 87 | sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) | ||
| 88 | sock.connect(os.environ["NIRI_SOCKET"]) | ||
| 89 | sock.send(b"\"EventStream\"\n") | ||
| 90 | for line in sock.makefile(buffering=1, encoding='utf-8'): | ||
| 91 | if line_json := json.loads(line): | ||
| 92 | if "WorkspacesChanged" in line_json: | ||
| 93 | workspaces = line_json["WorkspacesChanged"]["workspaces"] | ||
| 94 | for workspace in workspaces: | ||
| 95 | if not workspace["is_focused"]: | ||
| 96 | continue | ||
| 97 | output_changed(workspace["output"]) | ||
| 98 | break | ||
| 99 | if "WorkspaceActivated" in line_json and line_json["WorkspaceActivated"]["focused"]: # noqa: E501 | ||
| 100 | for workspace in workspaces: | ||
| 101 | if not workspace["id"] == line_json["WorkspaceActivated"]["id"]: # noqa: E501 | ||
| 102 | continue | ||
| 103 | output_changed(workspace["output"]) | ||
| 104 | break | ||
| 105 | ''; | ||
| 106 | }; | ||
| 107 | Install = { | ||
| 108 | WantedBy = [ "mako.service" ]; | ||
| 109 | }; | ||
| 110 | }; | ||
| 49 | }; | 111 | }; |
| 50 | } | 112 | } |
