Skip to content

Commit 42bbba6

Browse files
refactor(ui): replace session spinner with fill
Busy session numbers drove a shared ~15fps timer and kept repainting whenever any slot was working and on screen. A static Highlight fill shows the same state without timer work, never changes layout size, and keeps the digit readable. - Track dock visibility so hidden/tabbed strips still reinstall - Align strip/dock tests with fill and tabbed-away waiting dots
1 parent 2975484 commit 42bbba6

6 files changed

Lines changed: 111 additions & 134 deletions

File tree

‎src/docks/AiAgentDock.cpp‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ AiAgentDock::AiAgentDock(QString sessionId,
100100
connect(this, &QDockWidget::dockLocationChanged, this, [this](Qt::DockWidgetArea) {
101101
scheduleStripReinstall();
102102
});
103-
connect(this, &QDockWidget::visibilityChanged, this, [this](bool) {
103+
connect(this, &QDockWidget::visibilityChanged, this, [this](bool visible) {
104+
m_onScreen = visible;
104105
// Hidden docks must reinstall too: tabify rebuilds the area bar and
105106
// the inactive project's [1][2] live on that bar, not on this widget.
106107
scheduleStripReinstall();
@@ -200,7 +201,7 @@ void AiAgentDock::wireSlotSignals(Slot &slot)
200201
connect(slot.connection, &AcpConnection::backgroundIdle,
201202
this, &AiAgentDock::onNativeGoalBackgroundIdle,
202203
Qt::UniqueConnection);
203-
// Background tasks and Monitor watches keep the session number spinning.
204+
// Background tasks and Monitor watches keep the session number's working fill.
204205
connect(slot.connection, &AcpConnection::backgroundIdle,
205206
this, &AiAgentDock::onWorkChanged, Qt::UniqueConnection);
206207
connect(slot.connection, &AcpConnection::scheduledJobsChanged,
@@ -502,7 +503,7 @@ void AiAgentDock::setActivityIndicator(bool active)
502503
if (const int newest = indexOfSession(newestSessionId()); newest >= 0) {
503504
if (m_current != newest)
504505
m_slots[newest].hasActivity = true;
505-
else if (!isVisible())
506+
else if (!m_onScreen)
506507
m_slots[m_current].hasActivity = true;
507508
}
508509
} else if (Slot *slot = currentSlot()) {
@@ -513,15 +514,15 @@ void AiAgentDock::setActivityIndicator(bool active)
513514

514515
AiAgentDock::ProjectMark AiAgentDock::projectMark() const
515516
{
516-
const bool raised = isVisible();
517+
const bool raised = m_onScreen;
517518
bool activity = false;
518519
bool working = false;
519520
bool waiting = false;
520521
for (int i = 0; i < m_slots.size(); ++i) {
521522
const Slot &slot = m_slots.at(i);
522523
if (slot.hasActivity && (!raised || i != m_current))
523524
activity = true;
524-
// A raised dock already shows each number's own spinner and dot.
525+
// A raised dock already shows each number's own fill and dot.
525526
if (!raised && slotWorking(slot))
526527
working = true;
527528
if (!raised && slotWaiting(slot))
@@ -1124,7 +1125,7 @@ void AiAgentDock::pushStripSnapshots()
11241125
return;
11251126
QVector<AiDockSessionStrip::SlotSnapshot> snaps;
11261127
snaps.reserve(m_slots.size());
1127-
const bool raised = isVisible();
1128+
const bool raised = m_onScreen;
11281129
for (int i = 0; i < m_slots.size(); ++i) {
11291130
const Slot &slot = m_slots.at(i);
11301131
AiDockSessionStrip::SlotSnapshot snap;

‎src/docks/AiAgentDock.h‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ class AiAgentDock : public QDockWidget
8383
// A turn or goal is running. Scheduled tasks and the idle reaper go by this.
8484
bool isSessionBusy(const QString &sessionId) const;
8585
// Busy, or background work the agent started (tasks, Monitor watches) is
86-
// still alive: what the session number's spinner shows.
86+
// still alive: what the session number's working fill shows.
8787
bool isSessionWorking(const QString &sessionId) const;
8888
// A question form or permission request waits on the user, whether or not
8989
// the user can see it right now (the number's dot hides while they can).
@@ -241,6 +241,10 @@ private slots:
241241
QString m_newestSessionId; // last addSlot; survives reordering
242242
ProjectMark m_iconMark = ProjectMark::None; // what the window icon shows now
243243
QRgb m_iconHighlight = 0; // ... and in which Highlight colour
244+
// The dock is on screen, from QDockWidget::visibilityChanged. Never
245+
// isVisible(): a tabbed dock whose tab is not current stays visible, Qt
246+
// only parks it off-screen.
247+
bool m_onScreen = false;
244248

245249
QWidget *m_header = nullptr;
246250
QHBoxLayout *m_headerLayout = nullptr;

‎src/widgets/AiDockSessionStrip.cpp‎

Lines changed: 29 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,16 @@
3232
#include <QResizeEvent>
3333
#include <QSizePolicy>
3434
#include <QTabBar>
35-
#include <QTimer>
3635
#include <QToolButton>
3736
#include <QToolTip>
38-
#include <QWindow>
3937

4038
namespace {
4139

42-
constexpr int kSpinIntervalMs = 66; // ~15 fps, one timer for the whole strip
43-
constexpr int kSpinPeriodMs = 1000; // one turn of the arc
44-
constexpr int kArcSpanDeg = 100;
40+
constexpr int kBusyFillAlpha = 110; // Highlight at ~43%: the digit stays readable
4541

46-
// A session number that can wear a spinner. Painting only; the size never
47-
// changes, so a busy session never relayouts the tab bar.
42+
// A session number that can wear a working fill and a waiting dot. Painting
43+
// only, and static: the size never changes (a busy session never relayouts the
44+
// tab bar) and nothing repaints on a timer.
4845
class SessionNumberButton : public QToolButton
4946
{
5047
public:
@@ -64,31 +61,26 @@ class SessionNumberButton : public QToolButton
6461
m_waiting = waiting;
6562
update();
6663
}
67-
void setSpinAngle(int degrees)
68-
{
69-
m_angle = degrees;
70-
if (m_busy)
71-
update();
72-
}
7364

7465
protected:
7566
void paintEvent(QPaintEvent *event) override
7667
{
77-
QToolButton::paintEvent(event);
78-
if (!m_busy && !m_waiting)
79-
return;
80-
QPainter p(this);
81-
p.setRenderHint(QPainter::Antialiasing);
68+
// One painter at a time on a widget: the base paint opens its own.
8269
if (m_busy) {
83-
const int side = qMin(width(), height()) - 2;
84-
QRectF ring(0, 0, side, side);
85-
ring.moveCenter(QRectF(rect()).center());
86-
QPen pen(palette().color(QPalette::Highlight), 1.5);
87-
pen.setCapStyle(Qt::RoundCap);
88-
p.setPen(pen);
89-
p.drawArc(ring, -m_angle * 16, -kArcSpanDeg * 16);
70+
// Under the stylesheet's transparent rest background, so the
71+
// digit, the current number's border and the hover fill draw on top.
72+
QPainter p(this);
73+
p.setRenderHint(QPainter::Antialiasing);
74+
QColor fill = palette().color(QPalette::Highlight);
75+
fill.setAlpha(kBusyFillAlpha);
76+
p.setPen(Qt::NoPen);
77+
p.setBrush(fill);
78+
p.drawRoundedRect(QRectF(rect()), kFillRadius, kFillRadius);
9079
}
80+
QToolButton::paintEvent(event);
9181
if (m_waiting) {
82+
QPainter p(this);
83+
p.setRenderHint(QPainter::Antialiasing);
9284
// A window-coloured rim keeps the dot apart from the digit.
9385
const QPointF center(width() - kDotRadius - 1, kDotRadius + 1);
9486
p.setPen(QPen(palette().color(QPalette::Window), 1));
@@ -99,19 +91,16 @@ class SessionNumberButton : public QToolButton
9991

10092
private:
10193
static constexpr qreal kDotRadius = 3.0; // ~6px dot, top-right corner
94+
static constexpr qreal kFillRadius = 4.0; // ui-dna status-surface radius
10295
bool m_busy = false;
10396
bool m_waiting = false;
104-
int m_angle = 0;
10597
};
10698

10799
} // namespace
108100

109101
AiDockSessionStrip::AiDockSessionStrip(QWidget *parent)
110102
: QWidget(parent)
111103
{
112-
m_spinTimer = new QTimer(this);
113-
m_spinTimer->setInterval(kSpinIntervalMs);
114-
connect(m_spinTimer, &QTimer::timeout, this, &AiDockSessionStrip::onSpinTick);
115104
m_layout = new QHBoxLayout(this);
116105
m_layout->setContentsMargins(0, 0, 0, 0);
117106
m_layout->setSpacing(kSpacingPx);
@@ -143,9 +132,9 @@ void AiDockSessionStrip::setSlots(int count, int current, const QVector<SlotSnap
143132
rebuildButtons();
144133
}
145134

146-
bool AiDockSessionStrip::isSpinning() const
135+
bool AiDockSessionStrip::busyAt(int index) const
147136
{
148-
return m_spinTimer->isActive();
137+
return index >= 0 && index < m_snapshots.size() && m_snapshots.at(index).busy;
149138
}
150139

151140
QColor AiDockSessionStrip::attentionColor()
@@ -158,54 +147,10 @@ bool AiDockSessionStrip::waitingAt(int index) const
158147
return index >= 0 && index < m_snapshots.size() && m_snapshots.at(index).waiting;
159148
}
160149

161-
void AiDockSessionStrip::updateSpinTimer()
162-
{
163-
bool anyBusy = false;
164-
for (const SlotSnapshot &snap : std::as_const(m_snapshots)) {
165-
if (snap.busy) {
166-
anyBusy = true;
167-
break;
168-
}
169-
}
170-
const QWidget *top = window();
171-
const bool want = anyBusy && isVisible() && top && !top->isMinimized();
172-
if (want == m_spinTimer->isActive())
173-
return;
174-
if (want) {
175-
m_spinClock.start();
176-
m_spinTimer->start();
177-
} else {
178-
m_spinTimer->stop();
179-
}
180-
}
181-
182-
void AiDockSessionStrip::onSpinTick()
183-
{
184-
const int angle = static_cast<int>((m_spinClock.elapsed() % kSpinPeriodMs) * 360 / kSpinPeriodMs);
185-
for (QToolButton *btn : std::as_const(m_buttons))
186-
static_cast<SessionNumberButton *>(btn)->setSpinAngle(angle);
187-
}
188-
189-
void AiDockSessionStrip::showEvent(QShowEvent *event)
190-
{
191-
QWidget::showEvent(event);
192-
// Minimizing hides no widget: follow the window's own visibility.
193-
if (QWindow *handle = window() ? window()->windowHandle() : nullptr; handle != m_trackedWindow) {
194-
if (m_trackedWindow)
195-
disconnect(m_trackedWindow, nullptr, this, nullptr);
196-
m_trackedWindow = handle;
197-
if (handle) {
198-
connect(handle, &QWindow::visibilityChanged, this, [this]() { updateSpinTimer(); });
199-
}
200-
}
201-
updateSpinTimer();
202-
}
203-
204150
void AiDockSessionStrip::hideEvent(QHideEvent *event)
205151
{
206152
QWidget::hideEvent(event);
207153
endDrag();
208-
updateSpinTimer();
209154
}
210155

211156
QSize AiDockSessionStrip::sizeHint() const
@@ -406,23 +351,27 @@ void AiDockSessionStrip::restyleButtons()
406351
for (int i = 0; i < m_buttons.size(); ++i) {
407352
QToolButton *btn = m_buttons.at(i);
408353
const bool current = (i == m_current);
354+
const bool busy = busyAt(i);
409355
auto *numberBtn = static_cast<SessionNumberButton *>(btn);
410-
numberBtn->setBusy(i < m_snapshots.size() && m_snapshots.at(i).busy);
356+
numberBtn->setBusy(busy);
411357
numberBtn->setWaiting(waitingAt(i));
412358

413359
QFont font = btn->font();
414360
font.setBold(current);
415361
btn->setFont(font);
416362

363+
// A muted digit on the working fill is too faint: busy numbers take the
364+
// full text colour (the current one still has the bold and the border).
365+
const bool strong = current || busy;
417366
QPalette pal = btn->palette();
418-
pal.setColor(QPalette::ButtonText, current ? currentColor : muted);
419-
pal.setColor(QPalette::WindowText, current ? currentColor : muted);
367+
pal.setColor(QPalette::ButtonText, strong ? currentColor : muted);
368+
pal.setColor(QPalette::WindowText, strong ? currentColor : muted);
420369
btn->setPalette(pal);
421370
// Toolbar chrome (ui-dna): auto-raise + 1px mid border on hover.
422371
// Transparent rest border keeps size stable. Windows QStyle ignores
423372
// QToolButton palette colors, so paint via palette() roles.
424-
const QString colorRole = current ? QStringLiteral("palette(button-text)")
425-
: QStringLiteral("palette(placeholder-text)");
373+
const QString colorRole = strong ? QStringLiteral("palette(button-text)")
374+
: QStringLiteral("palette(placeholder-text)");
426375
const QString restBorder = current ? QStringLiteral("1px solid palette(mid)")
427376
: QStringLiteral("1px solid transparent");
428377
btn->setStyleSheet(
@@ -433,7 +382,6 @@ void AiDockSessionStrip::restyleButtons()
433382
.arg(colorRole, QString::number(kSpacingPx), restBorder));
434383
btn->setMinimumSize(btn->sizeHint());
435384
}
436-
updateSpinTimer();
437385
syncIntrinsicSize();
438386
notifyHostTabBar();
439387
}

‎src/widgets/AiDockSessionStrip.h‎

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,14 @@
2020
#define AI_DOCK_SESSION_STRIP_H
2121

2222
#include <QColor>
23-
#include <QElapsedTimer>
2423
#include <QPoint>
25-
#include <QPointer>
2624
#include <QString>
2725
#include <QVector>
2826
#include <QWidget>
2927

3028
class QHBoxLayout;
3129
class QHideEvent;
32-
class QShowEvent;
33-
class QTimer;
3430
class QToolButton;
35-
class QWindow;
3631

3732
// Clickable 1 2 3 session buttons for a project-grouped AI dock.
3833
// The strip is a pure view: it never queries ACP. The owner pushes a
@@ -69,9 +64,8 @@ class AiDockSessionStrip : public QWidget
6964
int slotCount() const { return m_count; }
7065
int currentIndex() const { return m_current; }
7166
QString slotTooltip(int index) const { return tooltipFor(index); }
72-
// True while the shared spin timer runs: some slot is working and the
73-
// strip is on screen. Nothing ticks otherwise.
74-
bool isSpinning() const;
67+
// The session is working: its number sits on a static Highlight fill.
68+
bool busyAt(int index) const;
7569
bool waitingAt(int index) const;
7670

7771
QSize sizeHint() const override;
@@ -87,12 +81,9 @@ class AiDockSessionStrip : public QWidget
8781
void changeEvent(QEvent *event) override;
8882
bool event(QEvent *event) override;
8983
bool eventFilter(QObject *watched, QEvent *event) override;
90-
void showEvent(QShowEvent *event) override;
9184
void hideEvent(QHideEvent *event) override;
9285

9386
private:
94-
void updateSpinTimer();
95-
void onSpinTick();
9687
void rebuildButtons();
9788
void restyleButtons();
9889
void syncIntrinsicSize();
@@ -113,10 +104,6 @@ class AiDockSessionStrip : public QWidget
113104
int m_count = 0;
114105
int m_current = 0;
115106

116-
QTimer *m_spinTimer = nullptr;
117-
QElapsedTimer m_spinClock;
118-
QPointer<QWindow> m_trackedWindow;
119-
120107
int m_pressIndex = -1;
121108
QPoint m_pressGlobalPos;
122109
bool m_dragging = false;

‎tests/test_acp_session_view_wake.cpp‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <QComboBox>
1616
#include <QDockWidget>
1717
#include <QLabel>
18+
#include <QMainWindow>
1819
#include <QPlainTextEdit>
1920
#include <QScrollArea>
2021
#include <QSignalSpy>
@@ -268,6 +269,7 @@ private slots:
268269
void waiting_formCancelledForUnattendedSession_doesNotCount();
269270
void dock_waitingSession_showsDotUntilTheUserCanSeeIt();
270271
void dock_waiting_beatsWorking_onTheProjectTab();
272+
void dock_tabbedAway_showsDotOnTheOpenSession();
271273
void draft_selectorChange_becomesAgentDefault();
272274
void afterUserSend_selectorChange_staysInThisSession();
273275
void goalAndHostPrompts_doNotEndTheDraft();
@@ -574,6 +576,43 @@ void TestAcpSessionViewWake::dock_waiting_beatsWorking_onTheProjectTab()
574576
QCOMPARE(dock.projectMark(), AiAgentDock::ProjectMark::Working);
575577
}
576578

579+
// Switching to another project's tab does not hide a tabbed QDockWidget: Qt
580+
// parks it off-screen and it stays isVisible(). The open session's dot and the
581+
// project tab's mark must still come back.
582+
void TestAcpSessionViewWake::dock_tabbedAway_showsDotOnTheOpenSession()
583+
{
584+
Session s;
585+
QMainWindow win;
586+
win.setCentralWidget(new QWidget(&win));
587+
auto *dock = new AiAgentDock(QStringLiteral("s1"), QStringLiteral("claude"), QStringLiteral("/tmp"),
588+
s.model.get(), &s.conn, nullptr, nullptr, nullptr, &win);
589+
auto *other = new QDockWidget(QStringLiteral("other"), &win);
590+
other->setObjectName(QStringLiteral("other"));
591+
other->setWidget(new QLabel(QStringLiteral("other project"), other));
592+
win.addDockWidget(Qt::RightDockWidgetArea, dock);
593+
win.addDockWidget(Qt::RightDockWidgetArea, other);
594+
win.tabifyDockWidget(dock, other);
595+
win.resize(900, 600);
596+
win.show();
597+
QVERIFY(QTest::qWaitForWindowExposed(&win));
598+
dock->raise();
599+
600+
s.prompt(QStringLiteral("list files"));
601+
s.channel->pushStdout(permissionRequest(41));
602+
QVERIFY(dock->isSessionWaiting(QStringLiteral("s1")));
603+
AiDockSessionStrip *strip = nullptr;
604+
QTRY_VERIFY((strip = win.findChild<AiDockSessionStrip *>()) != nullptr);
605+
QTRY_VERIFY(!strip->waitingAt(0)); // on screen: the user sees the prompt
606+
607+
other->raise();
608+
QTRY_VERIFY(strip->waitingAt(0));
609+
QCOMPARE(dock->projectMark(), AiAgentDock::ProjectMark::Waiting);
610+
611+
dock->raise();
612+
QTRY_VERIFY(!strip->waitingAt(0));
613+
QCOMPARE(dock->projectMark(), AiAgentDock::ProjectMark::None);
614+
}
615+
577616
namespace {
578617

579618
// The model catalogue session/new reports (Opus current unless told otherwise).

0 commit comments

Comments
 (0)