From d239f2ad5efc00622f059aa928cb12902ce2b304 Mon Sep 17 00:00:00 2001 From: Simon Bruder Date: Sun, 7 Mar 2021 20:25:15 +0100 Subject: [PATCH] mako: Implement notification inhibition Fixes #43. --- pkgs/default.nix | 11 +++++++++ users/simon/files/waybar/style.css | 5 ++++ users/simon/modules/sway.nix | 39 ++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+) diff --git a/pkgs/default.nix b/pkgs/default.nix index df75e64..b2704f0 100644 --- a/pkgs/default.nix +++ b/pkgs/default.nix @@ -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"; + }) + ]; + }); } diff --git a/users/simon/files/waybar/style.css b/users/simon/files/waybar/style.css index a60e9af..750085d 100644 --- a/users/simon/files/waybar/style.css +++ b/users/simon/files/waybar/style.css @@ -151,3 +151,8 @@ window#waybar { #tray { padding: 0 5px; } + +#custom-notification_inhibitor.active { + background-color: @base3@; + color: @base03@; +} diff --git a/users/simon/modules/sway.nix b/users/simon/modules/sway.nix index a60235e..20ed170 100644 --- a/users/simon/modules/sway.nix +++ b/users/simon/modules/sway.nix @@ -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"; };