From 33580a8bffee44054150fa2a7b99cccd4a950fa8 Mon Sep 17 00:00:00 2001 From: Tigor Hutasuhut Date: Sun, 20 Oct 2024 16:34:59 +0700 Subject: [PATCH] discord: added focus-window script to hyprland --- home/modules/hyprland/swaync.nix | 3 +-- home/programs/discord.nix | 13 ++++++++++++- scripts/hyprland/focus-window.nix | 14 ++++++++++++++ 3 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 scripts/hyprland/focus-window.nix diff --git a/home/modules/hyprland/swaync.nix b/home/modules/hyprland/swaync.nix index 1870e7b..e118f2b 100644 --- a/home/modules/hyprland/swaync.nix +++ b/home/modules/hyprland/swaync.nix @@ -19,10 +19,9 @@ in timeout-low = 3; scripts = { - _99-play-notification-sound = { + _98-play-notification-sound-normal = { exec = ''${pkgs.sox}/bin/play --volume 0.5 ${./gran_turismo_menu_sound_effect.mp3}''; app-name = "^(?!discord|TelegramDesktop|Slack|slack|Signal|Element).*$"; - urgency = "Normal"; }; }; }; diff --git a/home/programs/discord.nix b/home/programs/discord.nix index ea8a005..25f763e 100644 --- a/home/programs/discord.nix +++ b/home/programs/discord.nix @@ -1,6 +1,7 @@ { config, pkgs, lib, ... }: -with lib; let + inherit (lib) mkIf; + inherit (lib.meta) getExe; cfg = config.profile.discord; in { @@ -18,5 +19,15 @@ in wayland.windowManager.hyprland.settings.exec-once = lib.mkIf cfg.autostart [ "sleep 10; until ${pkgs.unixtools.ping}/bin/ping -c 1 discord.com; do sleep 1; done; vesktop" ]; + + services.swaync.settings.scripts._10-discord = + let + script = pkgs.callPackage ../../scripts/hyprland/focus-window.nix { }; + in + { + app-name = "discord"; + exec = "${getExe script}"; + run-on = "action"; + }; }; } diff --git a/scripts/hyprland/focus-window.nix b/scripts/hyprland/focus-window.nix new file mode 100644 index 0000000..2cfb1b5 --- /dev/null +++ b/scripts/hyprland/focus-window.nix @@ -0,0 +1,14 @@ +{ pkgs, ... }: +let + hyprctl = "${pkgs.hyprland}/bin/hyprctl"; + gojq = "${pkgs.gojq}/bin/gojq"; +in +pkgs.writeShellScriptBin "focus-window.sh" /*sh*/ '' + appname="$SWAYNC_APP_NAME" + state="$(${hyprctl} -j clients)" + window="$(echo "$state" | ${gojq} -r --arg APP "$appname" '.[] | select(.class == $APP) | .address')" + + if [[ "$window" != "" ]]; then + ${hyprctl} dispatch focuswindow address:"$window" + fi +''