summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--accounts/gkleen@sif/niri/waybar.nix4
-rwxr-xr-xoverlays/worktime/worktime/__main__.py23
2 files changed, 20 insertions, 7 deletions
diff --git a/accounts/gkleen@sif/niri/waybar.nix b/accounts/gkleen@sif/niri/waybar.nix
index 56a1b648..3f1f8119 100644
--- a/accounts/gkleen@sif/niri/waybar.nix
+++ b/accounts/gkleen@sif/niri/waybar.nix
@@ -61,7 +61,7 @@ in {
61 text = f"<span font=\"Symbols Nerd Font Mono\" size=\"90%\">{icon}</span>" # noqa: E501 61 text = f"<span font=\"Symbols Nerd Font Mono\" size=\"90%\">{icon}</span>" # noqa: E501
62 if is_silent: 62 if is_silent:
63 text = f"<span color=\"#ffffff\">{text}</span>" 63 text = f"<span color=\"#ffffff\">{text}</span>"
64 print(json.dumps({'text': text}, separators=(',', ':')), flush=True) # noqa: E501 64 print(json.dumps({'text': text, 'tooltip': ', '.join(modes)}, separators=(',', ':')), flush=True) # noqa: E501
65 65
66 async def on_properties_changed(interface_name, changed_properties, invalidated_properties): # noqa: E501 66 async def on_properties_changed(interface_name, changed_properties, invalidated_properties): # noqa: E501
67 if "Modes" not in invalidated_properties: 67 if "Modes" not in invalidated_properties:
@@ -124,13 +124,11 @@ in {
124 interval = 60; 124 interval = 60;
125 exec = "${lib.getExe pkgs.worktime} time --waybar"; 125 exec = "${lib.getExe pkgs.worktime} time --waybar";
126 return-type = "json"; 126 return-type = "json";
127 tooltip = false;
128 }; 127 };
129 "custom/worktime-today" = { 128 "custom/worktime-today" = {
130 interval = 60; 129 interval = 60;
131 exec = "${lib.getExe pkgs.worktime} today --waybar"; 130 exec = "${lib.getExe pkgs.worktime} today --waybar";
132 return-type = "json"; 131 return-type = "json";
133 tooltip = false;
134 }; 132 };
135 "niri/workspaces" = { 133 "niri/workspaces" = {
136 ignore = ["eff" "pwctl" "kpxc" "bmgr" "edit" "term"]; 134 ignore = ["eff" "pwctl" "kpxc" "bmgr" "edit" "term"];
diff --git a/overlays/worktime/worktime/__main__.py b/overlays/worktime/worktime/__main__.py
index 9b556850..9335afdc 100755
--- a/overlays/worktime/worktime/__main__.py
+++ b/overlays/worktime/worktime/__main__.py
@@ -519,6 +519,13 @@ def format_days(worktime, days, date_format=None):
519 return ', '.join(map(lambda group: ','.join(map(format_group, group)), groups)) 519 return ', '.join(map(lambda group: ','.join(map(format_group, group)), groups))
520 520
521 521
522def tooltip_timedelta(td):
523 if td < timedelta(seconds = 0):
524 return "-" + tooltip_timedelta(-td)
525 mm, ss = divmod(td.total_seconds(), 60)
526 hh, mm = divmod(mm, 60)
527 return "%d:%02d:%02d" % (hh, mm, ss)
528
522def worktime(pull_forward_cutoff, waybar, **args): 529def worktime(pull_forward_cutoff, waybar, **args):
523 worktime = Worktime(**args) 530 worktime = Worktime(**args)
524 531
@@ -564,7 +571,8 @@ def worktime(pull_forward_cutoff, waybar, **args):
564 return f"({difference_string})" 571 return f"({difference_string})"
565 572
566 out_class = "running" if worktime.running_entry else "stopped" 573 out_class = "running" if worktime.running_entry else "stopped"
567 if worktime.time_pulled_forward >= pull_forward_cutoff: 574 tooltip = tooltip_timedelta(worktime.time_to_work - worktime.time_worked)
575 if worktime.time_pulled_forward >= min(pull_forward_cutoff, timedelta(seconds = 1)):
568 worktime_no_pulled_forward = deepcopy(worktime) 576 worktime_no_pulled_forward = deepcopy(worktime)
569 worktime_no_pulled_forward.time_to_work -= worktime_no_pulled_forward.time_pulled_forward 577 worktime_no_pulled_forward.time_to_work -= worktime_no_pulled_forward.time_pulled_forward
570 worktime_no_pulled_forward.time_pulled_forward = timedelta() 578 worktime_no_pulled_forward.time_pulled_forward = timedelta()
@@ -572,12 +580,16 @@ def worktime(pull_forward_cutoff, waybar, **args):
572 difference_string = format_worktime(worktime) 580 difference_string = format_worktime(worktime)
573 difference_string_no_pulled_forward = format_worktime(worktime_no_pulled_forward) 581 difference_string_no_pulled_forward = format_worktime(worktime_no_pulled_forward)
574 582
575 out_text = f"{difference_string_no_pulled_forward}…{difference_string}" 583 tooltip = tooltip_timedelta(worktime_no_pulled_forward.time_to_work - worktime_no_pulled_forward.time_worked) + "…" + tooltip
584 if worktime.time_pulled_forward >= pull_forward_cutoff:
585 out_text = f"{difference_string_no_pulled_forward}…{difference_string}"
586 else:
587 out_text = format_worktime(worktime)
576 else: 588 else:
577 out_text = format_worktime(worktime) 589 out_text = format_worktime(worktime)
578 590
579 if waybar: 591 if waybar:
580 json.dump({"text": out_text, "class": out_class}, stdout) 592 json.dump({"text": out_text, "class": out_class, "tooltip": tooltip}, stdout)
581 else: 593 else:
582 print(out_text) 594 print(out_text)
583 595
@@ -593,6 +605,7 @@ def time_worked(now, waybar, **args):
593 605
594 out_text = None 606 out_text = None
595 out_class = "stopped" 607 out_class = "stopped"
608 tooltip = tooltip_timedelta(worked)
596 if args['do_round']: 609 if args['do_round']:
597 total_minutes_difference = 5 * ceil(worked / timedelta(minutes = 5)) 610 total_minutes_difference = 5 * ceil(worked / timedelta(minutes = 5))
598 (hours_difference, minutes_difference) = divmod(abs(total_minutes_difference), 60) 611 (hours_difference, minutes_difference) = divmod(abs(total_minutes_difference), 60)
@@ -611,12 +624,14 @@ def time_worked(now, waybar, **args):
611 difference = target_time - worked 624 difference = target_time - worked
612 clockout_difference = 5 * ceil(difference / timedelta(minutes = 5)) 625 clockout_difference = 5 * ceil(difference / timedelta(minutes = 5))
613 clockout_time = now.now + difference 626 clockout_time = now.now + difference
627 exact_clockout_time = clockout_time
614 clockout_time += (5 - clockout_time.minute % 5) * timedelta(minutes = 1) 628 clockout_time += (5 - clockout_time.minute % 5) * timedelta(minutes = 1)
615 clockout_time = clockout_time.replace(second = 0, microsecond = 0) 629 clockout_time = clockout_time.replace(second = 0, microsecond = 0)
616 630
617 if now.running_entry and clockout_time and clockout_difference >= 0: 631 if now.running_entry and clockout_time and clockout_difference >= 0:
618 out_class = "running" 632 out_class = "running"
619 out_text = f"{difference_string}/{clockout_time:%H:%M}" 633 out_text = f"{difference_string}/{clockout_time:%H:%M}"
634 tooltip = f"{tooltip_timedelta(worked)}/{exact_clockout_time:%H:%M}"
620 else: 635 else:
621 if now.running_entry: 636 if now.running_entry:
622 out_class = "over" 637 out_class = "over"
@@ -625,7 +640,7 @@ def time_worked(now, waybar, **args):
625 out_text = str(worked) 640 out_text = str(worked)
626 641
627 if waybar: 642 if waybar:
628 json.dump({"text": out_text, "class": out_class}, stdout) 643 json.dump({"text": out_text, "class": out_class, "tooltip": tooltip}, stdout)
629 else: 644 else:
630 print(out_text) 645 print(out_text)
631 646