Skip to content

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.

feat(pets): show the control strip only while it is useful

rubenluetke10-beep0c90cf370473
diff --git a/docs/pets.md b/docs/pets.md
index 24e970de5e..c1aa64e156 100644
--- a/docs/pets.md
+++ b/docs/pets.md
@@ -18,7 +18,10 @@ one click.
- **The figure.** It reacts to Jarvis in real time (see *States*). It can be
dragged anywhere, and its position is remembered per monitor
(`[overlay.mascot] position_*`, shared with the mascot).
-- **The control strip** under the figure, from left to right:
+- **The control strip** under the figure. At rest only the figure shows; the
+ strip appears while Jarvis is listening, thinking, talking or dictating and
+ while the pointer is on the figure or the strip (it leaves 0.6 s after the
+ pointer does). With the pet "None" it always shows. From left to right:
- pen: raise the main window and open a new chat (`ComposeRequested`);
- microphone: mute Jarvis's microphone (`VoiceMuteToggleRequested`, mirrored
from `VoiceMuteChanged`);
@@ -39,7 +42,7 @@ one click.
- **The pet "None"** (`pet_id = "none"`) shows the control strip and the
card without a figure.
-The pet stays on screen while Jarvis is idle. The global shortcut
+The pet stays on screen while Jarvis is idle (its strip does not). The global shortcut
(`[trigger] hotkey_pet_toggle`, default `alt+win+p`) hides it or brings it
back and to the front; hiding lasts until the next app start. The shortcut is
changed on the My Pets page (Customize); an empty value switches it off. On
diff --git a/tests/unit/ui/test_pet_overlay_surface.py b/tests/unit/ui/test_pet_overlay_surface.py
index 7b7910d316..3c3d27e048 100644
--- a/tests/unit/ui/test_pet_overlay_surface.py
+++ b/tests/unit/ui/test_pet_overlay_surface.py
@@ -498,3 +498,83 @@ def test_the_host_dispatches_status_ops_including_the_old_keys() -> None:
("clear_status", 0.5),
("clear_status", 1.5),
]
+
+
+# --- The control strip shows only while it is useful -------------------------
+
+
+class _Strip:
+ """Records what the overlay asks of its pet strip."""
+
+ def __init__(self) -> None:
+ self.calls: list[str] = []
+ self.pointer_inside = False
+
+ def set_state(self, **_kwargs: object) -> None:
+ pass
+
+ def show(self) -> None:
+ self.calls.append("show")
+
+ def hide(self) -> None:
+ self.calls.append("hide")
+
+ def hide_after_grace(self) -> None:
+ self.calls.append("grace")
+
+
+def _pet_with_strip(pet_id: str = "gigi") -> tuple[OrbOverlay, _Strip]:
+ pet = OrbOverlay(style="pet", pet_id=pet_id)
+ strip = _Strip()
+ pet._controls = strip # type: ignore[assignment]
+ pet._window_mapped = lambda: True # type: ignore[method-assign]
+ return pet, strip
+
+
+def test_an_idle_pet_shows_only_the_figure() -> None:
+ pet, strip = _pet_with_strip()
+ pet._mode = "idle"
+ assert pet._pet_strip_wanted() is False
+ pet._sync_controls_visibility()
+ assert strip.calls == ["grace"]
+
+
[email protected]("mode", ["listen", "think", "speak", "dictate", "dictate_transcribing"])
+def test_the_strip_joins_the_pet_while_jarvis_is_engaged(mode: str) -> None:
+ pet, strip = _pet_with_strip()
+ pet._mode = mode
+ pet._sync_controls_visibility()
+ assert strip.calls == ["show"]
+
+
+def test_hovering_the_pet_brings_the_strip_and_leaving_lets_it_go() -> None:
+ pet, strip = _pet_with_strip()
+ pet._mode = "idle"
+ pet._on_orb_pointer_enter()
+ assert strip.calls == ["show"]
+ assert pet._pet_strip_wanted() is True
+ pet._on_orb_pointer_leave()
+ assert strip.calls == ["show", "grace"]
+ assert pet._pet_strip_wanted() is False
+
+
+def test_the_pointer_on_the_strip_keeps_it_up() -> None:
+ pet, strip = _pet_with_strip()
+ pet._mode = "idle"
+ strip.pointer_inside = True
+ assert pet._pet_strip_wanted() is True
+
+
+def test_the_figureless_pet_always_keeps_its_strip() -> None:
+ pet, strip = _pet_with_strip(pet_id="none")
+ pet._mode = "idle"
+ pet._sync_controls_visibility()
+ assert strip.calls == ["show"]
+
+
+def test_a_hidden_pet_hides_its_strip_even_mid_conversation() -> None:
+ pet, strip = _pet_with_strip()
+ pet._mode = "speak"
+ pet._window_mapped = lambda: False # type: ignore[method-assign]
+ pet._sync_controls_visibility()
+ assert strip.calls == ["hide"]
diff --git a/ui/orb/overlay.py b/ui/orb/overlay.py
index a7dfbf46e0..fae52525fe 100644
--- a/ui/orb/overlay.py
+++ b/ui/orb/overlay.py
@@ -2375,13 +2375,17 @@ class PetControlStrip(OrbControlRow):
"""The pet's control strip — see ``ui.orb.controls`` (``PET_ACTIONS``).
The voice orb's row with three differences that make it the pet's own: it
- stays up whenever the pet is on screen (a companion, not a pop-up), its
- empty area is a drag handle for the whole group (the only one when the pet
- is "None"), and its orb pulses with the live audio level through cached
- frames, so a strip at rest never repaints.
+ shows only while the overlay's ``keep_visible`` says so (Jarvis is engaged,
+ the pointer is on the pet, or there is no figure to hover), its empty area
+ is a drag handle for the whole group (the only one when the pet is "None"),
+ and its orb pulses with the live audio level through cached frames, so a
+ strip at rest never repaints.
"""
GUARDED_ACTIONS: tuple[str, ...] = ("orb",)
+ #: Longer than the orb row's: the pointer crosses a gap between the
+ #: figure and the strip, and a strip that vanishes on the way is a miss.
+ HOVER_GRACE_MS = 600
def __init__(
self,
@@ -2396,8 +2400,10 @@ class PetControlStrip(OrbControlRow):
on_drag_motion: Callable[[Any], None] | None = None,
on_drag_release: Callable[[Any], None] | None = None,
on_context: Callable[[Any], None] | None = None,
+ keep_visible: Callable[[], bool] | None = None,
) -> None:
self._scale = float(scale)
+ self._keep_visible = keep_visible
self._on_drag_press = on_drag_press
self._on_drag_motion = on_drag_motion
self._on_drag_release = on_drag_release
@@ -2491,11 +2497,17 @@ class PetControlStrip(OrbControlRow):
# -- pointer ----------------------------------------------------------
def hide_after_grace(self) -> None:
- """The strip stays while the pet is on screen; the pointer leaving is not a reason."""
+ """Hide after the grace, unless the overlay still wants the strip up."""
+ if self._keep_visible is not None and self._keep_visible():
+ return
+ super().hide_after_grace()
- def _on_leave(self, _event: tk.Event) -> None:
- self._pointer_inside = False
- self._set_hovered(None)
+ def _grace_elapsed(self) -> None:
+ # The conversation may have started during the grace.
+ if self._keep_visible is not None and self._keep_visible():
+ self._hide_after_id = None
+ return
+ super()._grace_elapsed()
def _on_press(self, event: tk.Event) -> None:
super()._on_press(event)
@@ -3275,6 +3287,7 @@ class OrbOverlay:
on_drag_motion=self._on_drag_motion,
on_drag_release=self._on_drag_release,
on_context=self._on_right_click,
+ keep_visible=self._pet_strip_wanted,
)
else:
row = OrbControlRow(
@@ -3302,11 +3315,27 @@ class OrbOverlay:
if row is not None:
row.show()
+ def _pet_strip_wanted(self) -> bool:
+ """Should the pet's strip be up right now?
+
+ Only while it is useful: Jarvis is listening, thinking or talking, the
+ pointer is on the figure or the strip, or the pet is "None" (the strip
+ is all there is, so hiding it would leave nothing to hover).
+ """
+ if self._pet_id == NO_PET_ID:
+ return True
+ if self._mode in PET_VOICE_MODES or self._mode in PET_THINK_MODES:
+ return True
+ row = self._controls
+ return self._pointer_over_orb or (row is not None and row.pointer_inside)
+
def _on_orb_pointer_leave(self, _event: tk.Event | None = None) -> None:
self._pointer_over_orb = False
row = self._controls
- if row is None or self._style == "pet":
- # The pet's strip stays while the pet does.
+ if row is None:
+ return
+ if self._style == "pet":
+ row.hide_after_grace() # a no-op while the strip is still wanted
return
# A live conversation keeps the controls out: hanging up is the one
# thing the user reaches for mid-call, and hunting for a row that hides
@@ -3323,11 +3352,13 @@ class OrbOverlay:
active = self._mode in ("listen", "think", "speak")
row.set_state(active=active)
if self._style == "pet":
- # The pet's strip lives exactly as long as the pet is on screen.
- if self._window_mapped():
+ # The pet alone at rest; its strip joins it while it is useful.
+ if not self._window_mapped():
+ row.hide()
+ elif self._pet_strip_wanted():
row.show()
else:
- row.hide()
+ row.hide_after_grace()
return
# Never on its own: the row is the orb's controls, so a mode change
# arriving while the sphere is withdrawn must not float four buttons
@@ -4065,6 +4096,8 @@ class OrbOverlay:
return
renderer.load(pet_id)
self._refit_pet_window()
+ # "None" keeps its strip up; a figure lets it rest hidden again.
+ self._sync_controls_visibility()
def _apply_pet_look(self) -> None:
if self._style != "pet":