Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.
Python agent-orchestrationai-agentai-coding-assistantclaude-codecoding-agentcomputer-usedesktop-applocal-firstmcppersonal-jarvisvoice-assistantvoice-coding
fix(appshot): keep tiny and thin captures visible in the corner card
rubenluetke10-beepa1a7b757f39e
diff --git a/jarvis/cu/indicator/renderer.py b/jarvis/cu/indicator/renderer.pyindex 42f49984a0..e2b41ad37c 100644--- a/jarvis/cu/indicator/renderer.py+++ b/jarvis/cu/indicator/renderer.py@@ -161,6 +161,12 @@ _SNAP_FLY_MS = 430_SNAP_TOTAL_MS = _SNAP_FLY_START_MS + _SNAP_FLY_MS_SNAP_THUMB_W = 320_SNAP_THUMB_MAX_H = 240+#: The card never gets smaller than this, however thin or tiny the capture:+#: a 1280x18 strip still lands as a card with room for its buttons. The+#: picture sits centred on a neutral backdrop and is only ever scaled down.+_CARD_MIN_W = 200.0+_CARD_MIN_H = 112.0+_CARD_BACKDROP = QColor(28, 28, 32, 242)_SNAP_MARGIN = 28_SNAP_RADIUS = 12.0@@ -251,13 +257,70 @@ def _screen_named(name: str):return QGuiApplication.primaryScreen()-def _paint_card(painter: QPainter, rect: QRectF, thumb: QImage, radius: float, ring: float) -> None:- """The thumbnail with rounded corners and a white ring — flight and card."""+def _card_geometry(+ width: float,+ height: float,+ *,+ max_w: float = _SNAP_THUMB_W,+ max_h: float = _SNAP_THUMB_MAX_H,+ min_w: float | None = None,+ min_h: float | None = None,+) -> tuple[float, float, float, float]:+ """``(card w, card h, picture w, picture h)`` for a picture of ``width`` x ``height``.++ The picture keeps its aspect and is scaled down to fit, never up: a tiny+ capture shows at its real size. The card around it is at least+ ``min_w`` x ``min_h``, so a sliver or a few pixels never vanish.+ """+ min_w = _CARD_MIN_W if min_w is None else min_w+ min_h = _CARD_MIN_H if min_h is None else min_h+ width, height = max(1.0, float(width)), max(1.0, float(height))+ scale = min(1.0, max_w / width, max_h / height)+ pw, ph = width * scale, height * scale+ return min(max_w, max(pw, min_w)), min(max_h, max(ph, min_h)), pw, ph+++def _centred(box: QRectF, width: float, height: float) -> QRectF:+ return QRectF(+ box.center().x() - width / 2.0, box.center().y() - height / 2.0, width, height+ )+++def _paint_card(+ painter: QPainter,+ rect: QRectF,+ thumb: QImage,+ radius: float,+ ring: float,+ picture: QRectF | None = None,+) -> None:+ """The thumbnail with rounded corners and a white ring — flight and card.++ ``picture`` is where the image goes inside ``rect``; by default it fills+ ``rect`` as far as its aspect allows. Whatever it leaves free shows the+ neutral backdrop instead of a stretched image.+ """+ if picture is None and not thumb.isNull():+ width, height = float(thumb.width()), float(thumb.height())+ scale = min(rect.width() / width, rect.height() / height)+ picture = _centred(rect, width * scale, height * scale)clip = QPainterPath()clip.addRoundedRect(rect, radius, radius)painter.save()painter.setClipPath(clip)- painter.drawImage(rect, thumb)+ framed = picture is not None and (+ picture.width() < rect.width() - 0.75 or picture.height() < rect.height() - 0.75+ )+ if framed:+ painter.fillRect(rect, _CARD_BACKDROP)+ painter.drawImage(picture if picture is not None else rect, thumb)+ if framed:+ # A hairline marks where a small picture ends on the backdrop.+ edge = QPen(QColor(255, 255, 255, 56))+ edge.setWidthF(1.0)+ painter.setPen(edge)+ painter.setBrush(Qt.BrushStyle.NoBrush)+ painter.drawRect(picture.adjusted(-0.5, -0.5, 0.5, 0.5))painter.restore()if ring > 0.0:pen = QPen(QColor(255, 255, 255, int(235 * ring)))@@ -312,16 +375,10 @@ class _SnapWindow(QWidget):w, h = float(screen.geometry().width()), float(screen.geometry().height())fx, fy, fw, fh = (max(0.0, min(1.0, float(v))) for v in rect_frac)self._src = QRectF(fx * w, fy * h, max(1.0, fw * w), max(1.0, fh * h))- aspect = (- thumb.height() / max(1, thumb.width())- if not thumb.isNull()- else (fh * h) / max(fw * w, 1e-6)- )- tw = float(_SNAP_THUMB_W)- th = tw * aspect- if th > _SNAP_THUMB_MAX_H:- th = float(_SNAP_THUMB_MAX_H)- tw = th / max(aspect, 1e-6)+ # The captured area is the picture's real size on screen.+ tw, th, pw, ph = _card_geometry(self._src.width(), self._src.height())+ #: The picture inside the landed card (the rest is backdrop).+ self.picture_size = (pw, ph)# Land inside the work area, so the card never sits under the taskbar.avail = screen.availableGeometry()geo = screen.geometry()@@ -398,6 +455,11 @@ class _SnapWindow(QWidget):_lerp(self._src.width(), self._dst.width(), fly),_lerp(self._src.height(), self._dst.height(), fly),)+ picture = _centred(+ rect,+ _lerp(self._src.width(), self.picture_size[0], fly),+ _lerp(self._src.height(), self.picture_size[1], fly),+ )if not self._thumb.isNull():if fly > 0.0:for spread, alpha in ((10.0, 18), (5.0, 30), (2.0, 46)):@@ -406,7 +468,7 @@ class _SnapWindow(QWidget):painter.setBrush(QColor(0, 0, 0, int(alpha * fly)))radius = _SNAP_RADIUS * fly + spreadpainter.drawRoundedRect(shadow, radius, radius)- _paint_card(painter, rect, self._thumb, _SNAP_RADIUS * fly, fly)+ _paint_card(painter, rect, self._thumb, _SNAP_RADIUS * fly, fly, picture)flash = 1.0 - _ease_out_cubic(t / _SNAP_FLASH_MS)if self._flash and flash > 0.0:@@ -435,12 +497,10 @@ def _drag_preview(thumb: QImage, card: QRectF, grab: QPointF, dpr: float) -> tupspot the user pressed, mapped onto the smaller picture, so the picturedoes not jump out from under the pointer."""- aspect = thumb.height() / max(1, thumb.width()) if not thumb.isNull() else 0.6- w = _DRAG_PREVIEW_W- h = w * aspect- if h > _DRAG_PREVIEW_H:- h = _DRAG_PREVIEW_H- w = h / max(aspect, 1e-6)+ w, h, _pw, _ph = _card_geometry(+ card.width(), card.height(), max_w=_DRAG_PREVIEW_W, max_h=_DRAG_PREVIEW_H,+ min_w=_DRAG_PREVIEW_W * 0.55, min_h=_DRAG_PREVIEW_H * 0.4,+ )pad = _DRAG_PREVIEW_PADdpr = max(1.0, float(dpr))size = QPointF(w + 2 * pad, h + 2 * pad)@@ -515,23 +575,24 @@ def _drag_copy_cursor(dpr: float) -> QPixmap:return canvas-def _card_rect(screen, thumb: QImage) -> QRectF:- """Where the resting card sits: the bottom-right of ``screen``'s work area.+def _card_rect(screen, thumb: QImage) -> tuple[QRectF, tuple[float, float]]:+ """Where the resting card sits, and its picture's size inside it.- Absolute (virtual-desktop) logical coordinates. Shared by the shutter- flight's landing spot and a card that comes back after the editor.+ The card is at the bottom-right of ``screen``'s work area, in absolute+ (virtual-desktop) logical coordinates. Used by a card that comes back+ after the editor; the thumbnail's pixels stand for the picture's size."""- aspect = thumb.height() / max(1, thumb.width()) if not thumb.isNull() else 0.6- tw = float(_SNAP_THUMB_W)- th = tw * aspect- if th > _SNAP_THUMB_MAX_H:- th = float(_SNAP_THUMB_MAX_H)- tw = th / max(aspect, 1e-6)+ dpr = float(screen.devicePixelRatio() or 1.0)+ natural = (+ (thumb.width() / dpr, thumb.height() / dpr) if not thumb.isNull() else (320.0, 192.0)+ )+ tw, th, pw, ph = _card_geometry(*natural)# Inside the work area, so the card never sits under the taskbar.avail = screen.availableGeometry()right = float(avail.right() + 1)bottom = float(avail.bottom() + 1)- return QRectF(right - tw - _SNAP_MARGIN, bottom - th - _SNAP_MARGIN, tw, th)+ rect = QRectF(right - tw - _SNAP_MARGIN, bottom - th - _SNAP_MARGIN, tw, th)+ return rect, (pw, ph)def _stack_tops(@@ -599,8 +660,11 @@ class _CardWindow(QWidget):appshot_id: str = "",image: QImage | None = None,screen_name: str = "",+ picture_size: tuple[float, float] | None = None,) -> None:super().__init__(None)+ #: The picture inside the card; ``None`` = as large as its aspect allows.+ self.picture_size = picture_sizeself.setWindowFlags(Qt.WindowType.FramelessWindowHint| Qt.WindowType.WindowStaysOnTopHint@@ -904,7 +968,10 @@ class _CardWindow(QWidget):painter.setBrush(QColor(0, 0, 0, alpha))shadow = rect.adjusted(-spread, -spread + 3, spread, spread + 3)painter.drawRoundedRect(shadow, _SNAP_RADIUS + spread, _SNAP_RADIUS + spread)- _paint_card(painter, rect, self._thumb, _SNAP_RADIUS, 1.0)+ picture = (+ _centred(rect, *self.picture_size) if self.picture_size is not None else None+ )+ _paint_card(painter, rect, self._thumb, _SNAP_RADIUS, 1.0, picture)if self._status:self._paint_scrim(painter, rect, 150)self._paint_centered(painter, rect, self._status)@@ -1308,6 +1375,7 @@ class Renderer(QObject):screen_name: str,appshot_id: str = "",image: QImage | None = None,+ picture_size: tuple[float, float] | None = None,) -> _CardWindow:"""A new card at the bottom of the stack; the older ones move up."""card = _CardWindow(@@ -1320,6 +1388,7 @@ class Renderer(QObject):appshot_id=appshot_id,image=image,screen_name=screen_name,+ picture_size=picture_size,)self._cards.append(card)_emit(protocol.EVENT_CARD, open=True)@@ -1335,6 +1404,7 @@ class Renderer(QObject):screen_name=flight.screen_name,appshot_id=flight.appshot_id,image=flight.image,+ picture_size=flight.picture_size,).start()def _relayout(self) -> None:@@ -1417,8 +1487,13 @@ class Renderer(QObject):self._relayout()win.start()return+ rect, picture_size = _card_rect(screen, thumb)self._new_card(- _card_rect(screen, thumb), thumb, screen_name=screen.name(), appshot_id=appshot_id+ rect,+ thumb,+ screen_name=screen.name(),+ appshot_id=appshot_id,+ picture_size=picture_size,).start(slide_in=True)def card_action(self, card: _CardWindow, action: str) -> None:diff --git a/tests/unit/cu/indicator/test_card_geometry.py b/tests/unit/cu/indicator/test_card_geometry.pynew file mode 100644index 0000000000..d9ca9a53e3--- /dev/null+++ b/tests/unit/cu/indicator/test_card_geometry.py@@ -0,0 +1,32 @@+"""The corner card stays visible however small or thin the captured area is."""++from __future__ import annotations++import pytest++pytest.importorskip("PySide6")++from jarvis.cu.indicator import renderer # noqa: E402+++def test_a_thin_strip_still_lands_as_a_full_card() -> None:+ card_w, card_h, pic_w, pic_h = renderer._card_geometry(853, 12)+ assert (card_w, card_h) == (renderer._SNAP_THUMB_W, renderer._CARD_MIN_H)+ assert pic_w == renderer._SNAP_THUMB_W and pic_h < 5+++def test_a_tiny_area_keeps_its_real_size_inside_the_card() -> None:+ card_w, card_h, pic_w, pic_h = renderer._card_geometry(20, 20)+ assert (card_w, card_h) == (renderer._CARD_MIN_W, renderer._CARD_MIN_H)+ assert (pic_w, pic_h) == (20, 20) # never scaled up+++def test_a_tall_narrow_area_keeps_the_minimum_width() -> None:+ card_w, card_h, pic_w, pic_h = renderer._card_geometry(13, 400)+ assert card_w == renderer._CARD_MIN_W and card_h == renderer._SNAP_THUMB_MAX_H+ assert pic_h == renderer._SNAP_THUMB_MAX_H and pic_w < 10+++def test_an_ordinary_area_fills_its_card() -> None:+ card_w, card_h, pic_w, pic_h = renderer._card_geometry(900, 600)+ assert (card_w, card_h) == (pic_w, pic_h) == (320, pytest.approx(213.33, abs=0.01))diff --git a/tests/unit/cu/indicator/test_card_stack.py b/tests/unit/cu/indicator/test_card_stack.pyindex 7e7acf984f..8b8980c631 100644--- a/tests/unit/cu/indicator/test_card_stack.py+++ b/tests/unit/cu/indicator/test_card_stack.py@@ -64,10 +64,12 @@ def renderer(qt, monkeypatch):snap.finish_now()-def _shutter(r, shot_id: str, size: tuple[int, int] = (400, 240)) -> None:+def _shutter(+ r, shot_id: str, size: tuple[int, int] = (400, 240), rect: list[float] | None = None+) -> None:"""One appshot: the shutter flight, its finished picture, then it lands."""r.on_line(protocol.encode_command(- protocol.CMD_SNAP, monitor=[], rect=[0.1, 0.1, 0.5, 0.5], thumb=_b64_png(*size)+ protocol.CMD_SNAP, monitor=[], rect=rect or [0.1, 0.1, 0.5, 0.5], thumb=_b64_png(*size)))r.on_line(protocol.encode_command(protocol.CMD_SNAP_IMAGE, image=_b64_png(*size), id=shot_id))for snap in list(r._snaps):@@ -156,10 +158,13 @@ def test_a_gone_card_lets_the_ones_above_it_move_down(renderer) -> None:@needs_qt-def test_the_stack_holds_at_most_max_cards(renderer) -> None:+def test_the_stack_holds_at_most_max_cards(renderer, monkeypatch) -> None:r, _ = renderer+ # Flat cards, so the small offscreen screen has room for every slot.+ module = importlib.import_module("jarvis.cu.indicator.renderer")+ monkeypatch.setattr(module, "_CARD_MIN_H", 40.0)for n in range(protocol.MAX_CARDS + 1):- _shutter(r, f"{n:08x}", size=(400, 60))+ _shutter(r, f"{n:08x}", size=(400, 60), rect=[0.1, 0.1, 0.5, 0.05])staying = [card.appshot_id for card in r._cards if not card.leaving]assert len(staying) == protocol.MAX_CARDSassert "00000000" not in staying, "the oldest card leaves first"