From 2d76b1228ba1867a4aca49384d2f5eed806b703a Mon Sep 17 00:00:00 2001 From: Filippo Berto Date: Wed, 4 Jan 2023 12:18:31 +0100 Subject: [PATCH] Notification handler and better powermenu --- hm_modules/polybar.nix | 38 ++++++++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/hm_modules/polybar.nix b/hm_modules/polybar.nix index d472189..54a70c9 100644 --- a/hm_modules/polybar.nix +++ b/hm_modules/polybar.nix @@ -9,6 +9,20 @@ let pgrep = "${pkgs.procps}/bin/pgrep"; pkill = "${pkgs.procps}/bin/pkill"; playerCtl = "${pkgs.playerctl}/bin/playerctl"; + dunstctl = "${pkgs.dunst}/bin/dunstctl"; + notificationStatus = pkgs.writeShellScript "notificationStatus" '' + PATH=$PATH:"${lib.makeBinPath [ pkgs.dbus ]}" + if [[ `${dunstctl} is-paused` == "true" ]]; then echo ; else echo ; fi + ''; + notificationToggle = pkgs.writeShellScript "notificationToggle" '' + PATH=$PATH:"${lib.makeBinPath [ pkgs.dbus ]}" + ${dunstctl} set-paused toggle + ''; + notificationHistory = pkgs.writeShellScript "notificationToggle" '' + PATH=$PATH:"${lib.makeBinPath [ pkgs.dbus ]}" + ${dunstctl} set-paused false + for i in {1..10}; do ${dunstctl} history-pop; done + ''; playerStatus = "${playerCtl} -f '{{emoji(status)}} {{title}} - {{artist}}' metadata | ${head} -c 60"; confirm_command = { cmd, title ? null, text ? null, image ? null }: @@ -92,6 +106,7 @@ let "Noto Sans CJK CN:size=${toString pkgs.rice.font.monospace.size};0" "Noto Sans CJK HK:size=${toString pkgs.rice.font.monospace.size};0" ]; + enable-ipc = true; wm-restack = "bspwm"; }; @@ -125,8 +140,7 @@ in "bar/primary" = recursiveUpdate commonBar { modules-left = "bspwm"; # modules-center = - modules-right = "player pulseaudio temperature cpu memory battery date powermenu"; - enable-ipc = true; + modules-right = "player pulseaudio temperature cpu memory battery notifications powermenu date"; tray = { position = "right"; padding = 1; @@ -136,9 +150,7 @@ in "bar/secondary" = recursiveUpdate commonBar { modules-left = "bspwm"; # modules-center = - modules-right = - "player pulseaudio temperature cpu memory battery date powermenu"; - enable-ipc = true; + modules-right = "player pulseaudio temperature cpu memory battery notifications powermenu date"; }; "module/battery" = { @@ -286,14 +298,10 @@ in "module/powermenu" = { type = "custom/menu"; expand.right = true; - format = { - spacing = 1; - suffix = " "; - }; + format.spacing = 1; label = { open = recursiveUpdate colors.normal { text = "●"; }; close = recursiveUpdate colors.normal { text = ""; }; - # separator = { text = "|"; }; }; menu = [ [ @@ -333,6 +341,16 @@ in ]; }; + "module/notifications" = { + type = "custom/script"; + format = recursiveUpdate colors.normal { padding = 0; }; + exec = "${notificationStatus}"; + click.left = "${notificationToggle}"; + click.right = "${notificationHistory}"; + interval = 0.5; + # tail = 1; + }; + "module/player" = { type = "custom/script"; format = recursiveUpdate colors.normal { padding = 0; };