Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/architecture/application.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
2 changes: 1 addition & 1 deletion docs/roadmap.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
188 changes: 188 additions & 0 deletions internal/platform/linux/resize_live_native_test.go
Original file line number Diff line number Diff line change
@@ -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()
}
}
162 changes: 162 additions & 0 deletions internal/platform/windows/resize_live_native_test.go
Original file line number Diff line number Diff line change
@@ -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()
}
}
Loading