Files
nixos/apps/hyprland/scripts/window-rules.nix
T

41 lines
1.2 KiB
Nix

{pkgs, ...}: let
hyprctl = "${pkgs.hyprland}/bin/hyprctl";
jq = "${pkgs.jq}/bin/jq";
socat = "${pkgs.socat}/bin/socat";
hypr-window-rules = pkgs.writeShellScriptBin "hypr-window-rules" ''
handle() {
local event="$1"
case "$event" in
windowtitlev2*)
local data="''${event#windowtitlev2>>}"
local addr="0x''${data%%,*}"
local title="''${data#*,}"
if echo "$title" | grep -qi "bitwarden"; then
local info
info=$(${hyprctl} clients -j | ${jq} -r --arg addr "$addr" \
'.[] | select(.address == $addr) | "\(.class)|\(.floating)"')
local class="''${info%|*}"
local floating="''${info#*|}"
if [[ "$class" == "firefox" && "$floating" == "false" ]]; then
${hyprctl} dispatch togglefloating "address:$addr"
fi
fi
;;
esac
}
${socat} - \
"UNIX-CONNECT:$XDG_RUNTIME_DIR/hypr/$HYPRLAND_INSTANCE_SIGNATURE/.socket2.sock" \
| while IFS= read -r line; do handle "$line"; done
'';
in {
home.packages = [hypr-window-rules];
wayland.windowManager.hyprland.settings.exec-once = [
"hypr-window-rules"
];
}