Skip to content

Agent Zero AI framework

Fit Desktop display to the active canvas

Alessandrodffaecae1374
diff --git a/helpers/virtual_desktop.py b/helpers/virtual_desktop.py
index a1a4155a2..27efe8885 100644
--- a/helpers/virtual_desktop.py
+++ b/helpers/virtual_desktop.py
@@ -23,7 +23,6 @@ MAX_WIDTH = 1920
MAX_HEIGHT = 1080
MIN_WIDTH = 360
MIN_HEIGHT = 240
-MIN_DESKTOP_ASPECT_RATIO = 4 / 3
SESSION_PATH = "/desktop/session"
XPRA_HTML_ROOT_CANDIDATES = (
Path("/usr/share/xpra/www"),
@@ -234,38 +233,6 @@ def normalize_size(
)
-def normalize_desktop_display_size(
- width: int | float | str,
- height: int | float | str,
- *,
- max_width: int = MAX_WIDTH,
- max_height: int = MAX_HEIGHT,
- min_width: int = MIN_WIDTH,
- min_height: int = MIN_HEIGHT,
- min_aspect_ratio: float = MIN_DESKTOP_ASPECT_RATIO,
-) -> tuple[int, int]:
- normalized_width, normalized_height = normalize_size(
- width,
- height,
- max_width=max_width,
- max_height=max_height,
- min_width=min_width,
- min_height=min_height,
- )
- if normalized_height <= 0:
- return normalized_width, normalized_height
- if normalized_width / normalized_height >= min_aspect_ratio:
- return normalized_width, normalized_height
- return normalize_size(
- DEFAULT_WIDTH,
- DEFAULT_HEIGHT,
- max_width=max_width,
- max_height=max_height,
- min_width=min_width,
- min_height=min_height,
- )
-
-
def resize_display(
*,
display: int,
diff --git a/helpers/virtual_desktop.py.dox.md b/helpers/virtual_desktop.py.dox.md
index dc43919d4..cc32444f6 100644
--- a/helpers/virtual_desktop.py.dox.md
+++ b/helpers/virtual_desktop.py.dox.md
@@ -28,7 +28,6 @@
- `find_xpra_html_root() -> Path | None`
- `_package_installed(package: str) -> bool`
- `normalize_size(width: int | float | str, height: int | float | str, max_width: int=..., max_height: int=..., min_width: int=..., min_height: int=...) -> tuple[int, int]`
-- `normalize_desktop_display_size(width: int | float | str, height: int | float | str, max_width: int=..., max_height: int=..., min_width: int=..., min_height: int=..., min_aspect_ratio: float=...) -> tuple[int, int]`
- `resize_display(display: int, width: int, height: int, max_width: int=..., max_height: int=..., window_class: str=..., keys: tuple[str, ...]=..., xauthority: str=..., home: str=..., settle_seconds: float=...) -> dict[str, Any]`
- `_ensure_xrandr_mode(env: dict[str, str], width: int, height: int) -> None`
- `_select_xrandr_mode(env: dict[str, str], width: int, height: int) -> subprocess.CompletedProcess[str]`
diff --git a/plugins/_desktop/AGENTS.md b/plugins/_desktop/AGENTS.md
index 35f2f3327..7a1db2d6c 100644
--- a/plugins/_desktop/AGENTS.md
+++ b/plugins/_desktop/AGENTS.md
@@ -14,6 +14,7 @@
## Local Contracts
- Preserve session startup, cleanup, and route protection for desktop access.
+- Resize the system desktop to the active canvas or modal dimensions through `virtual_desktop.resize_display`, retaining its minimum/maximum bounds. Do not replace narrow or portrait viewport sizes with a default landscape resolution.
- Apply shared `virtual_desktop.XPRA_START_ENV` defaults to Xpra launches and restarts while preserving inherited overrides. Disable local shared-memory transport for the WebSocket viewer.
- Keep the Xpra server, client modules, and GTK introspection runtime present as one compatible stack; Xpra shadow sessions import all three even when users connect only through HTML5.
- Route APT commands through `system_packages.run_runtime_apt` so existing Kali containers repair from the build's snapshot. Preserve the installed Xpra component version. If GTK needs a missing ATK typelib, align ATK's version-locked libraries and any installed optional components with the build's pinned snapshot version; do not fetch dependencies from rolling.
diff --git a/plugins/_desktop/helpers/desktop_session.py b/plugins/_desktop/helpers/desktop_session.py
index 63ca7060a..bf66a8228 100644
--- a/plugins/_desktop/helpers/desktop_session.py
+++ b/plugins/_desktop/helpers/desktop_session.py
@@ -430,8 +430,6 @@ class DesktopSessionManager:
if not session:
return {"ok": False, "error": "LibreOffice desktop session not found."}
is_system_desktop = session.session_id == SYSTEM_SESSION_ID and session.extension == "desktop"
- if is_system_desktop:
- width, height = virtual_desktop.normalize_desktop_display_size(width, height)
result = virtual_desktop.resize_display(
display=session.display,
width=width,
diff --git a/tests/test_office_canvas_setup.py b/tests/test_office_canvas_setup.py
index 06be9ec3e..a76a35a55 100644
--- a/tests/test_office_canvas_setup.py
+++ b/tests/test_office_canvas_setup.py
@@ -310,7 +310,6 @@ def test_desktop_plugin_owns_routes_runtime_surface_and_state_paths():
assert "canvas?.clientWidth || canvas?.width" in desktop_store
assert "overflow: auto !important;" in desktop_store
assert "Installing Agent Zero Desktop runtime dependencies" in desktop_session
- assert "normalize_desktop_display_size" in desktop_session
assert "__a0XpraOffsetWarnPatched" in desktop_store
assert "window does not fit in canvas, offsets" in desktop_store
assert "decode error packet" in desktop_store
diff --git a/tests/test_office_desktop_state.py b/tests/test_office_desktop_state.py
index 506b277b9..81ef94550 100644
--- a/tests/test_office_desktop_state.py
+++ b/tests/test_office_desktop_state.py
@@ -318,12 +318,31 @@ def test_desktop_prompt_context_recommends_structured_state_before_screenshots()
assert "before any coordinate action" not in context
-def test_virtual_desktop_system_display_normalization_rejects_portrait_viewports():
- assert virtual_desktop.normalize_desktop_display_size(395, 1080) == (
- virtual_desktop.DEFAULT_WIDTH,
- virtual_desktop.DEFAULT_HEIGHT,
[email protected]("size", [(395, 1080), (575, 672), (980, 850), (1600, 900)])
+def test_system_desktop_resize_preserves_canvas_dimensions(monkeypatch, tmp_path, size):
+ from plugins._desktop.helpers import desktop_session
+
+ session = types.SimpleNamespace(
+ session_id=desktop_session.SYSTEM_SESSION_ID, extension="desktop",
+ display=120, profile_dir=tmp_path, width=1440, height=900,
)
- assert virtual_desktop.normalize_desktop_display_size(1600, 900) == (1600, 900)
+ manager = desktop_session.DesktopSessionManager()
+ monkeypatch.setattr(manager, "get", lambda _id: session)
+ monkeypatch.setattr(manager, "_xauthority", lambda _session: "")
+ calls = []
+
+ def resize_display(**kwargs):
+ calls.append(kwargs)
+ return {"ok": True, "width": kwargs["width"], "height": kwargs["height"]}
+
+ monkeypatch.setattr(virtual_desktop, "resize_display", resize_display)
+ result = manager.resize(session.session_id, *size)
+
+ assert (calls[0]["width"], calls[0]["height"]) == size
+ assert calls[0]["window_class"] == ""
+ assert calls[0]["keys"] == ()
+ assert (result["width"], result["height"]) == size
+ assert (session.width, session.height) == size
@pytest.mark.parametrize(