From d0900f1cf89cfe2cee407cb47fb9450dbba171fa Mon Sep 17 00:00:00 2001 From: Simon Bruder Date: Sat, 17 Jul 2021 16:13:45 +0200 Subject: [PATCH] waybar: Add calendar --- users/simon/modules/sway/waybar.css | 5 ++++ users/simon/modules/sway/waybar.nix | 36 +++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/users/simon/modules/sway/waybar.css b/users/simon/modules/sway/waybar.css index 1c37e13..16a8e19 100644 --- a/users/simon/modules/sway/waybar.css +++ b/users/simon/modules/sway/waybar.css @@ -166,3 +166,8 @@ window#waybar { animation-iteration-count: infinite; animation-direction: alternate; } + +#custom-calendar.active { + background-color: @base3@; + color: @base00@; +} diff --git a/users/simon/modules/sway/waybar.nix b/users/simon/modules/sway/waybar.nix index 8e0e249..39f535e 100644 --- a/users/simon/modules/sway/waybar.nix +++ b/users/simon/modules/sway/waybar.nix @@ -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 = "{:%Y %B}\n{calendar}"; }; + "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", "{name}, {date}"]).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;