From 938e47b3b0d888a89e18dbaa40410ef96518a69d Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Tue, 28 Jan 2025 21:11:46 +0100 Subject: ... --- accounts/gkleen@sif/niri/waybar.nix | 4 +--- overlays/worktime/worktime/__main__.py | 23 +++++++++++++++++++---- 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 { text = f"{icon}" # noqa: E501 if is_silent: text = f"{text}" - print(json.dumps({'text': text}, separators=(',', ':')), flush=True) # noqa: E501 + print(json.dumps({'text': text, 'tooltip': ', '.join(modes)}, separators=(',', ':')), flush=True) # noqa: E501 async def on_properties_changed(interface_name, changed_properties, invalidated_properties): # noqa: E501 if "Modes" not in invalidated_properties: @@ -124,13 +124,11 @@ in { interval = 60; exec = "${lib.getExe pkgs.worktime} time --waybar"; return-type = "json"; - tooltip = false; }; "custom/worktime-today" = { interval = 60; exec = "${lib.getExe pkgs.worktime} today --waybar"; return-type = "json"; - tooltip = false; }; "niri/workspaces" = { 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): return ', '.join(map(lambda group: ','.join(map(format_group, group)), groups)) +def tooltip_timedelta(td): + if td < timedelta(seconds = 0): + return "-" + tooltip_timedelta(-td) + mm, ss = divmod(td.total_seconds(), 60) + hh, mm = divmod(mm, 60) + return "%d:%02d:%02d" % (hh, mm, ss) + def worktime(pull_forward_cutoff, waybar, **args): worktime = Worktime(**args) @@ -564,7 +571,8 @@ def worktime(pull_forward_cutoff, waybar, **args): return f"({difference_string})" out_class = "running" if worktime.running_entry else "stopped" - if worktime.time_pulled_forward >= pull_forward_cutoff: + tooltip = tooltip_timedelta(worktime.time_to_work - worktime.time_worked) + if worktime.time_pulled_forward >= min(pull_forward_cutoff, timedelta(seconds = 1)): worktime_no_pulled_forward = deepcopy(worktime) worktime_no_pulled_forward.time_to_work -= worktime_no_pulled_forward.time_pulled_forward worktime_no_pulled_forward.time_pulled_forward = timedelta() @@ -572,12 +580,16 @@ def worktime(pull_forward_cutoff, waybar, **args): difference_string = format_worktime(worktime) difference_string_no_pulled_forward = format_worktime(worktime_no_pulled_forward) - out_text = f"{difference_string_no_pulled_forward}…{difference_string}" + tooltip = tooltip_timedelta(worktime_no_pulled_forward.time_to_work - worktime_no_pulled_forward.time_worked) + "…" + tooltip + if worktime.time_pulled_forward >= pull_forward_cutoff: + out_text = f"{difference_string_no_pulled_forward}…{difference_string}" + else: + out_text = format_worktime(worktime) else: out_text = format_worktime(worktime) if waybar: - json.dump({"text": out_text, "class": out_class}, stdout) + json.dump({"text": out_text, "class": out_class, "tooltip": tooltip}, stdout) else: print(out_text) @@ -593,6 +605,7 @@ def time_worked(now, waybar, **args): out_text = None out_class = "stopped" + tooltip = tooltip_timedelta(worked) if args['do_round']: total_minutes_difference = 5 * ceil(worked / timedelta(minutes = 5)) (hours_difference, minutes_difference) = divmod(abs(total_minutes_difference), 60) @@ -611,12 +624,14 @@ def time_worked(now, waybar, **args): difference = target_time - worked clockout_difference = 5 * ceil(difference / timedelta(minutes = 5)) clockout_time = now.now + difference + exact_clockout_time = clockout_time clockout_time += (5 - clockout_time.minute % 5) * timedelta(minutes = 1) clockout_time = clockout_time.replace(second = 0, microsecond = 0) if now.running_entry and clockout_time and clockout_difference >= 0: out_class = "running" out_text = f"{difference_string}/{clockout_time:%H:%M}" + tooltip = f"{tooltip_timedelta(worked)}/{exact_clockout_time:%H:%M}" else: if now.running_entry: out_class = "over" @@ -625,7 +640,7 @@ def time_worked(now, waybar, **args): out_text = str(worked) if waybar: - json.dump({"text": out_text, "class": out_class}, stdout) + json.dump({"text": out_text, "class": out_class, "tooltip": tooltip}, stdout) else: print(out_text) -- cgit v1.2.3