Compare commits

..
2 Commits
Author SHA1 Message Date
tgrosinger 194029d713 End reading-mode breaks only on input
Breaks started from the menu in reading mode used to end on
their own once the due break's length passed, so work started
counting before the user was back. They now last until input,
which makes them identical to an ordinary idle_start, so the
reading_break event and its cap logic are gone.
2026-11-05 12:27:44 -08:00
tgrosinger 62266e366e Log idle_end in reading mode when the log is empty
After skip_long empties the log, reading mode dropped every
idle_end because none followed a break, so the timer never
got a start point and stayed frozen at full intervals.
2026-11-05 12:14:00 -08:00
3 changed files with 11 additions and 30 deletions

No files matched your search

+1 -1
View File
@@ -179,7 +179,7 @@ Right-click the break timer widget in Waybar to access the context menu:
- **Snooze**: Hide overdue breaks for 5 minutes (configurable). Does nothing if no break is due. Snoozing again restarts the 5 minutes, a break that comes due during the snooze also waits, and taking a break ends the snooze. The timers keep counting, so when the snooze ends the widget shows the true overdue amount. The icon changes to 💤 while snoozed. - **Snooze**: Hide overdue breaks for 5 minutes (configurable). Does nothing if no break is due. Snoozing again restarts the 5 minutes, a break that comes due during the snooze also waits, and taking a break ends the snooze. The timers keep counting, so when the snooze ends the widget shows the true overdue amount. The icon changes to 💤 while snoozed.
- **Toggle Reading Mode**: For reading or watching without touching the computer. While on: - **Toggle Reading Mode**: For reading or watching without touching the computer. While on:
- Hands-off time counts as work instead of a break - Hands-off time counts as work instead of a break
- Breaks only start from **Start Break**, and end on input or once the due break's length has passed - Breaks only start from **Start Break**, and end on input
- The widget icon changes to 📖 (via `format-icons`) - The widget icon changes to 📖 (via `format-icons`)
- **Skip Long Break**: Reset all timers (useful if you just returned from a break not tracked by the timer) - **Skip Long Break**: Reset all timers (useful if you just returned from a break not tracked by the timer)
- **Toggle Pause**: Pause or unpause the timer. While paused: - **Toggle Pause**: Pause or unpause the timer. While paused:
+6 -5
View File
@@ -8,7 +8,7 @@ qualifying break periods to keep log small.
In reading mode (a "reading" flag file next to the log), automatic idle is In reading mode (a "reading" flag file next to the log), automatic idle is
ignored so hands-off reading counts as work. Breaks are started from the menu ignored so hands-off reading counts as work. Breaks are started from the menu
with start-break and end on input or after the due break's length. with start-break and end on input.
""" """
import os import os
@@ -172,13 +172,14 @@ def is_paused(events: Events) -> bool:
def in_break(events: Events) -> bool: def in_break(events: Events) -> bool:
"""Whether the last idle-related event started a break""" """Whether the last idle-related event started a break. With none (e.g.
after skip_long) there is no work period yet, so idle_end must be logged."""
for _, event_type in reversed(events): for _, event_type in reversed(events):
if event_type in ("idle_start", "reading_break"): if event_type == "idle_start":
return True return True
if event_type == "idle_end": if event_type == "idle_end":
return False return False
return False return True
COMMANDS = ("idle_start", "idle_end", "sleep", "wake", "start-break", "snooze", COMMANDS = ("idle_start", "idle_end", "sleep", "wake", "start-break", "snooze",
@@ -224,7 +225,7 @@ def main():
elif not is_paused(events): # Don't log idle events when paused elif not is_paused(events): # Don't log idle events when paused
reading = reading_path.exists() reading = reading_path.exists()
if event_type == "start-break": if event_type == "start-break":
logged = "reading_break" if reading else "idle_start" logged = "idle_start"
elif event_type == "snooze": elif event_type == "snooze":
logged = "snoozed" logged = "snoozed"
elif event_type in ("sleep", "wake"): elif event_type in ("sleep", "wake"):
+4 -24
View File
@@ -157,7 +157,7 @@ def calculate_status(events: Events, config: Config) -> Status:
active_time_since_long_break = 0 active_time_since_long_break = 0
pause_events = [e for e in events if e[1] in ("paused", "unpaused")] pause_events = [e for e in events if e[1] in ("paused", "unpaused")]
idle_events = [e for e in events if e[1] in ("idle_start", "idle_end", "reading_break", "snoozed")] idle_events = [e for e in events if e[1] in ("idle_start", "idle_end", "snoozed")]
snooze_until = None snooze_until = None
# Helper to calculate paused time within a range # Helper to calculate paused time within a range
@@ -200,21 +200,11 @@ def calculate_status(events: Events, config: Config) -> Status:
snooze_until = None # Taking a break uses up the snooze snooze_until = None # Taking a break uses up the snooze
# Replay the log. Exactly one of active_start / idle_start_time is set once # Replay the log. Exactly one of active_start / idle_start_time is set once
# the first event is seen. idle_cap is when a reading-mode break ends on # the first event is seen.
# its own if no input arrives first.
active_start = None active_start = None
idle_start_time = None idle_start_time = None
idle_cap = None
def expire_cap(at: int) -> None:
nonlocal active_start, idle_start_time, idle_cap
if idle_cap is not None and at >= idle_cap:
credit_break(idle_start_time, idle_cap)
active_start, idle_start_time, idle_cap = idle_cap, None, None
for timestamp, event_type in idle_events: for timestamp, event_type in idle_events:
expire_cap(timestamp)
if event_type == "snoozed": if event_type == "snoozed":
# Only counts if a break is due; snoozing again restarts it # Only counts if a break is due; snoozing again restarts it
pending = 0 pending = 0
@@ -227,26 +217,16 @@ def calculate_status(events: Events, config: Config) -> Status:
elif event_type == "idle_end": elif event_type == "idle_end":
if idle_start_time is not None: if idle_start_time is not None:
credit_break(idle_start_time, timestamp) credit_break(idle_start_time, timestamp)
idle_start_time = idle_cap = None idle_start_time = None
if active_start is None: if active_start is None:
active_start = timestamp active_start = timestamp
elif idle_start_time is not None: elif idle_start_time is None: # idle_start; ignored if already on a break
# Already on a break. Sleeping during a reading break turns it
# into an ordinary break that lasts until input.
if event_type == "idle_start":
idle_cap = None
else:
if active_start is not None: if active_start is not None:
add_work(active_start, timestamp) add_work(active_start, timestamp)
active_start = None active_start = None
idle_start_time = timestamp idle_start_time = timestamp
if event_type == "reading_break":
long_due = active_time_since_long_break >= long_interval
idle_cap = timestamp + (long_duration if long_due else short_duration)
expire_cap(current_time)
if active_start is not None: if active_start is not None:
add_work(active_start, current_time) add_work(active_start, current_time)