From 8507fad62ca2f06e40f4e849bb8edaa6456c87ef Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Fri, 24 Jan 2025 13:03:27 +0100 Subject: ... --- accounts/gkleen@sif/niri/mako.nix | 56 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) (limited to 'accounts/gkleen@sif/niri/mako.nix') diff --git a/accounts/gkleen@sif/niri/mako.nix b/accounts/gkleen@sif/niri/mako.nix index 901ed022..e06d3b3a 100644 --- a/accounts/gkleen@sif/niri/mako.nix +++ b/accounts/gkleen@sif/niri/mako.nix @@ -47,5 +47,61 @@ Restart = "always"; }; }; + + systemd.user.services.mako-follows-focus = { + Unit = { + BindsTo = [ "niri.service" "mako.service" ]; + After = [ "niri.service" "mako.service" ]; + }; + Service = { + Type = "simple"; + Restart = "always"; + ExecStart = pkgs.writers.writePython3 "mako-follows-focus" { + libraries = with pkgs.python3Packages; []; + } '' + import os + import socket + import json + import subprocess + + + current_output = None + workspaces = [] + + + def output_changed(new_output): + global current_output + + if current_output == new_output: + return + + current_output = new_output + subprocess.run(["makoctl", "reload"]) + + + sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) + sock.connect(os.environ["NIRI_SOCKET"]) + sock.send(b"\"EventStream\"\n") + for line in sock.makefile(buffering=1, encoding='utf-8'): + if line_json := json.loads(line): + if "WorkspacesChanged" in line_json: + workspaces = line_json["WorkspacesChanged"]["workspaces"] + for workspace in workspaces: + if not workspace["is_focused"]: + continue + output_changed(workspace["output"]) + break + if "WorkspaceActivated" in line_json and line_json["WorkspaceActivated"]["focused"]: # noqa: E501 + for workspace in workspaces: + if not workspace["id"] == line_json["WorkspaceActivated"]["id"]: # noqa: E501 + continue + output_changed(workspace["output"]) + break + ''; + }; + Install = { + WantedBy = [ "mako.service" ]; + }; + }; }; } -- cgit v1.2.3