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
5 changes: 5 additions & 0 deletions src/toad/client/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ def deactivate(self, app: ClientApplication) -> ApplicationPresence:

def suspend(self, app: ClientApplication) -> ApplicationPresence:
app.application.backgrounded()
app.set_animations_paused(True)
return SUSPENDED_PRESENCE


Expand All @@ -116,6 +117,7 @@ def activate(self, app: ClientApplication) -> ApplicationPresence:

class SuspendedPresence(ApplicationPresence):
def activate(self, app: ClientApplication) -> ApplicationPresence:
app.set_animations_paused(False)
# `resume()` publishes `CoordinationObserved` once the fresh observation attaches,
# which triggers `stores_changed` -> `selected.reload()` on the new observer instead
# of racing a synchronous reload against the retiring one (`ObserverRetired`).
Expand Down Expand Up @@ -144,6 +146,9 @@ def history_displayed(self) -> None:
after its startup."""
HEAP.history_displayed()

def set_animations_paused(self, paused: bool) -> None:
"""Pause or resume the frontend's animation timer while the app is suspended."""

def open_settings(self) -> SavedSettings:
"""The settings file every frontend reads at launch and writes on a change; each
change applies its `Effect` through `apply_setting_effect`, so a setting changed in
Expand Down
37 changes: 23 additions & 14 deletions src/toad/qt/side_bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,13 @@ def __init__(self, surface: QtSideBar) -> None:
self.setAlignment(Qt.AlignmentFlag.AlignCenter)
self.setCursor(Qt.CursorShape.PointingHandCursor)
self._symbol = self._heading = ""
self._leading_splitter = False
self._trailing_splitter = False

def set_trailing_splitter(self, shown: bool) -> None:
if self._trailing_splitter != shown:
self._trailing_splitter = shown
def set_band_splitters(self, leading: bool, trailing: bool) -> None:
if self._leading_splitter != leading or self._trailing_splitter != trailing:
self._leading_splitter = leading
self._trailing_splitter = trailing
self.update()

def show_toggle(self, text: str, tooltip: str) -> None:
Expand All @@ -219,21 +221,23 @@ def show_turned(self, symbol: str, heading: str) -> None:
self._symbol, self._heading = symbol, heading
self.update()

def _draw_trailing_splitter(self, painter: QPainter) -> None:
if not self._trailing_splitter:
return
def _draw_hairlines(self, painter: QPainter, *, vertical: bool) -> None:
painter.save()
painter.setPen(self.palette().color(QPalette.ColorRole.Mid))
x = self.width() - 1
painter.drawLine(x, 0, x, self.height())
w, h = self.width(), self.height()
x1, y1, x2, y2 = self._surface.placement.side.inner_hairline(w, h)
painter.drawLine(x1, y1, x2, y2)
if vertical and self._leading_splitter:
painter.drawLine(0, 0, 0, h)
if self._trailing_splitter:
painter.drawLine(w - 1, 0, w - 1, h)
painter.restore()

def paintEvent(self, event) -> None: # type: ignore[override]
if self.height() <= self.width():
super().paintEvent(event)
if self._trailing_splitter:
painter = QPainter(self)
self._draw_trailing_splitter(painter)
painter = QPainter(self)
self._draw_hairlines(painter, vertical=False)
return
painter = QPainter(self)
option = QStyleOption()
Expand All @@ -253,7 +257,7 @@ def paintEvent(self, event) -> None: # type: ignore[override]
span = QRect(-reach, -self.width() // 2, 2 * reach, self.width())
painter.drawText(span, Qt.AlignmentFlag.AlignCenter, shown)
painter.restore()
self._draw_trailing_splitter(painter)
self._draw_hairlines(painter, vertical=True)


class QtSidebarResizeHandle(QtGripPointer, SidebarResizeGrip, QWidget, metaclass=PyQtWidgetMeta):
Expand Down Expand Up @@ -482,10 +486,15 @@ def arrange(self, *, animate: bool = True) -> None:
if region is None:
self._land(bar)
self.placed.pop(bar, None)
bar.toggle.set_trailing_splitter(False)
bar.toggle.set_band_splitters(False, False)
bar.hide()
continue
bar.toggle.set_trailing_splitter(self._layout.splits_after(bar.placement_identity, collapsed))
leading = self._layout.splits_before(bar.placement_identity, collapsed)
trailing = (
self._layout.splits_after(bar.placement_identity, collapsed)
and (bar.collapsed or not self._layout.next_in_band_folded(bar.placement_identity, collapsed))
)
bar.toggle.set_band_splitters(leading, trailing)
now = PlacedSidebar(region, bar.collapsed)
slide = self.slides.get(bar)
if slide is not None and slide.target == now:
Expand Down
17 changes: 13 additions & 4 deletions src/toad/qt/virtual_scroll.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import math
import time

import shiboken6
from PySide6.QtCore import QPoint, QRect, QRectF, QSize, Qt, QTimer
from PySide6.QtGui import (
QAbstractTextDocumentLayout,
Expand Down Expand Up @@ -661,8 +662,10 @@ def _application_state_changed(self, state: Qt.ApplicationState) -> None:
"""Defer dropping laid-out documents and tiles across brief Android app switches so
reopening within `SUSPEND_RELEASE_MS` paints from warm caches without a 100+ ms
re-layout/re-rasterize stall, while prolonged backgrounding still returns memory."""
if self._stopped or not shiboken6.isValid(self._suspend_release_timer):
return
if state is Qt.ApplicationState.ApplicationSuspended:
if not self._stopped and not self._suspend_release_timer.isActive():
if not self._suspend_release_timer.isActive():
self._suspend_release_timer.start()
elif state is Qt.ApplicationState.ApplicationActive:
self._suspend_release_timer.stop()
Expand Down Expand Up @@ -840,9 +843,15 @@ def cleanup(self) -> None:
return
self._stopped = True
self.preparing = False
self._viewport_update_timer.stop()
self._measure_timer.stop()
self._suspend_release_timer.stop()
app = QGuiApplication.instance()
if app is not None:
try:
app.applicationStateChanged.disconnect(self._application_state_changed)
except (RuntimeError, TypeError):
pass
for timer in (self._viewport_update_timer, self._measure_timer, self._suspend_release_timer):
if shiboken6.isValid(timer):
timer.stop()
self.preparer.clear()
self.stop_preparation()
self.preparer.stop()
Expand Down
16 changes: 14 additions & 2 deletions src/toad/qt/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -1756,6 +1756,8 @@ def __init__(self, connection: CoreConnection, project: Checkout,
# would land some ticks between two frames and show one frame twice.
self._animation_timer.setTimerType(Qt.TimerType.PreciseTimer)
self._animation_timer.timeout.connect(self._tick_animation)
self._animation_interval: float | None = None
self._animations_paused = False
self._layout_pending = False
self._presence: ApplicationPresence = ACTIVE_PRESENCE
self.animation_clock = AnimationClock(self._schedule_animation, enabled=animations_enabled())
Expand Down Expand Up @@ -1882,6 +1884,7 @@ def __init__(self, connection: CoreConnection, project: Checkout,
# The bar row is Toad's header band: a frame in the theme's header tone. Notices
# float over the pages in `float_layer`; they are no part of this band.
self.navigation = chrome = QFrame(self)
chrome.setObjectName("toad-navigation")
chrome_layout = QVBoxLayout(chrome)
chrome_layout.setContentsMargins(0, 0, 0, 0)
chrome_layout.setSpacing(0)
Expand Down Expand Up @@ -2111,13 +2114,20 @@ def source(self) -> ObservedSource:

def _schedule_animation(self, interval: float | None) -> None:
"""The clock's one timer: tick every ``interval`` seconds, or stop."""
self._animation_interval = interval
if not shiboken6.isValid(self._animation_timer):
return
if interval is None:
if interval is None or self._animations_paused:
self._animation_timer.stop()
else:
self._animation_timer.start(max(1, round(interval * 1000)))

