Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/toad/client/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ async def read_changes(self) -> bool:

def prepare_viewport(self) -> None:
super().prepare_viewport()
if self.can_draw_on_screen:
if self.can_draw_on_screen and not self.window.scroll_in_motion:
self.mark_visible()
self.follow_message_style()

Expand All @@ -183,7 +183,10 @@ async def restyle(self, style) -> None:

def mark_visible_after_paint(self) -> None:
"""Try marking read again once the frontend has painted its next frame, coalesced so
painting many rows in one scroll frame schedules one callback instead of N."""
painting many rows in one scroll frame schedules one callback instead of N. Defers
while the window is actively scrolling; settle flushes `prepare_viewport()` once."""
if self.window.scroll_in_motion:
return
if not self._read_mark_scheduled:
self._read_mark_scheduled = True
self.call_after_refresh(self._run_scheduled_mark_visible)
Expand Down Expand Up @@ -218,7 +221,7 @@ def read_fragments(self) -> tuple[EvidencedFragment, ...]:
return tuple(self._painted_reads.values())

def read_visible(self) -> PaintedRead:
if not self.is_attached:
if not self.is_attached or self.window.scroll_in_motion:
return NothingToRead()
if not any(fragment.evidence is not None for fragment in self.read_fragments()):
return NothingToRead()
Expand Down
10 changes: 9 additions & 1 deletion src/toad/client/history_notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ def check_notifications_after_refresh(self) -> None:

def check_notifications(self) -> None:
fragments = self.notification_targets() if self.can_draw_on_screen else ()
if any(target.notifications_deferred for target in fragments):
return
references = tuple(dict.fromkeys(
reference for fragment in fragments for reference in fragment.notification_references))
# The connection still showing a read for this view is checked too: a hide stops the
Expand Down Expand Up @@ -181,9 +183,15 @@ def rows_published(self) -> None:
self.notification_view.checked_references = None
self.notification_view.check_notifications_after_refresh()

@property
def notifications_deferred(self) -> bool:
"""Defer notification re-subscription while the window is actively scrolling."""
return self.window.scroll_in_motion

def prepare_viewport(self) -> None:
super().prepare_viewport()
self.notification_view.check_notifications()
if not self.notifications_deferred:
self.notification_view.check_notifications()

def check_visible_notifications(self) -> None:
self.notification_view.check_notifications_after_refresh()
Expand Down
5 changes: 5 additions & 0 deletions src/toad/client/history_pager.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,11 @@ class PagingWindow(ReaderWindow):
arrival_burst: ArrivalBurst = NO_BURST
"""The messages that last arrived together at the end the reader follows."""

@property
def scroll_in_motion(self) -> bool:
"""Whether an active drag, fling, or unsettled scroll burst is moving this window."""
return False

def arrivals_followed(self, arrivals: tuple[HistoryFragment, ...]) -> None:
"""`arrivals` were published at the followed end: they join the burst while the reader
follows it, or while the burst is still arriving (Textual stops following where it
Expand Down
2 changes: 1 addition & 1 deletion src/toad/history_jump.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def record_reader_scroll(self, delta: float) -> None:
self.rejoin_reached_tail()


class ReaderWindow(JumpsToLatest):
class PagedReader(JumpsToLatest):
"""A history window the reader keys move: a page either way, or back to the latest
(`reader_actions`). Textual's `HistoryWindow` and Qt's `QtHistoryWindow` both list it."""

Expand Down
10 changes: 7 additions & 3 deletions src/toad/qt/activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from PySide6.QtGui import QColor, QLinearGradient, QPainter
from PySide6.QtWidgets import QVBoxLayout, QWidget
from pyqt_reactive.widgets.fitted_text import ElidedLine
from ui_theme.clock import Animation, AnimationClock
from ui_theme.clock import Animation
from ui_theme.effects import ACTIVITY_SWEEP, Ribbon
from ui_theme.scheme import BackgroundColour

Expand All @@ -23,7 +23,7 @@
from toad.qt.lines import QtLineRenderer
from toad.status_thread import ObservedActivity
from toad.qt.metrics import UiGap
from toad.qt.widget_animation import WidgetAnimation
from toad.qt.widget_animation import QtAnimationClock, WidgetAnimation


class ActivitySweep(SweepEffect, WidgetAnimation, QWidget):
Expand All @@ -36,7 +36,7 @@ class ActivitySweep(SweepEffect, WidgetAnimation, QWidget):
backing store continuously.
"""

def __init__(self, renderer: QtLineRenderer, clock: AnimationClock) -> None:
def __init__(self, renderer: QtLineRenderer, clock: QtAnimationClock) -> None:
super().__init__()
self.renderer = renderer
self.working = False
Expand Down Expand Up @@ -74,6 +74,10 @@ def repaint(self) -> None:
"""A shared clock tick invalidates this strip; Qt schedules its native paint."""
self.update()

@property
def animation_visible(self) -> bool:
return super().animation_visible and not self.clock.scrolling

def paintEvent(self, event) -> None: # type: ignore[override]
painter = QPainter(self)
background, bg_qcolor, stops_map = self._scheme_colours()
Expand Down
39 changes: 26 additions & 13 deletions src/toad/qt/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
FragmentLocation, FragmentPosition, ReaderPage, ReaderPosition, RowPosition, TailPosition,
UnloadedFragment,
)
from toad.history_jump import FollowsTail, JumpsToLatest, ReaderWindow
from toad.history_jump import FollowsTail, JumpsToLatest, PagedReader
from toad.no_worker import NoTask
from toad.qt.live_turn import QtLiveBlock
from toad.qt.workspace_frame import QtWorkspaceHosted
Expand Down Expand Up @@ -1204,13 +1204,6 @@ class QtHistoryNotifications(OneHistoryNotifications):
notification_work = NoTask()
_notifications_timer: QTimer | None = None

def check_notifications(self) -> None:
"""Defer notification re-subscription while a finger is actively dragging or flinging
QScroller; `QtHistoryWindow._on_scroller_state` flushes the instant motion settles."""
if self.message_history.window.actively_scrolling:
return
super().check_notifications()

def report_queue_evidence(self) -> None:
"""New queue evidence repaints the composer's queue rows, as Textual's
`Conversation.queue_evidence_changed` does through its submissions. Skip scheduling
Expand Down Expand Up @@ -1534,7 +1527,7 @@ def show_jump(self, shown: bool) -> None:
self.setVisible(shown)


class QtHistoryWindow(AnimatesArrivals, ReaderPlacement, ShowsLatestJumpBar, FollowsTail, ReaderWindow,
class QtHistoryWindow(AnimatesArrivals, ReaderPlacement, ShowsLatestJumpBar, FollowsTail, PagedReader,
QtWorkspaceHosted, VirtualRowCanvas, PagingWindow, TogglesFragmentShown, PinsMessageHeader,
SettingsReading):
"""The reader window of one Qt conversation: prefix-sum virtual rows of the history's
Expand Down Expand Up @@ -1665,6 +1658,7 @@ def repaint_arrival_keys(self, keys: tuple[object, ...]) -> None:

def _on_widget_destroyed(self, *_args) -> None:
self.stop_arrival_motion()
self.animation_clock.set_scrolling(self, False)

async def acquire_links(self, app) -> None:
"""The names this conversation's bodies link through; redraw rows only if links changed."""
Expand Down Expand Up @@ -2200,6 +2194,8 @@ def showEvent(self, event) -> None: # type: ignore[override]
def hideEvent(self, event) -> None: # type: ignore[override]
super().hideEvent(event)
self.actively_scrolling = False
self._settle_timer.stop()
self._sync_clock_scrolling()

def resizeEvent(self, event) -> None: # type: ignore[override]
"""A window that follows the latest message stays on it when its height changes: the
Expand Down Expand Up @@ -2317,10 +2313,18 @@ def reveal_head_at(self, point: QPoint) -> bool:
return False
return self.start_head_reveal(self.scroll_y + top)

@property
def scroll_in_motion(self) -> bool:
"""Whether a finger drag/fling or an unsettled scroll burst is moving the viewport."""
return self.actively_scrolling or self._settle_timer.isActive()

def _sync_clock_scrolling(self) -> None:
self.animation_clock.set_scrolling(self, self.scroll_in_motion)

def _on_scroller_state(self, state) -> None:
"""A finger taking the rows stops a head reveal; a press that stops a fling is
remembered, so its release is not read as a tap on a row. Notification checks wait
until the drag/fling settles instead of firing hundreds of Core subscriptions mid-fling."""
remembered, so its release is not read as a tap on a row. Notification checks,
read-marking, and decorative chrome animations wait until motion settles."""
scrolling = state in (QScroller.State.Dragging, QScroller.State.Scrolling)
was_scrolling = self.actively_scrolling
self.actively_scrolling = scrolling
Expand All @@ -2334,8 +2338,15 @@ def _on_scroller_state(self, state) -> None:
self._overshoot = 0.0
self._travel_origin = 0.0
if was_scrolling and not scrolling:
for history in tuple(self.histories):
history.notification_view.check_notifications_after_refresh()
if self._settle_timer.isActive():
self._settle_timer.stop()
self._sync_clock_scrolling()
self._settle()
else:
self._sync_clock_scrolling()
self.request_preparation()
else:
self._sync_clock_scrolling()

_travel_origin = 0.0
"""How far layout has moved the reader since the finger now scrolling them came down.
Expand Down Expand Up @@ -2451,6 +2462,7 @@ def _schedule_settle(self) -> None:
self._last_scroll_at = monotonic()
if not self._settle_timer.isActive():
self._settle_timer.start(int(self.lookahead.idle_seconds * 1000))
self._sync_clock_scrolling()

def _on_settle_timer(self) -> None:
if self.widget_gone:
Expand All @@ -2459,6 +2471,7 @@ def _on_settle_timer(self) -> None:
if remaining_ms > 15:
self._settle_timer.start(remaining_ms)
return
self._sync_clock_scrolling()
self._settle()

def after_source_presented(self, callback, *arguments) -> None:
Expand Down
4 changes: 2 additions & 2 deletions src/toad/qt/name_wave.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ def wave_visible(self) -> bool:

@property
def animation_visible(self) -> bool:
return self.wave_visible()
return self.wave_visible() and not self.wave_clock().scrolling

def wave_running(self) -> bool:
return self.animation is not None
Expand Down Expand Up @@ -431,7 +431,7 @@ def __init__(self, bar: QtSessionTabBar) -> None:

@property
def animation_visible(self) -> bool:
return self.bar.isVisible()
return self.bar.isVisible() and not self.bar.clock.scrolling

def marquee_running(self) -> bool:
return self.animation is not None
Expand Down
29 changes: 29 additions & 0 deletions src/toad/qt/widget_animation.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,35 @@
from ui_theme.clock import AnimationClock


class QtAnimationClock(AnimationClock):
"""Qt's shared animation clock: tracks scrolling history windows so infinite decorative
chrome effects (name waves, tab marquees, activity sweeps) yield while scrolling without
stalling finite transitions (arrivals, fades, tab open/close) or expanding Android's
backing-store dirty bounding box to a full-screen GPU upload."""

def __init__(self, schedule, *, enabled: bool = True, frame_interval: float = 1 / 60,
now=None) -> None:
if now is None:
super().__init__(schedule, enabled=enabled, frame_interval=frame_interval)
else:
super().__init__(schedule, now=now, enabled=enabled, frame_interval=frame_interval)
self._scrolling_owners: set[int] = set()

@property
def scrolling(self) -> bool:
return bool(self._scrolling_owners)

def set_scrolling(self, owner: object, active: bool) -> None:
was = self.scrolling
oid = id(owner)
if active:
self._scrolling_owners.add(oid)
else:
self._scrolling_owners.discard(oid)
if self.scrolling != was:
self.refresh()


def frame_interval(screen: QScreen | None) -> float:
"""Seconds between the frames `screen` shows: one over its refresh rate (a Pixel 8a's 120 Hz),
or 60 Hz where it reports none (offscreen, some remote displays). Motion ticks at it
Expand Down
5 changes: 2 additions & 3 deletions src/toad/qt/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
from toad.qt.mailbox_view import QtMailboxView
from toad.qt.opening_view import QtOpeningSessionView
from toad.qt.tap_flash import QtPushButton, QtTextButton
from ui_theme.clock import AnimationClock
from ui_theme.scheme import (
AlternateRowToneColour,
ColourScheme,
Expand All @@ -74,7 +73,7 @@
from toad.app_core import CorePrewarm
from toad.client.application import ACTIVE_PRESENCE, ApplicationPresence, ClientApplication
from toad.qt.workspace_frame import QtWorkspaceFrame, QtWorkspaceHosted
from toad.qt.widget_animation import frame_interval
from toad.qt.widget_animation import QtAnimationClock, frame_interval
from toad.workspace_frame import WorkspaceFrame
from toad.client.session_scope import NoConversationView
from toad.client.application_actions import ApplicationAction, MenuActionRun, NewSessionAction, NewSessionControl
Expand Down Expand Up @@ -1764,7 +1763,7 @@ def __init__(self, connection: CoreConnection, project: Checkout,
self._animations_paused = False
self._layout_pending = False
self._presence: ApplicationPresence = ACTIVE_PRESENCE
self.animation_clock = AnimationClock(self._schedule_animation, enabled=animations_enabled())
self.animation_clock = QtAnimationClock(self._schedule_animation, enabled=animations_enabled())
# Notices and the work the reader waits on float over the pages, never in their layout.
self.float_layer = QtFloatLayer(
self.theme.color_scheme, self.renderer, self.animation_clock, self)
Expand Down
4 changes: 2 additions & 2 deletions src/toad/reader_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@

from textual.document._editing import VimMode

from toad.history_jump import ReaderWindow
from toad.history_jump import PagedReader
from toad.widget_actions import Action


class ReaderAction(Action, affix="Action"):
"""Vim reader keys every history window answers."""

context_capability = ReaderWindow
context_capability = PagedReader


class PageDownAction(ReaderAction, declared_name="reader_page_down"):
Expand Down
4 changes: 2 additions & 2 deletions src/toad/transcript_publication.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
from toad.core.link_context_changed import CoreEventStream
from toad.core.projection import MroProjection
from toad.core.source_events import TranscriptCoverage as CoverageEvent
from toad.history_jump import ReaderWindow
from toad.history_jump import PagedReader
from toad.live_output import LiveOutput
from toad.client.resource_release import AsyncResourceRelease, ResourceRelease
from toad.client.session_scope import SessionOrigin, SessionScope
Expand Down Expand Up @@ -1196,7 +1196,7 @@ def retire_presentations(

if any(candidate.display for candidate in candidates):
# Their rows leave the window now; the reader stays on theirs.
contents.query_ancestor(ReaderWindow).keep_reader()
contents.query_ancestor(PagedReader).keep_reader()
for candidate in candidates:
candidate.display = False
retirement = asyncio.create_task(
Expand Down
4 changes: 2 additions & 2 deletions src/toad/widgets/history_anchor.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

from toad.block_navigation import ConversationBlock
from toad.arrivals import AnimatesArrivals
from toad.history_jump import FollowsTail, JumpsToLatest, ReaderWindow
from toad.history_jump import FollowsTail, JumpsToLatest, PagedReader
from toad.core.projection import MroProjection
from toad.no_worker import NO_TIMER, NoTimer
from toad.workspace_frame import WorkspaceHosted
Expand Down Expand Up @@ -57,7 +57,7 @@


class HistoryWindow(FollowsTail, NativeMethodKeys, WorkspaceHosted, MroProjection[tuple[MessageRowOwner, ...]],
AnimatesArrivals, ReaderPlacement, ReaderWindow, VerticalScroll, PagingWindow,
AnimatesArrivals, ReaderPlacement, PagedReader, VerticalScroll, PagingWindow,
actions=(ReaderAction,)):
"""A document owns reader intent and ends its pointer-scroll route.

Expand Down
Loading
Loading