From b26e3ae4e0511dce01008c105f8249e9d4b9ca78 Mon Sep 17 00:00:00 2001 From: ONEO Date: Tue, 24 Nov 2026 23:09:47 +0800 Subject: [PATCH 1/2] test: check live resizes on Windows and Hyprland Co-Authored-By: Claude Opus 5.5 --- docs/architecture/application.md | 2 +- docs/roadmap.md | 2 +- .../platform/linux/resize_live_native_test.go | 188 ++++++++++++++++++ .../windows/resize_live_native_test.go | 162 +++++++++++++++ 4 files changed, 352 insertions(+), 2 deletions(-) create mode 100644 internal/platform/linux/resize_live_native_test.go create mode 100644 internal/platform/windows/resize_live_native_test.go diff --git a/docs/architecture/application.md b/docs/architecture/application.md index fffeb83f5..1e6de2d1d 100644 --- a/docs/architecture/application.md +++ b/docs/architecture/application.md @@ -153,7 +153,7 @@ A scene is a window of the app's one engine, as a desktop window is (decided for X11 placement and stacking ran in isolated Xvfb sessions under Openbox (2026-11-22), with a separate Xlib observer and XTest clicks. Decorated and undecorated windows moved to requested positions, preserved their outer corner through a width-only resize, reported external moves, and applied a position requested while hidden after mapping. Native minimum-size clamping left no stale restoration. The tests passed at whole scales 1 and 2 and with GTK client-side decorations; a floating window remained above a second window activated by a native click, and normal level restored ordinary stacking. GNOME on Xorg, KDE on X11 and explicit Wayland layer surfaces remain in #1379 and #1377. -Linux's native resize tests run under Xvfb with GTK's Cairo renderer (2026-11-22): each allocation grows or shrinks the actual surface widget, and the root's native allocation and its snapshot's corner marker agree with the new layout before the callback returns. A held engine proves the 16 ms timeout, skipped repeat waits, late idle commits and resumed synchronous allocation; a queued-batch test covers recursive drains. Restoring the old asynchronous resize fails the allocation test, and removing the pending-wait guard makes 12 busy allocations wait about 194 ms. Compositor-driven edge drags on Windows, X11 and Wayland remain in the roadmap. +Linux's native resize tests run under Xvfb with GTK's Cairo renderer (2026-11-22): each allocation grows or shrinks the actual surface widget, and the root's native allocation and its snapshot's corner marker agree with the new layout before the callback returns. A held engine proves the 16 ms timeout, skipped repeat waits, late idle commits and resumed synchronous allocation; a queued-batch test covers recursive drains. Restoring the old asynchronous resize fails the allocation test, and removing the pending-wait guard makes 12 busy allocations wait about 194 ms. Live resizes have opt-in checks with `NSGO_LIVE_RESIZE=1` that read the screen through a window whose app takes 12 ms to style each size (2026-11-24). On Windows 11 `TestEdgeDragShowsEachSizeLaidOut` drags the right edge with the system pointer through the sizing loop, 400 pixels out and back: no sample shows a stretched frame or the window's background, where without the wait about 40 of 240 do, and a 40 ms app shows them either way. DWM can still show the window at its last extent for a composition, clipping the new layout. Under Hyprland 0.56 `TestCompositorResizeShowsEachSizeLaidOut` steps a floating window's width: every allocation gets its commit within the wait, yet nearly every step shows the previous size's layout at the new size for tens of milliseconds, and about half of them with a 4 ms app; an app that styles at once shows each size. X11 window managers remain unchecked. `internal/platform/linux/paneldock_native_test.go` checks the compositor's actual PNG pixels for four dock edges on two outputs at scales 1 and 2, content growth/shrink, hide/show and real keyboard delivery to the original window. Run with `NSGO_LAYER_SHELL_TEST=1`, `GDK_BACKEND=wayland`, `grim` and `wtype` against an isolated headless Sway with two `HEADLESS-` outputs (800×600 at scale 1, 1200×800 at scale 2); the fixture refuses other output names. Separate processes with `NSGO_LAYER_SHELL_UNAVAILABLE` set to the expected error substring check the missing-library and preloaded-libwayland cases while ordinary windows still show. `NSGO_X11_DOCK_TEST=1` opts into real X11 geometry checks under isolated Xvfb/Openbox. macOS's `TestEdgeDockedPanelUsesNativeScreenFrames` reads actual app-owned panel frames through resizing and reopening. Physical mixed-scale displays remain a native acceptance gap. diff --git a/docs/roadmap.md b/docs/roadmap.md index 55ec7d0e5..5bb053d88 100644 --- a/docs/roadmap.md +++ b/docs/roadmap.md @@ -141,7 +141,7 @@ What Windows and Linux still lack of what macOS opens for an app, and Android of | --- | --- | --- | | Editing menu validation on Windows and Linux | [#2018](https://github.com/nsgo-dev/nsgo/issues/2018), [menus](architecture/services.md#menus) | Undo, Redo and selection-dependent menu roles follow the focused editor’s history and selection; these backends currently dispatch editing roles without native menu validation | | Owned-window placement and Wayland acceptance | `WindowOptions.Parent` (#108), [#1840](https://github.com/nsgo-dev/nsgo/issues/1840) | Center a new child over its parent on Windows and where a Linux compositor allows placement; macOS already centers it. Native ownership, visibility and minimization following are implemented on all three desktops; verify stacking and minimize/restore on a Wayland compositor separately from X11. | -| Resizes that keep up on Windows and Linux | macOS's `surface.resize`, [#1375](https://github.com/nsgo-dev/nsgo/issues/1375) | Dragging a window's edge on Windows and Linux waits up to 16 ms for the layout at each size before the backend applies it; Linux drains queued batches from GTK's allocation callback and leaves a busy commit to its idle path. Native GTK allocation tests under Xvfb verify growing, shrinking, immediate widget geometry and snapshot pixels, a busy engine's bounded wait, skipped repeat waits and late commits. Live edge drags under Windows, X11 and Wayland compositors remain unchecked (2026-11-22) | +| Resizes that keep up on Windows and Linux | macOS's `surface.resize`, [#1375](https://github.com/nsgo-dev/nsgo/issues/1375) | Dragging a window's edge on Windows and Linux waits up to 16 ms for the layout at each size before the backend applies it; Linux drains queued batches from GTK's allocation callback and leaves a busy commit to its idle path. Native GTK allocation tests under Xvfb verify growing, shrinking, immediate widget geometry and snapshot pixels, a busy engine's bounded wait, skipped repeat waits and late commits. A live edge drag on Windows 11 shows each size laid out for an app within the wait (2026-11-24). Under Hyprland a step resize still shows the previous size's layout at the new size once the app takes a few milliseconds a size, though its commit arrives within the wait; X11 window managers remain unchecked | | Panels that do not activate on Windows | `WS_EX_NOACTIVATE`; macOS's `NsgoPanel`, [#1376](https://github.com/nsgo-dev/nsgo/issues/1376) | A panel takes the keyboard without activating the app or taking the foreground from the app in front, as macOS's do | | Panels beside a caret or the pointer | NSGo's [#243](https://github.com/nsgo-dev/nsgo/issues/243), [#1377](https://github.com/nsgo-dev/nsgo/issues/1377) | Check panels placed by `Window.ShowAt` and docked by `PanelOptions.Dock` on physical monitors of mixed scales, and Windows' docked-panel visibility and focus on a visible desktop | | Panel frame animation on Linux | `WindowFrame.Animated`, [panel frame clocks](architecture/application.md#surfaces) | Visible panels ease to their new native size and supported position on GTK's frame clock; Linux currently applies the frame immediately | diff --git a/internal/platform/linux/resize_live_native_test.go b/internal/platform/linux/resize_live_native_test.go new file mode 100644 index 000000000..8c5e945f0 --- /dev/null +++ b/internal/platform/linux/resize_live_native_test.go @@ -0,0 +1,188 @@ +//go:build linux && !android + +package linux + +import ( + "bytes" + "encoding/json" + "fmt" + "image/png" + "os" + "os/exec" + "strings" + "testing" + "time" + + "github.com/nsgo-dev/nsgo/core" + "github.com/nsgo-dev/nsgo/internal/driver" +) + +// TestCompositorResizeShowsEachSizeLaidOut has Hyprland resize a floating +// window step by step, keeping its left edge, as a drag of its right edge +// does, and reads the middle row of +// what the compositor shows at each size: a 200-point red column, a blue +// fill and a 24-point green strip end the window wherever it is shown, +// and past it is what was there before the window, never a strip the +// window drew without its layout, while the app takes most of a frame to +// lay out each size (#1375). It needs a Hyprland session, grim and +// NSGO_LIVE_RESIZE=1, and turns the compositor's animations off while it +// runs. +func TestCompositorResizeShowsEachSizeLaidOut(t *testing.T) { + if os.Getenv("NSGO_LIVE_RESIZE") != "1" || os.Getenv("HYPRLAND_INSTANCE_SIGNATURE") == "" { + t.Skip("set NSGO_LIVE_RESIZE=1 in a Hyprland session") + } + grim, err := exec.LookPath("grim") + if err != nil { + t.Skip("needs grim") + } + hyprctl := func(args ...string) string { + t.Helper() + out, err := exec.Command("hyprctl", args...).Output() + if err == nil && strings.Contains(string(out), "error:") { + err = fmt.Errorf("%s", out) + } + if err != nil { + t.Fatalf("hyprctl %v: %v", args, err) + } + return string(out) + } + var animations struct{ Bool bool } + if err := json.Unmarshal([]byte(hyprctl("-j", "getoption", "animations:enabled")), &animations); err != nil { + t.Fatal(err) + } + animate := func(on bool) { hyprctl("eval", fmt.Sprintf("hl.config({ animations = { enabled = %t } })", on)) } + animate(false) + t.Cleanup(func() { animate(animations.Bool) }) + + const ( + red, blue, green = 0xff0000, 0x0000ff, 0x00ff00 + left, strip = 200, 24 + x0, y0, h = 100, 100, 300 + from, to, step = 400, 800, 10 + ) + app := func(cx *core.Scope) core.Node { + return core.View{Style: core.Style{Direction: core.Row, FlexGrow: 1}, Children: []core.Node{ + core.View{Style: core.Style{Width: driver.Pt(left), Background: driver.RGB(red)}}, + core.View{Style: core.Style{FlexGrow: 1, Background: driver.RGB(blue)}}, + // Each size takes the app 12 ms, within the wait, to style. + core.View{StyleFunc: func() core.Style { + _ = cx.Env().Window() + for start := time.Now(); time.Since(start) < 12*time.Millisecond; { + } + return core.Style{Width: driver.Pt(strip), Background: driver.RGB(green)} + }}, + }} + } + const title = "nsgo-live-resize1375" + startTestWindow(t, app, Options{Title: title, Width: from, Height: h}) + for deadline := time.Now().Add(5 * time.Second); !strings.Contains(hyprctl("clients"), "title: "+title); time.Sleep(50 * time.Millisecond) { + if time.Now().After(deadline) { + t.Fatal("Hyprland does not list the window") + } + } + // Hyprland's Lua dispatchers: a resize keeps the window's center, so + // each goes with a move, in one request, to keep its left edge. + window := `window = "title:^` + title + `$"` + frame := func(width int) { + hyprctl("--batch", fmt.Sprintf("dispatch hl.dsp.window.resize({ x = %d, y = %d, relative = false, %s }) ; "+ + "dispatch hl.dsp.window.move({ x = %d, y = %d, relative = false, %s })", width, h, window, x0, y0, window)) + } + hyprctl("dispatch", "hl.dsp.window.float({ action = \"enable\", "+window+" })") + frame(from) + hyprctl("dispatch", "hl.dsp.focus({ "+window+" })") + time.Sleep(500 * time.Millisecond) + + // row reads the screen's row through the window's middle, from its + // left edge to past its widest. + row := func() []uint32 { + out, err := exec.Command(grim, "-g", fmt.Sprintf("%d,%d %dx1", x0, y0+h/2, to+40), "-").Output() + if err != nil { + t.Fatalf("grim: %v", err) + } + img, err := png.Decode(bytes.NewReader(out)) + if err != nil { + t.Fatal(err) + } + b := img.Bounds() + px := make([]uint32, b.Dx()) + for x := range px { + r, g, bl, _ := img.At(b.Min.X+x, b.Min.Y).RGBA() + px[x] = r>>8<<16 | g>>8<<8 | bl>>8 + } + return px + } + near := func(c, want uint32) bool { + for shift := 0; shift < 24; shift += 8 { + if d := int(c>>shift&0xff) - int(want>>shift&0xff); d < -40 || d > 40 { + return false + } + } + return true + } + ours := func(c uint32) bool { return near(c, red) || near(c, blue) || near(c, green) } + // What is behind the window where it grows, read before it grows. + behind := row() + if !near(behind[10], red) { + t.Skipf("the window is not on screen where Hyprland was asked to put it: #%06x", behind[10]) + } + // check finds the extent of the layout shown and says what is wrong: + // a red column of another width, green not ending it, or anything but + // what was behind between it and the size asked for, short of the + // border Hyprland draws there. + check := func(size int) string { + px := row() + shown := 0 + for shown < len(px) && (ours(px[shown]) || shown+1 < len(px) && ours(px[shown+1])) { + shown++ + } + edge := 0 + for edge < shown && near(px[edge], red) { + edge++ + } + if edge < left-2 || edge > left+2 { + return fmt.Sprintf("red ends at %d, want %d", edge, left) + } + greenFrom := shown + for greenFrom > edge && near(px[greenFrom-1], green) { + greenFrom-- + } + if n := shown - greenFrom; n < strip-2 || n > strip+1 { + return fmt.Sprintf("green %d wide at %d of %d shown", n, greenFrom, shown) + } + for x := shown + 2; x < size-4 && x < len(px); x++ { + if x >= from && !near(px[x], behind[x]) { + return fmt.Sprintf("x %d is #%06x past the layout shown to %d at size %d, was #%06x", x, px[x], shown, size, behind[x]) + } + } + return "" + } + samples := 0 + var bad []string + sizes := []int{} + for s := from + step; s <= to; s += step { + sizes = append(sizes, s) + } + for s := to - step; s >= from; s -= step { + sizes = append(sizes, s) + } + for _, size := range sizes { + frame(size) + for range 2 { + samples++ + if problem := check(size); problem != "" { + bad = append(bad, fmt.Sprintf("size %d: %s", size, problem)) + } + } + } + t.Logf("%d samples at %d sizes: %d showed a stretched frame or background", samples, len(sizes), len(bad)) + for i, b := range bad { + if i == 20 { + t.Logf("... %d more", len(bad)-20) + break + } + t.Log(b) + } + if len(bad) > 0 { + t.Fail() + } +} diff --git a/internal/platform/windows/resize_live_native_test.go b/internal/platform/windows/resize_live_native_test.go new file mode 100644 index 000000000..591379ded --- /dev/null +++ b/internal/platform/windows/resize_live_native_test.go @@ -0,0 +1,162 @@ +//go:build windows + +package windows + +import ( + "fmt" + "os" + "testing" + "time" + "unsafe" + + "github.com/nsgo-dev/nsgo/core" + "github.com/nsgo-dev/nsgo/internal/driver" +) + +var mouseEvent = user32.NewProc("mouse_event") + +// TestEdgeDragShowsEachSizeLaidOut drags a window's right edge with the +// system's own pointer, through its modal sizing loop, and reads the +// screen at each size: a 200-point red column, a blue fill and a 24-point +// green strip at the right edge are where the layout at that size puts +// them, with neither a stretched frame, whose red would widen, nor a strip +// of background past the green, while the app takes most of a frame to lay +// out each size (#1375). It needs an interactive desktop +// session, and NSGO_LIVE_RESIZE=1. +func TestEdgeDragShowsEachSizeLaidOut(t *testing.T) { + if os.Getenv("NSGO_LIVE_RESIZE") != "1" { + t.Skip("set NSGO_LIVE_RESIZE=1 in an interactive desktop session") + } + const ( + red, blue, green, white = 0xff0000, 0x0000ff, 0x00ff00, 0xffffff + left, strip = 200, 24 + ) + app := func(cx *core.Scope) core.Node { + return core.View{Style: core.Style{Direction: core.Row, Height: core.Pct(100)}, Children: []core.Node{ + core.View{Style: core.Style{Width: driver.Pt(left), Background: driver.RGB(red)}}, + core.View{Style: core.Style{FlexGrow: 1, Background: driver.RGB(blue)}}, + // Each size takes the app 12 ms, within the wait, to style. + core.View{StyleFunc: func() core.Style { + _ = cx.Env().Window() + for start := time.Now(); time.Since(start) < 12*time.Millisecond; { + } + return core.Style{Width: driver.Pt(strip), Background: driver.RGB(green)} + }}, + }} + } + hwnd := startApp(t, "nsgo-live-resize1375", app, 400, 300) + if _, ok := waitForPixel(t, hwnd, 2, 2, red, 5*time.Second); !ok { + t.Skip("the window is not on screen: run in an interactive desktop session") + } + var scale float64 + onMain(t, hwnd, func(w *window) { scale = w.scale }) + var r rect + getWindowRect.Call(hwnd, uintptr(unsafe.Pointer(&r))) + x, y := r.Right-3, (r.Top+r.Bottom)/2 + near := func(c, want uint32) bool { + for shift := 0; shift < 24; shift += 8 { + if d := int(c>>shift&0xff) - int(want>>shift&0xff); d < -40 || d > 40 { + return false + } + } + return true + } + // check reads the client area's middle row as the screen shows it and + // says what is wrong with it, if anything. DWM can show the window at + // its last extent for a composition after the client area has grown, + // its border and what is behind it past there: the row is judged up to + // the extent shown, where a strip of the window's white background or + // a red column wider than 200 points is wrong, and the green strip + // ending short of it, a layout of another size, is counted apart. + check := func() (width int32, problem string, other bool) { + pix, width, height, ok := screenPixels(hwnd) + if !ok { + return 0, "unreadable", false + } + // A size that changed while the screen was read says nothing. + var after rect + getClientRect.Call(hwnd, uintptr(unsafe.Pointer(&after))) + if after.Right != width || after.Bottom != height { + return 0, "", false + } + row := int(height/2) * int(width) * 4 + at := func(x int32) uint32 { + i := row + int(x)*4 + return uint32(pix[i+2])<<16 | uint32(pix[i+1])<<8 | uint32(pix[i]) + } + ours := func(c uint32) bool { + return near(c, red) || near(c, blue) || near(c, green) || near(c, white) + } + // A column blended between two of ours is ours too. + shown := int32(0) + for shown < width && (ours(at(shown)) || shown+1 < width && ours(at(shown+1))) { + shown++ + } + edge := int32(0) + for edge < shown && near(at(edge), red) { + edge++ + } + if want := int32(left*scale + 0.5); edge < want-2 || edge > want+2 { + return width, fmt.Sprintf("red ends at %d, want %d", edge, want), false + } + for x := edge; x < shown; x++ { + if near(at(x), white) { + return width, fmt.Sprintf("background at %d of %d, shown to %d", x, width, shown), false + } + } + greenFrom := shown + for greenFrom > edge && near(at(greenFrom-1), green) { + greenFrom-- + } + // Antialiasing blends the strip's last column into what is past it. + want := int32(strip*scale + 0.5) + return width, "", shown-greenFrom < want-2 || shown-greenFrom > want+1 + } + setForegroundWindow.Call(hwnd) + setCursorPos.Call(uintptr(x), uintptr(y)) + time.Sleep(200 * time.Millisecond) + mouseEvent.Call(2, 0, 0, 0, 0) // MOUSEEVENTF_LEFTDOWN + time.Sleep(200 * time.Millisecond) + samples, others, sizes := 0, 0, map[int32]bool{} + var bad []string + // Out to 400 pixels wider and back, 10 pixels a step, faster than a + // hand, reading the screen three times within a frame of each step, + // once the sizing loop has had the pointer's move. + for i := 1; i <= 80; i++ { + dx := int32(i * 10) + if i > 40 { + dx = int32((80 - i) * 10) + } + setCursorPos.Call(uintptr(x+dx), uintptr(y)) + for _, wait := range []time.Duration{4, 4, 4} { + time.Sleep(wait * time.Millisecond) + width, problem, other := check() + if width == 0 && problem == "" { + continue + } + samples++ + sizes[width] = true + if other { + others++ + } + if problem != "" { + bad = append(bad, fmt.Sprintf("step %d +%dms: %s", i, wait, problem)) + } + } + } + mouseEvent.Call(4, 0, 0, 0, 0) // MOUSEEVENTF_LEFTUP + t.Logf("%d samples at %d widths, scale %.2f: %d showed a stretched frame or background, %d a layout of another size", samples, len(sizes), scale, len(bad), others) + if len(sizes) < 20 { + t.Fatalf("the drag resized the window to only %d widths: the pointer did not hold its edge", len(sizes)) + } + for i, b := range bad { + if i == 20 { + t.Logf("... %d more", len(bad)-20) + break + } + t.Log(b) + } + if len(bad) > 0 { + t.Fail() + } +} From 1c20d515a4e844acbd88225605a032e5e2dd2d58 Mon Sep 17 00:00:00 2001 From: ONEO Date: Tue, 24 Nov 2026 23:17:26 +0800 Subject: [PATCH 2/2] test: route the system pointer through windows on Windows Co-Authored-By: Claude Opus 5.5 --- docs/architecture/application.md | 2 +- docs/roadmap.md | 2 +- .../windows/windowpointer_live_native_test.go | 244 ++++++++++++++++++ 3 files changed, 246 insertions(+), 2 deletions(-) create mode 100644 internal/platform/windows/windowpointer_live_native_test.go diff --git a/docs/architecture/application.md b/docs/architecture/application.md index 1e6de2d1d..a6126e291 100644 --- a/docs/architecture/application.md +++ b/docs/architecture/application.md @@ -157,4 +157,4 @@ Linux's native resize tests run under Xvfb with GTK's Cairo renderer (2026-11-22 `internal/platform/linux/paneldock_native_test.go` checks the compositor's actual PNG pixels for four dock edges on two outputs at scales 1 and 2, content growth/shrink, hide/show and real keyboard delivery to the original window. Run with `NSGO_LAYER_SHELL_TEST=1`, `GDK_BACKEND=wayland`, `grim` and `wtype` against an isolated headless Sway with two `HEADLESS-` outputs (800×600 at scale 1, 1200×800 at scale 2); the fixture refuses other output names. Separate processes with `NSGO_LAYER_SHELL_UNAVAILABLE` set to the expected error substring check the missing-library and preloaded-libwayland cases while ordinary windows still show. `NSGO_X11_DOCK_TEST=1` opts into real X11 geometry checks under isolated Xvfb/Openbox. macOS's `TestEdgeDockedPanelUsesNativeScreenFrames` reads actual app-owned panel frames through resizing and reopening. Physical mixed-scale displays remain a native acceptance gap. -`internal/platform/ios/scene_test.go` opens a second scene on an iPad simulator (iOS 27, 2026-11-21): each scene shows its own surface in its own window, running a tree of its own, a press in each reaches its own tree, one disconnects and reconnects with its tree while the other runs, closing it ends its tree alone, and each scene's controller answers with its own status bar and orientations; `core/overlay_test.go` checks the trees a scene opens headless. `core/window_test.go` opens windows, panels and tray icons on a platform that opens windows, headless: shared signals, shutdown modes, canceled closes, reopening, keys and owners, tray clicks and menus, shortcuts, the Dock and the login item, and the main view where no windows open. `internal/engine` attaches an opened window and destroys it, and the Windows backend's tests decode the notification area's callbacks. On macOS `examples/tray` was run: its welcome window, its panel under the icon after a click, a close that keeps the app, and the gallery ending with its window. A panel placed with `ShowAt` and `MoveTo` was run on macOS 27, Windows 11 and Ubuntu 24.04 on Xwayland (2026-11-16): beside, flipped above at the bottom of the display and at a point; with `NoActivate` the app in front kept the foreground through its show, a click on its button that ran the handler, its moves and a toggle, while a panel without it took the keyboard; on Wayland `ShowAt` reported that it could not place the panel. `driver.PlaceWindow`'s flips and clamps have a test of their own. A window's pointer events are checked headless in `core/window_test.go` (the options, the setter and `AccessOverlay`) and `nsgotest`, `driver.Painted` has a table test, and `internal/platform/macos` opens a window with a painted view and checks `ignoresMouseEvents` and the painted hit test on macOS 27 (2026-11-17); the Windows backend's native test checks the extended style, compiled and not run. Linux's two-window native regression runs through XTest with Openbox and a virtual pointer with private Sway: presses, wheel and hover pass through `None` and the gaps in `Painted`, the island takes presses, wheel, hover, context menus and native window drags, nearer controls keep their presses, and `Auto` restores the input region without replacing either window ([roadmap](../roadmap.md#application-and-windows)). `core/window_test.go` checks that a fitted panel's size goes ahead of its first show and follows its content up to its largest size, and that `Transparent` reaches the platform and `Env`; a transparent fitted card was run on macOS 27 (2026-11-17), showing only the card and its shadow; on Linux under Xvfb, `internal/platform/linux/panel_native_test.go` shows a transparent fitted panel beside its anchor and checks its pixels and X11 position as it grows and shrinks, while Windows was only built and vetted. +`internal/platform/ios/scene_test.go` opens a second scene on an iPad simulator (iOS 27, 2026-11-21): each scene shows its own surface in its own window, running a tree of its own, a press in each reaches its own tree, one disconnects and reconnects with its tree while the other runs, closing it ends its tree alone, and each scene's controller answers with its own status bar and orientations; `core/overlay_test.go` checks the trees a scene opens headless. `core/window_test.go` opens windows, panels and tray icons on a platform that opens windows, headless: shared signals, shutdown modes, canceled closes, reopening, keys and owners, tray clicks and menus, shortcuts, the Dock and the login item, and the main view where no windows open. `internal/engine` attaches an opened window and destroys it, and the Windows backend's tests decode the notification area's callbacks. On macOS `examples/tray` was run: its welcome window, its panel under the icon after a click, a close that keeps the app, and the gallery ending with its window. A panel placed with `ShowAt` and `MoveTo` was run on macOS 27, Windows 11 and Ubuntu 24.04 on Xwayland (2026-11-16): beside, flipped above at the bottom of the display and at a point; with `NoActivate` the app in front kept the foreground through its show, a click on its button that ran the handler, its moves and a toggle, while a panel without it took the keyboard; on Wayland `ShowAt` reported that it could not place the panel. `driver.PlaceWindow`'s flips and clamps have a test of their own. A window's pointer events are checked headless in `core/window_test.go` (the options, the setter and `AccessOverlay`) and `nsgotest`, `driver.Painted` has a table test, and `internal/platform/macos` opens a window with a painted view and checks `ignoresMouseEvents` and the painted hit test on macOS 27 (2026-11-17); the Windows backend's native test checks the extended style. On a Windows 11 desktop (2026-11-24) `TestWindowPointerModesRouteTheSystemPointer`, opt-in with `NSGO_LIVE_POINTER=1`, lays one window over another and moves the system pointer with `mouse_event`. Presses, wheel turns and hovers reach the window below through `None` and around a `Painted` island. The island takes its own presses, wheel, hover, context menu and a `WindowDrag` of its strip, while a control in the strip keeps its press. `Auto` takes everything again without replacing the window. This holds in a plain window and a Mica one drawn through DirectComposition, which still shows its content while layered. Linux's two-window native regression runs through XTest with Openbox and a virtual pointer with private Sway: presses, wheel and hover pass through `None` and the gaps in `Painted`, the island takes presses, wheel, hover, context menus and native window drags, nearer controls keep their presses, and `Auto` restores the input region without replacing either window ([roadmap](../roadmap.md#application-and-windows)). `core/window_test.go` checks that a fitted panel's size goes ahead of its first show and follows its content up to its largest size, and that `Transparent` reaches the platform and `Env`; a transparent fitted card was run on macOS 27 (2026-11-17), showing only the card and its shadow; on Linux under Xvfb, `internal/platform/linux/panel_native_test.go` shows a transparent fitted panel beside its anchor and checks its pixels and X11 position as it grows and shrinks, while Windows was only built and vetted. diff --git a/docs/roadmap.md b/docs/roadmap.md index 5bb053d88..031095789 100644 --- a/docs/roadmap.md +++ b/docs/roadmap.md @@ -149,7 +149,7 @@ What Windows and Linux still lack of what macOS opens for an app, and Android of | Floating windows on Android | NSGo's [#53](https://github.com/nsgo-dev/nsgo/issues/53) and its [design](architecture/android-floating-windows.md); [#38](https://github.com/nsgo-dev/nsgo/issues/38) for the foreground service | `mobile.OpenOverlay`'s window, which the runtime shows after the user grants `SYSTEM_ALERT_WINDOW`, is checked on Android 12 to 15 devices and an API 29 emulator to take touches, pass them through when passive, be dragged, stay up in the background and with the screen off through its foreground service, end on a revoked grant and close cleanly, and the runtime has the fake-`WindowManager` tests its [verification](architecture/android-floating-windows.md#verification) lists | | Window levels and placement on Linux | [#573](https://github.com/nsgo-dev/nsgo/issues/573); `XMoveWindow`; `zwlr_layer_shell_v1`, [#1379](https://github.com/nsgo-dev/nsgo/issues/1379) | `SetWindowFrame` positions X11 windows and reports their native positions through `Frame` and `CanPlaceWindows`; isolated Xvfb tests under Openbox verify placement, native moves, hidden-window requests, and that floating stays above a window activated by a native click while normal returns to ordinary stacking (2026-11-22). GNOME on Xorg and KDE on X11 remain unchecked. On Wayland only panels reach the layer shell, through `PanelOptions.Dock` (#1377); ordinary toplevels still report `CanSetWindowLevel` and `CanPlaceWindows` false | | Alpha-aware painted window media | [#599](https://github.com/nsgo-dev/nsgo/issues/599) | macOS and Windows sample opted-in image pixels, and macOS samples video without controls or a track transform. Windows and Linux video, transformed macOS video, and Linux images still use view bounds. | -| Windows that let the pointer through | NSGo's [#568](https://github.com/nsgo-dev/nsgo/issues/568); `ignoresMouseEvents`, `WS_EX_LAYERED` with `WS_EX_TRANSPARENT`, `gdk_surface_set_input_region`, [#1380](https://github.com/nsgo-dev/nsgo/issues/1380) | Finish manual verification on macOS, Windows 11 and Ubuntu under X11 and Wayland: `WindowPointerNone` passes presses, wheel and hover; `WindowPointerPainted` keeps a 200 by 200 island interactive in a 600 by 400 window, including `WindowDrag` and `OnContextMenu`; modes change without reopening. Native two-window regressions pass under Openbox/X11 and private Sway/Wayland, including nearer-control drag precedence and hover on entry. macOS has property and painted-hit tests, while full native routing remains unchecked; Windows native acceptance, including plain and material DirectComposition windows through `None` and back to `Auto`, remains unchecked | +| Windows that let the pointer through | NSGo's [#568](https://github.com/nsgo-dev/nsgo/issues/568); `ignoresMouseEvents`, `WS_EX_LAYERED` with `WS_EX_TRANSPARENT`, `gdk_surface_set_input_region`, [#1380](https://github.com/nsgo-dev/nsgo/issues/1380) | Finish manual verification on macOS and Ubuntu under X11 and Wayland: `WindowPointerNone` passes presses, wheel and hover; `WindowPointerPainted` keeps a 200 by 200 island interactive in a 600 by 400 window, including `WindowDrag` and `OnContextMenu`; modes change without reopening. Native two-window regressions pass under Openbox/X11 and private Sway/Wayland, including nearer-control drag precedence and hover on entry. On Windows 11 the system pointer passes through `None` and around a `Painted` island, which takes presses, wheel, hover, its context menu and a `WindowDrag`, in a plain window and a Mica one through `None`, `Painted` and back to `Auto`, still showing its content (2026-11-24). macOS has property and painted-hit tests, while its full native routing remains unchecked | | Nonfixed maximum sizes on Wayland | `xdg_toplevel.set_max_size`, [#1381](https://github.com/nsgo-dev/nsgo/issues/1381) | GTK exposes neither this setter nor a public `xdg_toplevel` handle; X11 maximum-size hints and native GTK minimize/maximize button restrictions are implemented, checked under Openbox at 1× and 2× and with titlebar controls under headless Sway, while Wayland keeps fixed-size support | | Tray icons on Windows | `Shell_NotifyIcon`; #988, [#1382](https://github.com/nsgo-dev/nsgo/issues/1382) | Live tray views now rasterize into transparent `HICON`s, with updates from retained changes, animation invalidations and completed image loads; cached icons survive metadata updates and an unavailable or restarting Explorer. Finish interactive Windows verification of the visible icon, menus, clicks and panel anchoring through `Shell_NotifyIconGetRect`; a noninteractive session cannot establish that acceptance | | Tray icons on Linux | StatusNotifierItem and `com.canonical.dbusmenu` over D-Bus; #988, #1209 | KDE and GNOME with its AppIndicator extension show the icon, its menu and clicks; GNOME without one shows none; a drawn icon is drawn | diff --git a/internal/platform/windows/windowpointer_live_native_test.go b/internal/platform/windows/windowpointer_live_native_test.go new file mode 100644 index 000000000..e767a6d9b --- /dev/null +++ b/internal/platform/windows/windowpointer_live_native_test.go @@ -0,0 +1,244 @@ +//go:build windows + +package windows + +import ( + "fmt" + "os" + "sync/atomic" + "testing" + "time" + "unsafe" + + "github.com/nsgo-dev/nsgo/core" + "github.com/nsgo-dev/nsgo/internal/driver" +) + +type livePointerCounts struct{ press, wheel, enter, context atomic.Int32 } + +// TestWindowPointerModesRouteTheSystemPointer lays a 600 by 400 window +// over another and moves the system's own pointer over them, pressing, +// turning the wheel and pressing the right button, so Windows routes each +// message, never NSGo's hit test (#1380). With WindowPointerNone all of it +// reaches the window below; with WindowPointerPainted a 200 by 200 island +// takes its own, its context menu and a WindowDrag of its strip, while +// what is around it reaches the window below; Auto takes it all again, +// all without reopening the window or losing what it shows, plain and +// with a material, which draws through DirectComposition. It moves the pointer of an interactive +// desktop session, so it runs only with NSGO_LIVE_POINTER=1. +func TestWindowPointerModesRouteTheSystemPointer(t *testing.T) { + if os.Getenv("NSGO_LIVE_POINTER") != "1" { + t.Skip("set NSGO_LIVE_POINTER=1 in an interactive desktop session") + } + for _, c := range []struct { + name string + material core.WindowMaterial + }{{"plain", core.WindowMaterialNone}, {"mica", core.WindowMaterialMica}} { + t.Run(c.name, func(t *testing.T) { livePointerModes(t, c.material) }) + } +} + +func livePointerModes(t *testing.T, material core.WindowMaterial) { + lowerTitle, upperTitle := "nsgo-pointer1380-lower-"+t.Name(), "nsgo-pointer1380-upper-"+t.Name() + var lower, upper livePointerCounts + at := func(x, y, w, h driver.Points, rgb uint32) core.Style { + s := core.Style{Position: core.Absolute, Left: driver.Pt(x), Top: driver.Pt(y), Width: driver.Pt(w), Height: driver.Pt(h)} + if rgb != 0 { + s.Background = driver.RGB(rgb) + } + return s + } + ready := make(chan *core.Scope, 1) + app := core.AppRoot(func(cx *core.Scope) { + cx.SetShutdownMode(core.ShutdownOnExplicit) + cx.OpenWindow(core.WindowOptions{Title: lowerTitle, Width: 600, Height: 400}, func(*core.Scope) core.Node { + return core.View{Style: core.Style{FlexGrow: 1, Background: driver.RGB(0x44aa44)}, + OnPress: func(core.PressEvent) { lower.press.Add(1) }, OnWheel: func(core.WheelEvent) { lower.wheel.Add(1) }, + OnMouseEnter: func(core.MouseEvent) { lower.enter.Add(1) }} + }) + cx.OpenWindow(core.WindowOptions{Title: upperTitle, Width: 600, Height: 400, Material: material}, func(cx *core.Scope) core.Node { + ready <- cx + return core.View{Style: core.Style{FlexGrow: 1}, Children: []core.Node{ + core.View{Style: at(100, 100, 200, 200, 0x2244aa), + OnPress: func(core.PressEvent) { upper.press.Add(1) }, OnWheel: func(core.WheelEvent) { upper.wheel.Add(1) }, + OnMouseEnter: func(core.MouseEvent) { upper.enter.Add(1) }, OnContextMenu: func(core.ContextMenuEvent) { upper.context.Add(1) }, + Children: []core.Node{core.View{Desktop: core.DesktopViewProps{WindowDrag: core.WindowDragOn}, + Style: at(0, 0, 200, 40, 0), OnPress: func(core.PressEvent) { upper.press.Add(1) }, Children: []core.Node{ + core.View{Style: at(0, 0, 50, 40, 0), OnPress: func(core.PressEvent) { upper.press.Add(1) }}, + }}}}, + }} + }) + }) + root := startAppWith(t, app, Options{Title: "nsgo-pointer1380-host-" + t.Name(), Width: 200, Height: 100, Hidden: true}) + var cx *core.Scope + select { + case cx = <-ready: + case <-time.After(5 * time.Second): + t.Fatal("the upper window did not render") + } + find := func(title string) uintptr { + for deadline := time.Now().Add(5 * time.Second); ; time.Sleep(20 * time.Millisecond) { + if hwnd, _, _ := findWindowW.Call(0, uintptr(unsafe.Pointer(wide(title)))); hwnd != 0 { + return hwnd + } + if time.Now().After(deadline) { + t.Fatalf("no window %q", title) + } + } + } + bottom, top := find(lowerTitle), find(upperTitle) + var scale float64 + onMain(t, root, func(*window) { + for _, hwnd := range []uintptr{bottom, top} { + setWindowPos.Call(hwnd, 0, 100, 100, 0, 0, swpNoSize|swpNoZOrder|swpNoActivate) + } + scale = windows[top].scale + }) + raise := func() { setForegroundWindow.Call(top); time.Sleep(50 * time.Millisecond) } + origin := func() point { + p := point{} + clientToScreen.Call(top, uintptr(unsafe.Pointer(&p))) + return p + } + move := func(x, y float64) { + o := origin() + setCursorPos.Call(uintptr(o.X+int32(x*scale)), uintptr(o.Y+int32(y*scale))) + time.Sleep(40 * time.Millisecond) + } + // leave moves the pointer off both windows, so every route sees an + // enter. + leave := func() { + o := origin() + setCursorPos.Call(uintptr(o.X+int32(700*scale)), uintptr(o.Y+int32(500*scale))) + time.Sleep(60 * time.Millisecond) + } + const ( + leftDown, leftUp, rightDown, rightUp, wheel = 0x2, 0x4, 0x8, 0x10, 0x800 + ) + input := func(flags uintptr, data int32) { + mouseEvent.Call(flags, 0, 0, uintptr(uint32(data)), 0) + time.Sleep(20 * time.Millisecond) + } + wait := func(what string, ok func() bool, detail func() string) { + t.Helper() + for deadline := time.Now().Add(3 * time.Second); !ok(); time.Sleep(10 * time.Millisecond) { + if time.Now().After(deadline) { + t.Fatalf("timed out waiting for %s: %s", what, detail()) + } + } + } + counts := func() string { + return fmt.Sprintf("lower press %d wheel %d enter %d; upper press %d wheel %d enter %d context %d", + lower.press.Load(), lower.wheel.Load(), lower.enter.Load(), + upper.press.Load(), upper.wheel.Load(), upper.enter.Load(), upper.context.Load()) + } + setMode := func(mode core.WindowPointerEvents) { + t.Helper() + cx.Post(func() { cx.SetWindowPointerEvents(mode) }) + wait("the pointer mode", func() bool { + var applied bool + onMain(t, top, func(w *window) { applied = w.pointerMode == mode }) + return applied + }, func() string { return fmt.Sprint(mode) }) + raise() + // The window still shows its content, layered or not. + if got, ok := waitForPixel(t, top, int32(200*scale), int32(220*scale), 0x2244aa, 2*time.Second); !ok { + t.Errorf("with %v the island shows #%06x, want #2244aa", mode, got) + } + } + // click presses at x, y, where to must hear it and other must not. + click := func(x, y float64, to, other *atomic.Int32) { + t.Helper() + before, otherBefore := to.Load(), other.Load() + leave() + move(x, y) + input(leftDown, 0) + input(leftUp, 0) + wait(fmt.Sprintf("a press at %v, %v", x, y), func() bool { return to.Load() > before }, counts) + time.Sleep(50 * time.Millisecond) + if other.Load() != otherBefore { + t.Errorf("the press at %v, %v also reached the other window: %s", x, y, counts()) + } + } + // taken presses at x, y, where the upper window, which has nothing + // there, takes the press from the lower one. + taken := func(x, y float64) { + t.Helper() + before := lower.press.Load() + leave() + move(x, y) + input(leftDown, 0) + input(leftUp, 0) + time.Sleep(200 * time.Millisecond) + if lower.press.Load() != before { + t.Errorf("the press at %v, %v went through the window: %s", x, y, counts()) + } + } + // hoverAndWheel enters at x, y and turns the wheel, which win must hear. + hoverAndWheel := func(x, y float64, win, other *livePointerCounts) { + t.Helper() + entered, scrolled, otherScrolled := win.enter.Load(), win.wheel.Load(), other.wheel.Load() + leave() + move(x, y) + input(wheel, -120) + wait(fmt.Sprintf("hover and wheel at %v, %v", x, y), func() bool { + return win.enter.Load() > entered && win.wheel.Load() > scrolled + }, counts) + if other.wheel.Load() != otherScrolled { + t.Errorf("the wheel at %v, %v also reached the other window: %s", x, y, counts()) + } + } + raise() + taken(500, 350) + setMode(core.WindowPointerNone) + click(200, 220, &lower.press, &upper.press) + click(500, 350, &lower.press, &upper.press) + hoverAndWheel(200, 220, &lower, &upper) + + setMode(core.WindowPointerPainted) + click(200, 220, &upper.press, &lower.press) + hoverAndWheel(200, 220, &upper, &lower) + click(500, 350, &lower.press, &upper.press) + raise() + hoverAndWheel(500, 350, &lower, &upper) + raise() + leave() + move(200, 220) + context := upper.context.Load() + input(rightDown, 0) + input(rightUp, 0) + wait("the island's context menu", func() bool { return upper.context.Load() > context }, counts) + var before, after rect + getWindowRect.Call(top, uintptr(unsafe.Pointer(&before))) + // A control in the drag strip takes its own press. + click(120, 120, &upper.press, &lower.press) + getWindowRect.Call(top, uintptr(unsafe.Pointer(&after))) + if after != before { + t.Error("a press on a control in the drag strip moved the window") + } + // The strip itself drags the window. + raise() + leave() + move(200, 120) + input(leftDown, 0) + o := origin() + for i := 1; i <= 8; i++ { + setCursorPos.Call(uintptr(o.X+int32((200+float64(i)*5)*scale)), uintptr(o.Y+int32((120+float64(i)*5)*scale))) + time.Sleep(20 * time.Millisecond) + } + input(leftUp, 0) + wait("a WindowDrag of the island's strip", func() bool { + getWindowRect.Call(top, uintptr(unsafe.Pointer(&after))) + return after.Left != before.Left && after.Top != before.Top + }, func() string { return fmt.Sprint(before, after) }) + // The lower window stays where the upper one was, so put them back. + setWindowPos.Call(top, 0, uintptr(before.Left), uintptr(before.Top), 0, 0, swpNoSize|swpNoZOrder|swpNoActivate) + time.Sleep(100 * time.Millisecond) + + setMode(core.WindowPointerAuto) + taken(500, 350) + click(200, 220, &upper.press, &lower.press) + if find(upperTitle) != top || find(lowerTitle) != bottom { + t.Error("changing pointer modes replaced a window") + } +}