def set_animations_paused(self, paused: bool) -> None:
if self._animations_paused == paused:
return
self._animations_paused = paused
self._schedule_animation(self._animation_interval)

def _tick_animation(self) -> None:
self.animation_clock.tick()

Expand Down Expand Up @@ -2203,9 +2213,10 @@ def paint_chrome_colours(self) -> None:
)
self.tabs.set_colours(QColor(underline_hex), QColor(active_ink), QColor(inactive_ink))
sep_hex = self.palette().color(QPalette.ColorRole.Mid).name()
nav_edge = self.settings.ui.navigation_bar.qt_separator_edge
self.navigation.setStyleSheet(
scheme.styles.generate_frame_style()
+ f"QFrame {{ background-color: {bar_bg}; padding: 2px 2px; }}"
+ f"QFrame#toad-navigation {{ background-color: {bar_bg}; padding: 2px 2px; border: none; {nav_edge}: 1px solid {sep_hex}; }}"
+ f"QFrame#toad-nav-separator {{ border: none; padding: 0px; margin: 4px 0px; background: {sep_hex}; }}"
)
self.float_layer.follow_scheme(scheme)
Expand Down Expand Up @@ -2239,6 +2250,7 @@ def apply_layout_preferences(self) -> None:
layout.removeWidget(widget)
layout.insertWidget(index, widget, 1 if widget is self.chrome else 0)
self.apply_text_scale(self.settings.ui.message_font_scale)
self.paint_chrome_colours()
self._sync_keyboard_chrome()

def follow_theme(self) -> None:
Expand Down
8 changes: 6 additions & 2 deletions src/toad/setting_choices.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,6 @@ class NormalInputBox(TitledChoice, InputBox):
"""The classic prompt: a bordered, padded box above the info bar."""

