[user/malte] Implement do-not-disturb mode

This commit is contained in:
Malte Tammena 2022-04-18 15:56:23 +02:00
parent 6c1e8ebb26
commit 64b5b51b01
4 changed files with 109 additions and 5 deletions

65
pkgs/do-not-disturb.nix Normal file
View file

@ -0,0 +1,65 @@
# Small script to toggle DO-NOT-DISTURB mode
# and make it integrate well with other applications
{pkgs, ...}:
pkgs.writeShellApplication {
name = "do-not-disturb";
runtimeInputs = with pkgs; [
coreutils
mako
systemd
];
text = ''
MAKO_DEFAULT_MODE=default
MAKO_SILENT_MODE=do-not-disturb
# Sanity checks
if [ -z "''${1+x}" ]; then
print_help
fi
if [ -z "''${XDG_RUNTIME_DIR+x}" ]; then
printf "XDG_RUNTIME_DIR undefined! Cannot connect to mako!\n"
exit 1
fi
state="$XDG_RUNTIME_DIR/do-not-disturb"
# Print usage information
function print_help() {
printf "Usage:\n"
printf " %s [ toggle | is-on | is-off | get-file ]\n" "$0"
exit 1
}
# Toggle the mode
function toggle() {
if [ -f "$state" ]; then
rm "$state"
else
touch "$state"
fi
}
# Update mako's mode to this scripts mode
function update-mako() {
if [ -f "$state" ]; then
makoctl set-mode $MAKO_SILENT_MODE
else
makoctl set-mode $MAKO_DEFAULT_MODE
fi
}
action=$1
if [ "$action" = "toggle" ]; then
toggle
update-mako
elif [ "$action" = "is-on" ]; then
[ -f "$state" ]
elif [ "$action" = "is-off" ]; then
[ ! -f "$state" ]
elif [ "$action" = "get-file" ]; then
printf "%s" "$state"
else
print_help
fi
'';
}

View file

