waybar: Add calendar

This commit is contained in:
Simon Bruder 2021-07-17 16:13:45 +02:00
parent faf9a044fd
commit d0900f1cf8
Signed by: simon
GPG key ID: 8D3C82F9F309F8EC
2 changed files with 41 additions and 0 deletions

View file

@ -166,3 +166,8 @@ window#waybar {
animation-iteration-count: infinite;
animation-direction: alternate;
}
#custom-calendar.active {
background-color: @base3@;
color: @base00@;
}

View file

@ -49,6 +49,7 @@ in
"temperature"
"battery"
"clock"
"custom/calendar"
];
"sway/workspaces" = {
@ -223,6 +224,41 @@ in
format-alt = "{:%Y-%m-%d (%a)}";
tooltip-format = "<big>{:%Y %B}</big>\n<tt><small>{calendar}</small></tt>";
};
"custom/calendar" = {
interval = 300;
exec = pkgs.writeScript "calendar" ''
#!${pkgs.python3}/bin/python3
import json
import subprocess
def khal(args):
completed = subprocess.run(["${pkgs.khal}/bin/khal"] + args, capture_output=True)
assert completed.returncode == 0
return completed.stdout.decode("utf-8")
events_today = khal(["list", "today", "today", "-df", ""]).rstrip().split("\n")
events_2d = khal(["list", "today", "tomorrow", "-df", "<b>{name}, {date}</b>"]).rstrip()
if len(events_today) == 0:
text = " "
else:
text = f"{len(events_today)} "
print(
json.dumps(
{
"class": "active" if len(events_today) > 0 else "",
"text": text,
"tooltip": events_2d,
}
)
)
'';
return-type = "json";
format = "{}";
};
};
xdg.configFile."waybar/style.css".source = pkgs.substituteAll ({
src = ./waybar.css;