From c60f351214e8804055b00534b62f9db15c35d084 Mon Sep 17 00:00:00 2001 From: Waozi Date: Mon, 28 Sep 2026 18:19:08 -0300 Subject: [PATCH] Zoom the whole app with Ctrl and the mouse wheel Ctrl with the wheel, or Ctrl with plus, minus, or zero, now steps the UI scale setting the Appearance slider edits, so the wheel moves the slider, persists, and scales the entire app like a browser page zoom. Kryon's zoom decides when the wheel means zoom and takes the wheel away from scrolling; the frame stores the result in ui_scale_tenths (50% to 250%) and hands it to the DPI state, where the zoom multiplies the display density: everything drawn scales, including widget text, and the layout is the window divided by the result, so the navigation switches between rail and bottom bar as it does when the window gets narrower or wider. The raylib runtime rebakes fonts at the scaled size so text stays sharp. The Appearance scale slider only moved the navigation breakpoint since the Ziran port; it scales the app again. app_zoom_behavior covers the policy on source, saved IR, C, C++, and Go; native_zoom_test drives the real binary on a private display with the wheel and keys, checks the layout scale, and reads the saved setting. --- Makefile | 11 +++ src/app/app_nav_state.zi | 7 +- src/app/app_settings.zi | 3 +- src/app/app_zoom.zi | 87 +++++++++++++++++++++ src/app/dpi_state.zi | 35 +++++++-- src/platform/app_host.zi | 28 ++++++- tests/app_zoom_behavior.zi | 96 ++++++++++++++++++++++++ tests/app_zoom_zi_test.sh | 74 ++++++++++++++++++ tests/native_zoom_test.py | 150 +++++++++++++++++++++++++++++++++++++ tests/native_zoom_test.sh | 7 ++ 10 files changed, 484 insertions(+), 14 deletions(-) create mode 100644 src/app/app_zoom.zi create mode 100644 tests/app_zoom_behavior.zi create mode 100644 tests/app_zoom_zi_test.sh create mode 100644 tests/native_zoom_test.py create mode 100755 tests/native_zoom_test.sh diff --git a/Makefile b/Makefile index a07d2ff16..695fb5c00 100644 --- a/Makefile +++ b/Makefile @@ -818,6 +818,10 @@ native-screenshot-test: $(TARGET) native-navigation-test: $(TARGET) sh tests/native_navigation_test.sh $(abspath $(TARGET)) +.PHONY: native-zoom-test +native-zoom-test: $(TARGET) + sh tests/native_zoom_test.sh $(abspath $(TARGET)) + kryon-host: $(KRYON_HOST_TARGET) # Generate Kryon's checked Ziran modules into Inbe's build tree. @@ -1779,6 +1783,13 @@ app-nav-state-zi-test: $(ZI2C_BIN) test: app-nav-state-zi-test +.PHONY: app-zoom-test +app-zoom-test: $(ZI2C_BIN) + @env -u DISPLAY -u WAYLAND_DISPLAY \ + sh tests/app_zoom_zi_test.sh $(ZIRAN_BUILD_DIR)/bin + +test: app-zoom-test + .PHONY: sync-safety-test sync-safety-test: $(ZI2C_BIN) @env -u DISPLAY -u WAYLAND_DISPLAY \ diff --git a/src/app/app_nav_state.zi b/src/app/app_nav_state.zi index 9621b7974..1c881750d 100644 --- a/src/app/app_nav_state.zi +++ b/src/app/app_nav_state.zi @@ -49,16 +49,15 @@ app_capture_navigation_viewport :: (app: *InnerBreeze, width: s32, } app.ui.view_width = width app.ui.view_height = height - scale := cast(float32)app.ui_scale_tenths / 10.0 - app.ui.desktop_mode = cast(s32)IsDesktopWidth(width, scale) + // The width is already the layout width: the window divided by the zoom. + app.ui.desktop_mode = cast(s32)IsDesktopWidth(width, 1.0) } app_navigation_desktop_mode :: (app: *InnerBreeze) -> s32 { if app != null && app.ui.view_height > 0 { return app.ui.desktop_mode } - scale := ifx app != null then cast(float32)app.ui_scale_tenths / 10.0 else 1.0 - return cast(s32)IsDesktopWidth(ifx app != null then app.ui.view_width else 0, scale) + return cast(s32)IsDesktopWidth(ifx app != null then app.ui.view_width else 0, 1.0) } #program_export diff --git a/src/app/app_settings.zi b/src/app/app_settings.zi index cc542f07e..018401930 100644 --- a/src/app/app_settings.zi +++ b/src/app/app_settings.zi @@ -78,8 +78,7 @@ load_bottom_nav_routes :: (app: *InnerBreeze) { SettingsCacheInt("bottom_nav_route_2", APP_NAV_ROUTE_PRACTICE) app.bottom_nav_routes[3] = SettingsCacheInt("bottom_nav_route_3", APP_NAV_ROUTE_SETTINGS) - scale := cast(float32)app.ui_scale_tenths / 10.0 - profile_allowed := DesktopPlatform() != 0 && IsDesktopWidth(app.ui.view_width, scale) + profile_allowed := DesktopPlatform() != 0 && IsDesktopWidth(app.ui.view_width, 1.0) app.bottom_nav_route_count = BottomNavSanitize( app.bottom_nav_routes[:], app.bottom_nav_route_count, profile_allowed) } diff --git a/src/app/app_zoom.zi b/src/app/app_zoom.zi new file mode 100644 index 000000000..a358af71a --- /dev/null +++ b/src/app/app_zoom.zi @@ -0,0 +1,87 @@ +#import "dpi" +#import "session" +#import "zoom" + +using DPIPlatform; + +// Ctrl and the mouse wheel zoom the whole app as a browser does. Kryon's +// zoom decides when the wheel means zoom and how far one notch goes; this +// keeps the result in the same UI scale setting the appearance slider edits, +// so a wheel step moves the slider, persists, and rescales every metric. +UI_SCALE_MINIMUM_TENTHS :: 5; +UI_SCALE_MAXIMUM_TENTHS :: 25; + +zoom_configured_slot: s32; +zoom_configured_epoch: u64; + +// The scale chosen in Appearance, in tenths, as a zoom factor: 1.0 for 100%. +// The frame applies it as the DPI zoom, so it scales everything drawn and the +// layout is the window divided by it, as a browser page zoom does. +#program_export +UserScale :: (tenths: s32) -> float32 { + if tenths <= 0 { + return 1.0 + } + return cast(float32)tenths / 10.0 +} + +app_zoom_configure :: (session: Session) { + if session.slot == zoom_configured_slot && + session.epoch == zoom_configured_epoch { + return + } + props: ZoomProps + props.minimum = cast(float32)UI_SCALE_MINIMUM_TENTHS / 10.0 + props.maximum = cast(float32)UI_SCALE_MAXIMUM_TENTHS / 10.0 + props.step = 0.1 + unused ZoomConfigure(session, props) + zoom_configured_slot = session.slot + zoom_configured_epoch = session.epoch +} + +AppZoomResult :: struct { + wheel: float32 + tenths: s32 + changed: bool +} + +// One frame of zoom input: the saved scale in tenths, the wheel movement, the +// held modifier bits, and the zoom shortcut key pressed this frame (0 for +// none). The result holds the wheel movement left for scrolling, which is none +// when Ctrl held it for zoom, and the scale to save when it changed. +#program_export +app_zoom_frame :: (session: Session, platform: DPIPlatform, tenths: s32, + wheel: float32, modifiers: s32, key: s32) -> AppZoomResult { + result: AppZoomResult + result.wheel = wheel + result.tenths = tenths + if !SessionValid(session) { + return result + } + app_zoom_configure(session) + + // The saved setting is the truth; the slider changes it without telling + // the zoom, so bring the zoom to it before it reacts to the wheel. + unused ZoomSet(session, UserScale(tenths)) + + consumed := ZoomWheel(session, platform, wheel, modifiers) + if key != 0 && ZoomKey(session, platform, key, modifiers) { + consumed = true + } + + next := cast(s32)(ZoomFactor(session) * 10.0 + 0.5) + if next < UI_SCALE_MINIMUM_TENTHS { + next = UI_SCALE_MINIMUM_TENTHS + } + if next > UI_SCALE_MAXIMUM_TENTHS { + next = UI_SCALE_MAXIMUM_TENTHS + } + if next != tenths { + result.tenths = next + result.changed = true + } + if consumed { + result.wheel = 0.0 + } + return result +} diff --git a/src/app/dpi_state.zi b/src/app/dpi_state.zi index 1766dc55c..f8832e748 100644 --- a/src/app/dpi_state.zi +++ b/src/app/dpi_state.zi @@ -2,6 +2,7 @@ #import "geometry" #import, file "../platform/environment.zi"; #import, file "../platform/raylib_host.zi"; +#import, file "../../build/packages/kryon/src/backend/raylib_runtime.zi"; raylib :: #system_library "raylib"; IsWindowReady :: () -> bool #foreign raylib; GetWindowScaleDPI :: () -> Vector2 #foreign raylib; @@ -12,6 +13,7 @@ c :: #system_library "c"; device_density :: () -> float32 #foreign c "app_device_density"; dpi_state: DPIState; +dpi_user_zoom: float32 = 1.0; last_density: float32; last_window_scale: Vector2; @@ -23,14 +25,21 @@ InitDPI :: () { } #program_export -UpdateDPI :: (view_width: s32, view_height: s32) { - platform: DPIPlatform = cast(DPIPlatform)DPIPlatformDesktop - window_scale := Vector2.{1.0, 1.0} +CurrentDPIPlatform :: () -> DPIPlatform { if AndroidPlatform() != 0 { - platform = cast(DPIPlatform)DPIPlatformAndroid - } else if WebPlatform() != 0 { - platform = cast(DPIPlatform)DPIPlatformWeb - } else if IsWindowReady() { + return cast(DPIPlatform)DPIPlatformAndroid + } + if WebPlatform() != 0 { + return cast(DPIPlatform)DPIPlatformWeb + } + return cast(DPIPlatform)DPIPlatformDesktop +} + +#program_export +UpdateDPI :: (view_width: s32, view_height: s32) { + platform: DPIPlatform = CurrentDPIPlatform() + window_scale := Vector2.{1.0, 1.0} + if platform == cast(DPIPlatform)DPIPlatformDesktop && IsWindowReady() { window_scale = GetWindowScaleDPI() } density := device_density() @@ -45,6 +54,18 @@ UpdateDPI :: (view_width: s32, view_height: s32) { last_window_scale = window_scale dpi_state = ResolveDPI(dpi_state, view_width, view_height, platform, density, window_scale.x, window_scale.y) + // The user's zoom scales everything drawn and narrows or widens the + // layout; the text is baked at the size it ends up on screen. + dpi_state = ZoomDPI(dpi_state, dpi_user_zoom) + RaylibSetZoom(dpi_state.render_scale) +} + +// The zoom for the next UpdateDPI, 1.0 for 100%. +#program_export +SetDPIZoom :: (zoom: float32) { + if zoom > 0.0 { + dpi_user_zoom = zoom + } } #program_export diff --git a/src/platform/app_host.zi b/src/platform/app_host.zi index 71840e7bb..5a89b2340 100644 --- a/src/platform/app_host.zi +++ b/src/platform/app_host.zi @@ -16,6 +16,7 @@ app_getenv_bytes :: (name: *u8) -> *u8 #foreign c; #import, file "../app/dpi_state.zi"; #import, file "environment.zi"; #import, file "raylib_host.zi"; +#import, file "../../build/packages/kryon/src/backend/raylib_runtime.zi"; raylib :: #system_library "raylib"; SetConfigFlags :: (flags: u32) #foreign raylib; SetExitKey :: (key: s32) #foreign raylib; @@ -45,9 +46,12 @@ UnloadImage :: (image: RaylibImage) #foreign raylib; #import "tree_input" #import "session" #import "swipe_props" +#import "zoom" #import, file "scroll_input.zi"; #import, file "../app/app.zi"; +#import, file "../app/app_zoom.zi"; +#import, file "../app/app_settings.zi"; #import, file "../breaks/break_rules.zi"; #import, file "../breaks/break_types.zi"; #import, file "../app/current_app.zi"; @@ -277,8 +281,30 @@ app_frame :: (app: *InnerBreeze) { } else { SetMouseCursor(0) } + // Ctrl and the wheel zoom the whole app instead of scrolling a list. + modifiers := RaylibModifiers() + zoom_key: s32 = 0 + if (modifiers & KeyModifierControl) != 0 { + zoom_keys := s32.[ZoomKeyEqual, ZoomKeyMinus, ZoomKeyZero, + ZoomKeyKeypadAdd, ZoomKeyKeypadSubtract, ZoomKeyKeypadZero] + zoom_index: s32 = 0 + while zoom_index < 6 { + if IsKeyPressed(zoom_keys[zoom_index]) { + zoom_key = zoom_keys[zoom_index] + } + zoom_index += 1 + } + } + zoomed := app_zoom_frame(app.ui.session, CurrentDPIPlatform(), + app.ui_scale_tenths, GetMouseWheelMove(), modifiers, zoom_key) + if zoomed.changed { + app.ui_scale_tenths = zoomed.tenths + app.settings_dirty = 1 + save_settings(app) + } + SetDPIZoom(UserScale(app.ui_scale_tenths)) BeginScrollFrame(app.ui.session, mouse, pointer.pressed, pointer.down, - pointer.released, GetMouseWheelMove()) + pointer.released, zoomed.wheel) frame_bounds := Rectangle.{0.0, 0.0, cast(float32)width, cast(float32)height} diff --git a/tests/app_zoom_behavior.zi b/tests/app_zoom_behavior.zi new file mode 100644 index 000000000..47fd8b80e --- /dev/null +++ b/tests/app_zoom_behavior.zi @@ -0,0 +1,96 @@ +#import "dpi" +#import "session" +#import "zoom" +#import, file "../src/app/app_zoom.zi"; + +using DPIPlatform; + +Near :: (value: float32, expected: float32) -> bool { + difference := value - expected + if difference < 0.0 { + difference = -difference + } + return difference < 0.001 +} + +#program_export +Answer :: () -> s32 { + desktop := cast(DPIPlatform)DPIPlatformDesktop + web := cast(DPIPlatform)DPIPlatformWeb + control: s32 = 2 + session := SessionOpen() + tenths: s32 = 10 + + // The saved scale, in tenths, is the zoom the frame applies. + if !Near(UserScale(10), 1.0) { return 1 } + if !Near(UserScale(15), 1.5) { return 2 } + if !Near(UserScale(5), 0.5) { return 3 } + if !Near(UserScale(25), 2.5) { return 4 } + if !Near(UserScale(0), 1.0) { return 5 } + + // A wheel step without Ctrl is left for scrolling and changes nothing. + result := app_zoom_frame(session, desktop, tenths, 1.0, 0, 0) + if result.wheel != 1.0 || result.changed || result.tenths != 10 { + return 6 + } + + // Ctrl and the wheel change the saved scale by a tenth and take the + // wheel away from scrolling. + result = app_zoom_frame(session, desktop, tenths, 1.0, control, 0) + if result.wheel != 0.0 || !result.changed || result.tenths != 11 { + return 7 + } + tenths = result.tenths + result = app_zoom_frame(session, desktop, tenths, -3.0, control, 0) + if result.wheel != 0.0 || result.tenths != 8 { return 8 } + tenths = result.tenths + + // The scale stops at the slider's limits and the wheel stays with zoom. + result = app_zoom_frame(session, desktop, tenths, 40.0, control, 0) + if result.tenths != 25 || result.wheel != 0.0 { return 9 } + tenths = result.tenths + result = app_zoom_frame(session, desktop, tenths, 1.0, control, 0) + if result.changed || result.tenths != 25 || result.wheel != 0.0 { + return 10 + } + result = app_zoom_frame(session, desktop, tenths, -40.0, control, 0) + if result.tenths != 5 { return 11 } + + // The slider edits the setting directly; the wheel continues from it. + tenths = 20 + result = app_zoom_frame(session, desktop, tenths, -1.0, control, 0) + if result.tenths != 19 || !result.changed { return 12 } + + // Ctrl with plus, minus, and zero are the keyboard forms. + tenths = 19 + result = app_zoom_frame(session, desktop, tenths, 0.0, control, + ZoomKeyEqual) + if result.tenths != 20 || !result.changed { return 13 } + result = app_zoom_frame(session, desktop, tenths, 0.0, control, + ZoomKeyMinus) + if result.tenths != 18 { return 14 } + result = app_zoom_frame(session, desktop, tenths, 0.0, control, + ZoomKeyZero) + if result.tenths != 10 { return 15 } + + // A touchpad's small movements add up to a step, one frame at a time. + tenths = 10 + result = app_zoom_frame(session, desktop, tenths, 0.4, control, 0) + result = app_zoom_frame(session, desktop, tenths, 0.4, control, 0) + if result.tenths != 10 { return 16 } + result = app_zoom_frame(session, desktop, tenths, 0.4, control, 0) + if result.tenths != 11 { return 17 } + + // A browser zooms the page itself, so the wheel scrolls as usual. + tenths = 10 + result = app_zoom_frame(session, web, tenths, 1.0, control, 0) + if result.wheel != 1.0 || result.changed || result.tenths != 10 { + return 18 + } + + // Without a session there is nothing to zoom. + unused SessionClose(session) + result = app_zoom_frame(session, desktop, tenths, 1.0, control, 0) + if result.wheel != 1.0 || result.changed { return 19 } + return 42 +} diff --git a/tests/app_zoom_zi_test.sh b/tests/app_zoom_zi_test.sh new file mode 100644 index 000000000..961610360 --- /dev/null +++ b/tests/app_zoom_zi_test.sh @@ -0,0 +1,74 @@ +#!/bin/sh +set -eu + +root=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd) +bin=${1:-"$root/build/ziran-toolchain/bin"} +work=$root/build/app-zoom-test +source=$root/tests/app_zoom_behavior.zi +include=${ZIRAN_INCLUDE:-"$root/build/packages/ziran/include"} +kryon=$root/build/packages/kryon/src/ui +std=$root/build/packages/ziran/std + +mkdir -p "$work/ir" +"$bin/zi2zir" --root "$root/tests" --module-path "$root/src" --module-path "$kryon" \ + --module-path "$std" \ + -o "$work/ir" "$source" + +for input in source saved; do + if [ "$input" = source ]; then + file=$source + module_root=$root/tests + app_path=$root/src + else + file=$work/ir/app_zoom_behavior.zir + module_root=$work/ir + app_path=$work/ir + fi + output=$work/$input + mkdir -p "$output/c" "$output/cpp" "$output/go" + "$bin/zi2zib" bundle --root "$module_root" \ + --module-path "$app_path" --module-path "$kryon" \ + --module-path "$std" \ + --entry app_zoom_behavior:Answer \ + -o "$output/zoom.zib" "$file" + [ "$(env -u DISPLAY -u WAYLAND_DISPLAY "$bin/zi2zib" run "$output/zoom.zib")" = 42 ] + + "$bin/zi2c" --no-main --root "$module_root" \ + --module-path "$app_path" --module-path "$kryon" \ + --module-path "$std" -o "$output/c" "$file" + cat > "$output/c/main.c" <<'C' +#include "app_zoom_behavior.h" +int main(void) { return Answer() == 42 ? 0 : 1; } +C + "${CC:-cc}" -std=c11 -DZIRAN_BOUNDS_CHECK \ + -I"$include" -I"$output/c" "$output/c"/*.c -o "$output/c/test" + env -u DISPLAY -u WAYLAND_DISPLAY "$output/c/test" + + "$bin/zi2cpp" --no-main --root "$module_root" \ + --module-path "$app_path" --module-path "$kryon" \ + --module-path "$std" -o "$output/cpp" "$file" + cat > "$output/cpp/main.cpp" <<'CPP' +#include "app_zoom_behavior.hpp" +int main() { return Answer() == 42 ? 0 : 1; } +CPP + "${CXX:-c++}" -std=c++17 -DZIRAN_BOUNDS_CHECK \ + -I"$include" -I"$output/cpp" "$output/cpp"/*.cpp \ + -o "$output/cpp/test" + env -u DISPLAY -u WAYLAND_DISPLAY "$output/cpp/test" + + "$bin/zi2go" --no-main --root "$module_root" \ + --module-path "$app_path" --module-path "$kryon" \ + --module-path "$std" -o "$output/go" "$file" + cat > "$output/go/app_zoom_behavior_test.go" <<'GO' +package ziran +import "testing" +func TestAppZoom(t *testing.T) { + if got := AppZoomBehavior_Answer(); got != 42 { + t.Fatalf("app zoom: got %d, want 42", got) + } +} +GO + GO111MODULE=off go test "$output/go"/*.go +done + +cmp "$work/source/zoom.zib" "$work/saved/zoom.zib" diff --git a/tests/native_zoom_test.py b/tests/native_zoom_test.py new file mode 100644 index 000000000..85392997b --- /dev/null +++ b/tests/native_zoom_test.py @@ -0,0 +1,150 @@ +"""Zoom the real app with Ctrl and the wheel on the display owned by the shell harness.""" + +import os +from pathlib import Path +import sqlite3 +import subprocess +import sys +import tempfile +import time + +from PIL import Image, ImageChops + + +root = Path(__file__).resolve().parent.parent +output = root / "build/native-zoom-test" +output.mkdir(parents=True, exist_ok=True) +assert int(os.environ["DISPLAY"].split(":")[-1].split(".")[0]) >= 300 +data = Path(tempfile.mkdtemp(prefix="inbe-zoom-", dir=output)) +env = os.environ.copy() +for name in ("WAYLAND_DISPLAY", "GDK_DISPLAY"): + env.pop(name, None) +env["APP_NO_TRAY"] = "1" +env["HOME"] = str(data / "home") +env["XDG_DATA_HOME"] = str(data / "data") +os.makedirs(env["HOME"]) +os.makedirs(env["XDG_DATA_HOME"]) + + +def command(*args): + return subprocess.run(args, env=env, check=True, text=True, + capture_output=True, timeout=5).stdout.strip() + + +def capture(window, name): + raw = output / f"{name}.xwd" + png = output / f"{name}.png" + command("xwd", "-silent", "-id", window, "-out", str(raw)) + command("convert", str(raw), str(png)) + raw.unlink() + with Image.open(png) as image: + return image.convert("RGB").copy() + + +def content_width(image): + """Width of everything drawn on the flat background.""" + background = Image.new("RGB", image.size, image.getpixel((5, 5))) + drawn = ImageChops.difference(image, background).convert("L") + box = drawn.point(lambda value: 255 if value > 24 else 0).getbbox() + assert box, "nothing was drawn" + return box[2] - box[0] + + +def saved_scale(): + database = Path(env["XDG_DATA_HOME"]) / "inbe/inbe.db" + if not database.exists(): + return None + with sqlite3.connect(f"file:{database}?mode=ro", uri=True, timeout=2) as db: + row = db.execute("select value from settings where key = 'ui_scale'").fetchone() + return int(row[0]) if row else None + + +def wait_for_scale(expected, seconds=5): + deadline = time.monotonic() + seconds + while time.monotonic() < deadline: + if saved_scale() == expected: + return True + time.sleep(0.1) + return False + + +def wheel(window, direction, notches, control=True): + command("xdotool", "mousemove", "--window", window, "450", "400") + if control: + command("xdotool", "keydown", "ctrl") + for _ in range(notches): + command("xdotool", "click", "4" if direction > 0 else "5") + time.sleep(0.12) + if control: + command("xdotool", "keyup", "ctrl") + time.sleep(0.6) + + +log_path = output / "app.log" +with log_path.open("w") as log: + app = subprocess.Popen([sys.argv[1]], cwd=root, env=env, stdout=log, + stderr=subprocess.STDOUT, start_new_session=True) + try: + deadline = time.monotonic() + 15 + window = "" + while time.monotonic() < deadline: + assert app.poll() is None, "app exited during startup" + found = subprocess.run( + ["xdotool", "search", "--all", "--onlyvisible", "--pid", + str(app.pid), "--name", "Inner Breeze"], + env=env, capture_output=True, text=True, timeout=2) + if found.returncode == 0 and found.stdout.strip(): + window = found.stdout.splitlines()[0] + break + time.sleep(0.1) + assert window, "the app did not map its own window" + command("xdotool", "windowfocus", window) + assert wait_for_scale(10, 10), f"default scale is {saved_scale()}" + time.sleep(1.0) + normal = capture(window, "normal") + + # Ctrl and the wheel rescale the whole window and move the setting. + wheel(window, +1, 3) + zoomed_in = capture(window, "zoomed-in") + assert wait_for_scale(13), f"scale after three notches is {saved_scale()}" + ratio = content_width(zoomed_in) / content_width(normal) + assert 1.25 < ratio < 1.35, f"130% drew the content {ratio:.2f} times wider" + + # The wheel without Ctrl keeps its meaning and leaves the scale alone. + wheel(window, -1, 3, control=False) + assert saved_scale() == 13, "a plain wheel changed the scale" + + # Zooming back out returns to the layout the app started with. + wheel(window, -1, 3) + restored = capture(window, "restored") + assert wait_for_scale(10), f"scale after zooming back is {saved_scale()}" + ratio = content_width(restored) / content_width(normal) + assert 0.98 < ratio < 1.02, f"zooming back left the content {ratio:.2f} times wider" + + # The limits match the Appearance slider: 50% to 250%. + wheel(window, -1, 20) + assert wait_for_scale(5), f"the low limit is {saved_scale()}" + wheel(window, +1, 40) + assert wait_for_scale(25), f"the high limit is {saved_scale()}" + + # Ctrl+0 resets to 100%. + # Hold Ctrl across several frames, as a person does. + command("xdotool", "keydown", "ctrl") + time.sleep(0.2) + command("xdotool", "keydown", "0") + time.sleep(0.3) + command("xdotool", "keyup", "0") + time.sleep(0.3) + command("xdotool", "keyup", "ctrl") + assert wait_for_scale(10), f"Ctrl+0 left the scale at {saved_scale()}" + assert "APP: frame rejected with status" not in log_path.read_text() + finally: + if app.poll() is None: + app.terminate() + try: + app.wait(timeout=2) + except subprocess.TimeoutExpired: + app.kill() + app.wait(timeout=2) + +print("Native zoom: Ctrl+wheel and Ctrl+0 rescale the app, save the scale, and stop at its limits") diff --git a/tests/native_zoom_test.sh b/tests/native_zoom_test.sh new file mode 100755 index 000000000..8a5079caf --- /dev/null +++ b/tests/native_zoom_test.sh @@ -0,0 +1,7 @@ +#!/bin/sh +set -eu +root=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd) +binary=${1:-"$root/build/bin/linux/inbe-linux-x86_64"} +env -u DISPLAY -u WAYLAND_DISPLAY -u XAUTHORITY -u GDK_DISPLAY \ + timeout 90s xvfb-run -a -n 300 -s '-screen 0 1280x900x24' \ + python3 "$root/tests/native_zoom_test.py" "$binary"