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.

fix(pets): drag the control strip from any control

rubenluetke10-beep4a6989afb317
diff --git a/tests/unit/ui/test_pet_strip_drag.py b/tests/unit/ui/test_pet_strip_drag.py
new file mode 100644
index 0000000000..62cf661cc4
--- /dev/null
+++ b/tests/unit/ui/test_pet_strip_drag.py
@@ -0,0 +1,94 @@
+"""The pet strip is a drag handle everywhere, its controls included.
+
+With the pet "None" the strip is the only thing on screen and it is all
+controls, so a press on a control must still be able to move the pet: a press
+that travels past ``DRAG_THRESHOLD_PX`` is a drag (the control does not fire),
+one that does not is a click. No real Tk window — the handlers are called
+directly on a strip whose window parts are left empty.
+"""
+
+from __future__ import annotations
+
+import sys
+from types import SimpleNamespace
+
+import pytest
+
+if sys.platform != "win32":
+ pytest.skip("ui.orb.overlay pulls in Win32 helpers", allow_module_level=True)
+
+from ui.orb import controls as orb_controls
+from ui.orb.overlay import DRAG_THRESHOLD_PX, PetControlStrip
+
+
+class _Recorder:
+ def __init__(self) -> None:
+ self.calls: list[tuple[str, object]] = []
+
+ def press(self, event: object) -> None:
+ self.calls.append(("press", event))
+
+ def motion(self, event: object) -> None:
+ self.calls.append(("motion", event))
+
+ def release(self, event: object) -> None:
+ self.calls.append(("release", event))
+
+ def action(self, name: str) -> None:
+ self.calls.append(("action", name))
+
+ def kinds(self) -> list[str]:
+ return [kind for kind, _ in self.calls]
+
+
+def _strip(rec: _Recorder) -> PetControlStrip:
+ strip = PetControlStrip.__new__(PetControlStrip)
+ strip._scale = 1.0
+ strip._state = orb_controls.PetStripState()
+ strip._canvas = None
+ strip._top = None
+ strip._pressed_action = None
+ strip._click_block_until = 0.0
+ strip._dragging = False
+ strip._drag_moved = False
+ strip._press_root = (0, 0)
+ strip._on_drag_press = rec.press
+ strip._on_drag_motion = rec.motion
+ strip._on_drag_release = rec.release
+ strip._on_action = rec.action
+ return strip
+
+
+def _mic_point() -> tuple[int, int]:
+ layout = orb_controls.pet_strip_layout(1.0)
+ _x0, y0, _x1, y1 = layout.pill
+ for action, sx0, sx1 in layout.slots:
+ if action == "mic_mute":
+ return (sx0 + sx1) // 2, (y0 + y1) // 2
+ raise AssertionError("no mic slot")
+
+
+def _event(x: int, y: int, dx: int = 0) -> SimpleNamespace:
+ return SimpleNamespace(x=x + dx, y=y, x_root=500 + x + dx, y_root=500 + y)
+
+
+def test_a_short_press_on_a_control_is_a_click() -> None:
+ rec = _Recorder()
+ strip = _strip(rec)
+ x, y = _mic_point()
+ strip._on_press(_event(x, y))
+ strip._on_drag_motion_event(_event(x, y, dx=DRAG_THRESHOLD_PX // 4))
+ strip._on_release(_event(x, y))
+ assert ("action", "mic_mute") in rec.calls
+ assert "motion" not in rec.kinds()
+
+
+def test_a_drag_that_starts_on_a_control_moves_the_pet_and_fires_nothing() -> None:
+ rec = _Recorder()
+ strip = _strip(rec)
+ x, y = _mic_point()
+ strip._on_press(_event(x, y))
+ strip._on_drag_motion_event(_event(x, y, dx=DRAG_THRESHOLD_PX + 4))
+ strip._on_drag_motion_event(_event(x, y, dx=DRAG_THRESHOLD_PX + 40))
+ strip._on_release(_event(x, y, dx=DRAG_THRESHOLD_PX + 40))
+ assert rec.kinds() == ["press", "motion", "motion", "release"]
diff --git a/ui/orb/overlay.py b/ui/orb/overlay.py
index fb88134cc0..03ab8c54df 100644
--- a/ui/orb/overlay.py
+++ b/ui/orb/overlay.py
@@ -2409,6 +2409,10 @@ class PetControlStrip(OrbControlRow):
self._on_drag_release = on_drag_release
self._on_context = on_context
self._dragging = False
+ # The press point (screen px) and whether the pointer has since
+ # travelled far enough to make the press a drag rather than a click.
+ self._drag_moved = False
+ self._press_root: tuple[int, int] = (0, 0)
super().__init__(parent, orb_x, orb_y, orb_w, orb_h)
# -- layout hooks -----------------------------------------------------
@@ -2510,21 +2514,37 @@ class PetControlStrip(OrbControlRow):
super()._grace_elapsed()
def _on_press(self, event: tk.Event) -> None:
+ # Every press may become a drag — on a control too. The strip is all
+ # controls, so with the pet "None" there would otherwise be nothing
+ # to grab. A press that never travels past DRAG_THRESHOLD_PX stays a
+ # click; one that does moves the pet and the control does not fire.
super()._on_press(event)
- self._dragging = self._pressed_action is None
- if self._dragging and self._on_drag_press is not None:
+ self._dragging = True
+ self._drag_moved = False
+ self._press_root = (event.x_root, event.y_root)
+ if self._on_drag_press is not None:
self._on_drag_press(event)
def _on_drag_motion_event(self, event: tk.Event) -> None:
- if self._dragging and self._on_drag_motion is not None:
+ if not self._dragging:
+ return
+ if not self._drag_moved:
+ px, py = self._press_root
+ if abs(event.x_root - px) + abs(event.y_root - py) < DRAG_THRESHOLD_PX:
+ return
+ self._drag_moved = True
+ self._set_hovered(None)
+ if self._on_drag_motion is not None:
self._on_drag_motion(event)
def _on_release(self, event: tk.Event) -> None:
- if self._dragging:
- self._dragging = False
+ dragging, moved = self._dragging, self._drag_moved
+ self._dragging = False
+ self._drag_moved = False
+ if dragging and self._on_drag_release is not None:
+ self._on_drag_release(event)
+ if moved:
self._pressed_action = None
- if self._on_drag_release is not None:
- self._on_drag_release(event)
return
super()._on_release(event)