title = "Normal (bordered and padded)"
frame_margin = Spacing(0, 1, 0, 1)
frame_padding = Spacing(0, 1, 0, 0)
qt_border_pixels = 2

Expand All @@ -267,7 +266,7 @@ def qt_frame_sheet(cls, field: str, colour: str) -> str:

@classmethod
def info_bar_margin(cls, footer: bool) -> Spacing:
return Spacing(0, 2, 0, 2)
return Spacing(0, 1, 0, 1)


class CompactInputBox(TitledChoice, InputBox):
Expand Down Expand Up @@ -316,6 +315,8 @@ class NavigationBarPosition(DeclaredChoice, affix="NavigationBar"):
yields_to_keyboard: ClassVar[bool] = False
"""Bottom-docked bars hide while a touch soft keyboard is open so the composer sits flush
above the keyboard instead of floating over dead chrome."""
qt_separator_edge: ClassVar[str]
"""Qt CSS border property separating the navigation bar from the adjacent workspace chrome."""

@classmethod
@abstractmethod
Expand All @@ -330,13 +331,16 @@ def place(cls, navigation, body) -> None:


class TopNavigationBar(NavigationBarPosition):
qt_separator_edge = "border-bottom"

@classmethod
def around[W](cls, navigation: W, body: W) -> tuple[W, W]:
return navigation, body


class BottomNavigationBar(NavigationBarPosition):
yields_to_keyboard = True
qt_separator_edge = "border-top"

@classmethod
def around[W](cls, navigation: W, body: W) -> tuple[W, W]:
Expand Down
14 changes: 14 additions & 0 deletions src/toad/sidebar_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,12 @@ def set_split(self, side: type[SidebarEdge], percent: int) -> bool:
self._save(replace(self.terminal, splits=(*others, BandSplit(side, percent))))
return True

def splits_before(self, identity: type[SidebarPlacement],
collapsed: Mapping[type[SidebarPlacement], bool]) -> bool:
"""Whether an earlier shown bar in this one's band sits beside it on the left."""
shown = tuple(key for key in self._slot(self.placements, identity) if key in collapsed)
return shown.index(identity) > 0

def splits_after(self, identity: type[SidebarPlacement],
collapsed: Mapping[type[SidebarPlacement], bool]) -> bool:
"""Whether the next shown bar in this one's band sits beside it, so its splitter shows:
Expand All @@ -694,6 +700,14 @@ def splits_after(self, identity: type[SidebarPlacement],
index = shown.index(identity)
return index + 1 < len(shown)

def next_in_band_folded(self, identity: type[SidebarPlacement],
collapsed: Mapping[type[SidebarPlacement], bool]) -> bool:
"""Whether the next shown bar in this band is folded (and therefore draws its own
full-height leading hairline beside this open pane)."""
shown = tuple(key for key in self._slot(self.placements, identity) if key in collapsed)
index = shown.index(identity)
return index + 1 < len(shown) and collapsed[shown[index + 1]]

def _store(self, placements: dict[type[SidebarPlacement], SidebarPlacement]) -> None:
self._save(replace(self.terminal, placements=tuple(placements.values())))

Expand Down
15 changes: 15 additions & 0 deletions src/toad/sidebar_placement.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ def _toggle_text_step(cls, collapsed: bool, heading: str, symbol) -> str:
@abstractmethod
def control_offset(cls, distance: int) -> Offset: ...

@classmethod
@abstractmethod
def inner_hairline(cls, width: int, height: int) -> tuple[int, int, int, int]:
"""Line endpoints (x1, y1, x2, y2) for the 1 px hairline on the conversation-facing edge."""

@classmethod
def opposite(cls) -> type[SidebarEdge]:
"""The other concrete edge on the same axis (left<->right, top<->bottom).
Expand Down Expand Up @@ -219,6 +224,11 @@ def _toggle_text_step(cls, collapsed: bool, heading: str, symbol) -> str:
def control_offset(cls, distance: int) -> Offset:
return Offset(-cls.sign * distance, 0)

@classmethod
def inner_hairline(cls, width: int, height: int) -> tuple[int, int, int, int]:
x = width - 1 if cls.sign > 0 else 0
return (x, 0, x, height)


class HeightSidebarEdge(SidebarEdge):
minimum = 9
Expand Down Expand Up @@ -301,6 +311,11 @@ def _toggle_text_step(cls, collapsed: bool, heading: str, symbol) -> str:
def control_offset(cls, distance: int) -> Offset:
return Offset(0, -cls.sign * distance)

@classmethod
def inner_hairline(cls, width: int, height: int) -> tuple[int, int, int, int]:
y = height - 1 if cls.sign > 0 else 0
return (0, y, width, y)


class LeftSidebarEdge(LeadingSidebarEdge, WidthSidebarEdge):
dock = "left"
Expand Down
Loading
Loading