mako: Implement notification inhibition

Fixes #43.
This commit is contained in:
Simon Bruder 2021-03-07 20:25:15 +01:00
parent 442297ec85
commit d239f2ad5e
Signed by: simon
GPG key ID: 8D3C82F9F309F8EC
3 changed files with 55 additions and 0 deletions

View file

@ -28,4 +28,15 @@ in
})
];
});
# TODO: Remove patch once mako > 1.4.1 is released and in nixpkgs
mako = super.mako.overrideAttrs (o: o // {
patches = [
# Adds makoctl set
(super.fetchpatch {
url = "https://github.com/emersion/mako/commit/782ef66b04d5d927fe19254be175e0b5ddff343f.patch";
sha256 = "1qjaxhf11fyysmi9l8vwrz2vag3lcbllx8y8v2fgg3p52a7cwdjs";
})
];
});
}

View file

@ -151,3 +151,8 @@ window#waybar {
#tray {
padding: 0 5px;
}
#custom-notification_inhibitor.active {
background-color: @base3@;
color: @base03@;
}

View file

@ -22,6 +22,8 @@ let
wallpaper = if nixosConfig.sbruder.unfree.allowAssets then wallpaperUnfree else wallpaperFree;
cfg = config.wayland.windowManager.sway.config;
makoInhibitStateFile = "${config.xdg.dataHome}/mako/inhibit-state";
in
lib.mkIf nixosConfig.sbruder.gui.enable {
wayland.windowManager.sway = {
@ -319,6 +321,7 @@ lib.mkIf nixosConfig.sbruder.gui.enable {
"tray"
"custom/redshift"
"idle_inhibitor"
"custom/notification_inhibitor"
"backlight"
"mpd"
"pulseaudio"
@ -359,6 +362,37 @@ lib.mkIf nixosConfig.sbruder.gui.enable {
deactivated = " ";
};
};
"custom/notification_inhibitor" = {
exec = pkgs.writeShellScript "notification-inhibitor-watch-state" ''
set -euo pipefail
(echo; ${pkgs.inotify-tools}/bin/inotifywait -m -e close_write ${lib.escapeShellArg makoInhibitStateFile} 2>/dev/null) \
| (while read line; do
if [ "$(cat ${lib.escapeShellArg makoInhibitStateFile})" = "1" ]; then
echo '{"alt": "active", "class": "active"}'
else
echo '{"alt": "inactive", "class": "inactive"}'
fi
done)
'';
return-type = "json";
format = "{icon}";
format-icons = {
active = "${lrm} ";
inactive = "${lrm} ";
};
tooltip = false;
on-click = pkgs.writeShellScript "toggle-notification-inhibit" ''
set -e
current_state="$(cat ${lib.escapeShellArg makoInhibitStateFile})"
if [ "$current_state" = "0" ]; then
${pkgs.mako}/bin/makoctl set invisible=true
echo 1 > ${lib.escapeShellArg makoInhibitStateFile}
else
${pkgs.mako}/bin/makoctl set invisible=false
echo 0 > ${lib.escapeShellArg makoInhibitStateFile}
fi
'';
};
backlight = {
format = "{percent}% {icon}";
format-icons = [ " " " " " " " " " " " " " " ];
@ -515,6 +549,11 @@ lib.mkIf nixosConfig.sbruder.gui.enable {
Install.WantedBy = [ "sway-session.target" ];
Service = {
ExecStartPre = toString (pkgs.writeShellScript "reset-mako-inhibit-state" ''
set -e
mkdir -p "$(dirname ${lib.escapeShellArg makoInhibitStateFile})"
echo 0 > ${lib.escapeShellArg makoInhibitStateFile}
'');
ExecStart = "${pkgs.mako}/bin/mako";
Restart = "on-failure";
};