@ -4,6 +4,7 @@
... ...
}: let }: let
col = config.colors; col = config.colors;
doNotDisturb = pkgs.callPackage ../../pkgs/do-not-disturb.nix {};
in { in {
programs.mako = { programs.mako = {
enable = true; enable = true;
@ -18,7 +19,7 @@ in {
width = 400; width = 400;
height = 500; height = 500;
format = '' format = ''
<span color='${col.dark2.hashRgb}'><i>%a</i></span>\n<b>%s</b> %b"''; <span color='${col.dark2.hashRgb}'><i>%a</i></span>\n<b>%s</b> %b'';
layer = "overlay"; layer = "overlay";
margin = "5"; margin = "5";
padding = "6"; padding = "6";
@ -44,6 +45,9 @@ in {
background-color=${col.light4.hashRgb} background-color=${col.light4.hashRgb}
format=... %h more format=... %h more
[mode=do-not-disturb]
invisible=1
[app-name=fish urgency=normal] [app-name=fish urgency=normal]
background-color=${col.brightGreen.hashRgb} background-color=${col.brightGreen.hashRgb}
format= <b>%s</b>\n%b format= <b>%s</b>\n%b
@ -74,5 +78,8 @@ in {
Install = {WantedBy = ["graphical-session.target"];}; Install = {WantedBy = ["graphical-session.target"];};
}; };
home.packages = [pkgs.hackNerdLigatures]; home.packages = [
pkgs.hackNerdLigatures
doNotDisturb
];
} }

View file

@ -21,6 +21,7 @@
slurp = "${pkgs.slurp}/bin/slurp -db '#000000AA' -c '${col.light1.hashRgb}' -w1"; slurp = "${pkgs.slurp}/bin/slurp -db '#000000AA' -c '${col.light1.hashRgb}' -w1";
fuser = "${pkgs.psmisc}/bin/fuser"; fuser = "${pkgs.psmisc}/bin/fuser";
alsa_rec = "alsa_output.pci-0000_00_1f.3-platform-skl_hda_dsp_generic.HiFi__hw_sofhdadsp__sink.monitor"; alsa_rec = "alsa_output.pci-0000_00_1f.3-platform-skl_hda_dsp_generic.HiFi__hw_sofhdadsp__sink.monitor";
doNotDisturb = pkgs.callPackage ../../pkgs/do-not-disturb.nix {};
screenshot-path = "/home/malte/Pictures/screenshots/screenshot.png"; screenshot-path = "/home/malte/Pictures/screenshots/screenshot.png";
screenshot-all = "${grim} ${screenshot-path} && ${wl-copy} < ${screenshot-path}"; screenshot-all = "${grim} ${screenshot-path} && ${wl-copy} < ${screenshot-path}";
@ -221,6 +222,8 @@ in {
"${mod}+Ctrl+Shift+w" = "mode window"; "${mod}+Ctrl+Shift+w" = "mode window";
# Screenlocking # Screenlocking
"XF86Favorites" = "exec swaylock"; "XF86Favorites" = "exec swaylock";
# Toggle DO-NOT-DISTURB mode
"${mod}+n" = "exec ${doNotDisturb}/bin/do-not-disturb toggle";
}; };
gaps = let gaps = let

View file

@ -40,6 +40,23 @@
}" | ${jq} --unbuffered --compact-output }" | ${jq} --unbuffered --compact-output
''; '';
doNotDisturbJson = pkgs.writeShellApplication {
name = "do-not-disturb-json";
runtimeInputs = [
(pkgs.callPackage ../../pkgs/do-not-disturb.nix {})
pkgs.coreutils
pkgs.jq
];
text = ''
state=$(do-not-disturb get-file)
if [ -f "$state" ]; then
printf "{ \"text\": \" \", \
\"tooltip\": \"DO NOT DISTURB!\" \
}" | jq --unbuffered --compact-output
fi
'';
};
new-mail = let new-mail = let
notmuch = "${pkgs.notmuch}/bin/notmuch"; notmuch = "${pkgs.notmuch}/bin/notmuch";
wc = "${pkgs.coreutils}/bin/wc"; wc = "${pkgs.coreutils}/bin/wc";
@ -96,7 +113,7 @@ in {
modules-left = ["sway/workspaces" "sway/mode" "sway/window"]; modules-left = ["sway/workspaces" "sway/mode" "sway/window"];
modules-center = ["clock#time" "custom/check-system" "clock#date"]; modules-center = ["clock#time" "custom/check-system" "clock#date"];
modules-right = ["custom/taskwarrior" "custom/new-mail" "network" "battery" "tray"]; modules-right = ["custom/do-not-disturb" "custom/taskwarrior" "custom/new-mail" "network" "battery" "tray"];
modules = { modules = {
"sway/workspaces" = { "sway/workspaces" = {
@ -123,6 +140,11 @@ in {
tooltip = false; tooltip = false;
}; };
"custom/do-not-disturb" = {
exec = "${doNotDisturbJson}/bin/do-not-disturb-json";
return-type = "json";
interval = 1;
};
"custom/taskwarrior" = { "custom/taskwarrior" = {
exec = "${task-activity}/bin/task-activity"; exec = "${task-activity}/bin/task-activity";
return-type = "json"; return-type = "json";
@ -254,14 +276,16 @@ in {
#battery, #battery,
#network, #network,
#mode, #mode,
#custom-taskwarrior #custom-taskwarrior,
#custom-new-mail #custom-do-not-disturb,
#custom-new-mail,
#custom-check-system { #custom-check-system {
padding: 0 10px; padding: 0 10px;
color: ${col.light2.hashRgb}; color: ${col.light2.hashRgb};
} }
#custom-taskwarrior, #custom-taskwarrior,
#custom-do-not-disturb,
#custom-new-mail { #custom-new-mail {
padding: 0px 10px 0px 13px; padding: 0px 10px 0px 13px;
margin-right: 10px; margin-right: 10px;
@ -271,6 +295,11 @@ in {
border-bottom: 3px solid ${(col.brightYellow.darker darkenBorder).hashRgb}; border-bottom: 3px solid ${(col.brightYellow.darker darkenBorder).hashRgb};
} }
#custom-do-not-disturb {
background-color: ${col.neutralGreen.hashRgb};
border-bottom: 3px solid ${(col.neutralGreen.darker darkenBorder).hashRgb};
}
#custom-check-system { #custom-check-system {
margin: 0 5px; margin: 0 5px;
padding: 0 10px 0 13px; padding: 0 10px 0 13px;