discord: added focus-window script to hyprland

This commit is contained in:
Tigor Hutasuhut 2024-10-20 16:34:59 +07:00
parent 688981cb16
commit 33580a8bff
3 changed files with 27 additions and 3 deletions

View file

@ -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";
};
};
};

View file

@ -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";
};
};
}

View file

@ -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
''