Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
b6b49ed
feat(multiselect): add the opt-in multi-select page control
t8y2 Nov 19, 2026
830bf29
feat(base): name menu rows and scrollbar values for the page
t8y2 Nov 19, 2026
71240e2
feat(ui): target a control's slot and anchor following scrolls
t8y2 Nov 19, 2026
9431c74
fix(linux): allow paste from an image-only X11 clipboard
caichangqing1120 Nov 19, 2026
90f8de4
fix(linux): scale bitmaps in the CPU renderer
caichangqing1120 Nov 19, 2026
4cb3557
fix(linux): keep the selection when a GTK preedit is cancelled
caichangqing1120 Nov 19, 2026
089cd85
fix(darwin): select words on double-click and the value on triple-click
lizzzzz777 Nov 19, 2026
883a3c0
fix(app): preserve native window capabilities
Ezreal-byte Nov 19, 2026
59922de
test(app): cover fullscreen forwarding through the result window
lizzzzz777 Nov 19, 2026
85c2a15
feat(windows): add transparent drag previews
Ezreal-byte Nov 19, 2026
9e8bd3d
feat(hierarchypicker): add the opt-in hierarchical picker
t8y2 Nov 19, 2026
f382399
docs: record that Begin belongs to the style layer
t8y2 Nov 19, 2026
2225dd0
docs(website): stop showing Begin recipes as application usage
t8y2 Nov 19, 2026
2fd0534
test(ui): pin page popover and drawer motion to their components
t8y2 Nov 19, 2026
c245aed
docs(website): show page usage above component examples
t8y2 Nov 19, 2026
0a98064
feat(tree): compress only the indent, not the row's depth
t8y2 Nov 19, 2026
c937f50
docs(website): keep canvas-only snippets out of component pages
t8y2 Nov 19, 2026
382235d
docs(website): label page APIs apart from component source
t8y2 Nov 19, 2026
d73f9ac
refactor(base): move tree navigation into the engine
t8y2 Nov 19, 2026
e18e371
docs(website): add page usages for layout and tooltip controls
t8y2 Nov 19, 2026
44c3c53
docs(website): link the page API source its usage comes from
t8y2 Nov 19, 2026
eba4dcb
docs(website): show the table example's data in its page usage
t8y2 Nov 19, 2026
7a4b6f7
test(ui): pin switch, hover and scroll motion frame by frame
t8y2 Nov 19, 2026
2f13cac
docs(website): show one page API and only matching example code
t8y2 Nov 19, 2026
a5da67a
docs(website): show each example's actual source
t8y2 Nov 19, 2026
af1890a
docs(website): show caller-facing page snippets per example
t8y2 Nov 19, 2026
dd549b0
feat(ui): add the styled page toggle
t8y2 Nov 19, 2026
9d4672a
feat(ui): add the page range slider
t8y2 Nov 19, 2026
18cf839
docs(website): center the docs grid and restyle code blocks
t8y2 Nov 19, 2026
e83773b
docs(website): localize snippets and refine the component presentation
t8y2 Nov 19, 2026
0db15f4
docs(website): shrink the copy control and dismiss its notice
t8y2 Nov 19, 2026
82b73d5
docs(website): keep the copy control small and visible
t8y2 Nov 19, 2026
eb04a15
docs(website): drop the copied notice
t8y2 Nov 19, 2026
8363b0e
docs(website): set the code font to Geist Mono
t8y2 Nov 19, 2026
eaf280d
docs(website): give every example a page call site
t8y2 Nov 19, 2026
c028841
fix(windows): run a hidden window's wake without waiting for WM_PAINT
t8y2 Nov 19, 2026
362a5db
feat(ui): add page-first views for canvas components
t8y2 Nov 19, 2026
9a0dfc3
feat(ui): add page views for form and layout components
t8y2 Nov 19, 2026
da9f1a8
refactor(componentdemo): drive previews through page controls
t8y2 Nov 19, 2026
93f917f
feat(web): render with WebGL2 and fall back to Canvas2D
t8y2 Nov 19, 2026
2b9314d
fix(website): type demo page snippets
t8y2 Nov 19, 2026
bf28ee7
fix(linux): report visibility when Hide races the window manager
t8y2 Nov 19, 2026
b1356ff
test(conformance): hide the window before opening the panel
t8y2 Nov 19, 2026
d812524
feat(ui): close page control state gaps
t8y2 Nov 19, 2026
6ff3a8d
feat(website): refresh component docs layout and previews
t8y2 Nov 19, 2026
8f47260
fix(linux): draw the frame on a compositing desktop without synced re…
t8y2 Nov 19, 2026
92f9497
feat(ui): add parity checks and remaining page controls
t8y2 Nov 19, 2026
aa12f48
feat(a11y): propagate invalid state to assistive technology
t8y2 Nov 19, 2026
1b630a8
docs(ui): list the joined button and toggle group packages
t8y2 Nov 19, 2026
fa5301b
refactor(ui): drop the view suffix from opt-in page packages
t8y2 Nov 19, 2026
3291b6e
refactor(ui): name page package types by role
t8y2 Nov 19, 2026
92a6d59
fix(packaging): treat the GPU loader as optional
t8y2 Nov 19, 2026
29f5332
fix(docs): skip host-tool snippet compilation under wasm
t8y2 Nov 19, 2026
14c2167
test(ui): prove slot-hosted page controls paint like components
t8y2 Nov 19, 2026
cf4408e
docs: document optional page packages and the slot boundary
t8y2 Nov 19, 2026
4a12405
fix(gfx): keep invalid state across memo replay
t8y2 Nov 19, 2026
a14e377
docs(ui): repair renamed package docs
t8y2 Nov 19, 2026
d18933d
docs: keep optional package docs in sync
t8y2 Nov 19, 2026
dff3ae6
docs: state the optional package import boundary accurately
t8y2 Nov 19, 2026
1e84235
fix(gfx): replay the complete hit semantics and hit texts
t8y2 Nov 19, 2026
6590b05
perf(app): mirror only the semantics a repaint changed
t8y2 Nov 19, 2026
617a9ac
test(app): add the empty-window first-frame baseline
t8y2 Nov 19, 2026
5603663
perf(render): shrink retained instances on deletion
t8y2 Nov 19, 2026
be6157e
perf(scene): keep shape geometry out of rectangle changes
t8y2 Nov 19, 2026
3abd9fd
perf(scene): size the shape scratch to the shapes in the batch
t8y2 Nov 19, 2026
ba763de
merge: sync upstream before Lithe search release
xiaoyumuxi Nov 19, 2026
b7e344e
docs: include fork textview in optional package inventories
xiaoyumuxi Nov 19, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
18 changes: 13 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,12 @@ jobs:
GOOS=js GOARCH=wasm go build \
./cmd/component-preview ./cmd/gallery-web \
./examples/guides/hello ./examples/guides/webview
# The docs previews and the gallery build through the same public command
# an application uses, so a break in the deployment path fails here.
- name: build the public web entry points
run: |
go run ./cmd/viva build --target web ./cmd/component-preview -o build/component-preview-web
go run ./cmd/viva build --target web ./cmd/gallery-web -o build/gallery-web

# The real browser gate. It builds the fixture and drives it through the
# three engines in parallel with the wasm tests above; most of its elapsed
Expand Down Expand Up @@ -197,12 +203,14 @@ jobs:
tools/webcheck/node_modules/.bin/playwright install --with-deps chromium firefox webkit
# Each engine gets its own step so a failure names the engine that broke
# and the others still report their own result.
- name: drive the browser verification page (chromium)
run: node tools/webcheck/check.mjs --dir build/webcheck --browser chromium
- name: drive the browser verification page (chromium, WebGL2)
run: node tools/webcheck/check.mjs --dir build/webcheck --browser chromium --renderer webgl2
- name: drive the browser verification page (chromium, Canvas2D fallback)
run: node tools/webcheck/check.mjs --dir build/webcheck --browser chromium --renderer canvas2d
- name: drive the browser verification page (firefox)
run: node tools/webcheck/check.mjs --dir build/webcheck --browser firefox
run: node tools/webcheck/check.mjs --dir build/webcheck --browser firefox --renderer auto
- name: drive the browser verification page (webkit)
run: node tools/webcheck/check.mjs --dir build/webcheck --browser webkit
run: node tools/webcheck/check.mjs --dir build/webcheck --browser webkit --renderer auto

# The whole test suite except the packages that carry darwin-only files, split
# over several runners. .github/scripts/test-packages.sh decides what this
Expand Down Expand Up @@ -293,7 +301,7 @@ jobs:
# native structure ABI tests are here for the same reason: they build only
# on Windows.
- name: Material contracts and controls (WARP)
run: go test ./internal/platform/windows ./ui ./components ./headless ./app -run 'Test(Backdrop|WindowBackdrop|Notification|TaskbarCreated|CompositionClear|CompositionFallback|CompositionCreation|CustomBackdrop|AcrylicAccent|LegacyAcrylic|RoundedOutline|Translucent|MonospaceFamilies|FontWeights|(The)?MonoWeights|(The)?InterfaceWeights|EveryListedFamilyResolves|EngineReportsTheFontsUnderline|AlwaysOnTop|SaveDialogCheckbox|FileIcon|NativeStructureABI|ResizePresents|WindowSwapChain|LiveResize|FlipWindowResize|RedrawWaits|ContinuousRedraw|NoOpFrame|SameSize|ZeroSize|ResizeTimer|RedrawQueue|NativeRedrawMessage|CompositionSupersededFrame)' -count=1 -v
run: go test ./internal/platform/windows ./ui ./components ./headless ./app -run 'Test(Backdrop|WindowBackdrop|Notification|TaskbarCreated|CompositionClear|CompositionFallback|CompositionCreation|CustomBackdrop|AcrylicAccent|LegacyAcrylic|RoundedOutline|Translucent|MonospaceFamilies|FontWeights|(The)?MonoWeights|(The)?InterfaceWeights|EveryListedFamilyResolves|EngineReportsTheFontsUnderline|AlwaysOnTop|SaveDialogCheckbox|FileIcon|NativeStructureABI|ResizePresents|WindowSwapChain|LiveResize|FlipWindowResize|RedrawWaits|ContinuousRedraw|NoOpFrame|SameSize|ZeroSize|ResizeTimer|RedrawQueue|NativeRedrawMessage|CompositionSupersededFrame|DragPreview)' -count=1 -v
- name: Terminal keyboard routing
run: go test ./internal/platform/windows -run '^TestATerminalGetsEditingKeysAndChordsAsRawKeys$' -count=1 -v
- name: Native Windows global shortcut
Expand Down
7 changes: 7 additions & 0 deletions .github/workflows/website.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,15 @@ on:
- "website/**"
- "components/**"
- "internal/componentdemo/**"
- "internal/framebuild/**"
- "internal/platform/web/**"
- "internal/previewmeasure/**"
- "internal/render/**"
- "internal/scene/**"
- "internal/webbuild/**"
- "tools/docs/**"
- "cmd/component-preview/**"
- "cmd/viva/**"
- "ui/**"
- "app/**"
- "text/**"
Expand Down
21 changes: 13 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,11 @@ opening one, `viva.toml`, and an `AGENTS.md` describing the programming model.
platform's own bundle.

Requirements: Go 1.26 or newer (viva fetches it when missing). On macOS the Xcode command-line tools, because
Viva reaches Cocoa and Metal through cgo; on Linux, X11 with the system XCB and
Vulkan loaders; on Windows, Win32 with Direct3D 11 and DirectWrite. Viva loads
the system libraries at runtime and bundles none of them.
Viva reaches Cocoa and Metal through cgo; on Linux, X11 with the system XCB,
Pango and Cairo libraries, and a Vulkan loader and driver for GPU acceleration
(a machine without them draws on the CPU); on Windows, Win32 with Direct3D 11
and DirectWrite. Viva loads the system libraries at runtime and bundles none of
them.

The current release is `v0.6.5`; name it explicitly (`@v0.6.5`) to pin it. Guides,
the API reference, and a component catalog with live previews live in
Expand All @@ -66,7 +68,8 @@ and how to work on the framework rather than with it.
## Scope

Viva targets native desktop applications on macOS, Windows, and Linux, and
treats WebAssembly/Canvas2D as a supported web deployment target. Both targets
treats WebAssembly as a supported web deployment target, rendered with WebGL2
and falling back to Canvas2D when WebGL2 is unavailable. Both targets
share components, input, text, focus and accessibility semantics; capabilities
the browser does not have are reported through explicit asynchronous APIs and
`Capability`, never faked. The web target must not add cost to native builds.
Expand Down Expand Up @@ -210,8 +213,9 @@ without changing build commands. Unconfigured windows keep the ordinary renderer
limits, fallback behavior and the platforms actually verified.

Native label renderers draw single-line labels. The browser target runs the same
components on the Canvas2D backend; see [Web deployment](docs/web-deployment.md)
for its capability matrix and hosting requirements.
components on the WebGL2 backend, with Canvas2D as its fallback; see
[Web deployment](docs/web-deployment.md) for its capability matrix and hosting
requirements.

## Run the repository

Expand All @@ -224,8 +228,9 @@ tools/build_web.sh # viva build --target web, then serves http://127.0
go run ./tools/docs -check # the API and component data the website generates from
```

The browser build paints the same Go components through the Canvas2D
WebAssembly backend. It is a deployment target, not only a gallery: file
The browser build paints the same Go components through WebGL2, falling back to
the Canvas2D WebAssembly backend when WebGL2 is unavailable or a context is
lost. It is a deployment target, not only a gallery: file
pickers, drops, clipboard, notifications, encrypted secret storage and embedded
fonts have typed asynchronous APIs. Its visual direction and measured costs are
recorded in `docs/benchmarks/m3-gallery-style-darwin-arm64.md`.
Expand Down
8 changes: 4 additions & 4 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ viva dev . # hot reload: save a file, the window updates and keeps its st

`viva init` 会写一个可直接运行的项目:一个窗口、一个不用打开窗口就能驱动它的测试、`viva.toml`,以及一份描述编程模型的 `AGENTS.md`。`viva build` 把发布程序写到 `build/`,`viva package` 写出平台自己的包。

环境要求:Go 1.26 或更新版本(缺失时 viva 会自己下载)。macOS 上需要 Xcode 命令行工具,因为 Viva 通过 cgo 访问 Cocoa 和 Metal;Linux 上需要带系统 XCB 和 Vulkan 加载库的 X11;Windows 上需要 Win32、Direct3D 11 和 DirectWrite。Viva 在运行时加载系统库,自身不捆绑任何一个。
环境要求:Go 1.26 或更新版本(缺失时 viva 会自己下载)。macOS 上需要 Xcode 命令行工具,因为 Viva 通过 cgo 访问 Cocoa 和 Metal;Linux 上需要带系统 XCB、Pango 和 Cairo 库的 X11,Vulkan 加载库和驱动用于 GPU 加速,缺失时窗口用 CPU 渲染;Windows 上需要 Win32、Direct3D 11 和 DirectWrite。Viva 在运行时加载系统库,自身不捆绑任何一个。

当前版本是 `v0.6.5`;要固定版本就写明(`@v0.6.5`)。指南、API 参考和带实时预览的组件目录在 [`website/`](website/) 里,本地用 `npm run dev` 运行;也已经发布在 [vivaui.dev](https://vivaui.dev/zh/)。

下面的一切描述的都是这个仓库:它的测量、它自己的程序,以及如何开发框架本身,而不是如何用框架。

## 范围

Viva 面向 macOS、Windows 和 Linux 上的原生桌面应用,同时把 WebAssembly/Canvas2D 作为正式的 Web 发布目标:两个目标共享组件、输入、文本、焦点和无障碍语义,浏览器缺失的能力通过显式异步 API 和 `Capability` 报告,而不是伪造原生行为。Web 目标不得给原生构建增加成本。iOS、iPadOS、Android、移动端打包,以及以触摸为主的移动运行时,明确不在范围内。不会为了保留假设中的未来移动兼容性而削弱桌面性能与原生集成。
Viva 面向 macOS、Windows 和 Linux 上的原生桌面应用,同时把 WebAssembly 作为正式的 Web 发布目标:浏览器构建优先使用 WebGL2,WebGL2 不可用时回退 Canvas2D。两个目标共享组件、输入、文本、焦点和无障碍语义,浏览器缺失的能力通过显式异步 API 和 `Capability` 报告,而不是伪造原生行为。Web 目标不得给原生构建增加成本。iOS、iPadOS、Android、移动端打包,以及以触摸为主的移动运行时,明确不在范围内。不会为了保留假设中的未来移动兼容性而削弱桌面性能与原生集成。

三个后端都直接使用操作系统自己的窗口和 GPU API,没有 WebView,也不捆绑渲染运行时。

Expand Down Expand Up @@ -83,7 +83,7 @@ Viva 面向 macOS、Windows 和 Linux 上的原生桌面应用,同时把 WebAs

Windows 后端支持 amd64 和 arm64 交叉构建,并在 Wine/DXVK 下通过平台测试以及 Gallery 的启动、指针和键盘冒烟测试。平台测试、conformance 场景,以及输入、拖放和设备丢失路径,在一台 Windows 11 虚拟机(WARP)和一台 Debian KDE/X11 机器(lavapipe)上运行;`docs/conformance.md` 记录了需要真实硬件的场景。UI Automation 在一台真实的 Windows 11 机器上由外部客户端检查(见 docs/accessibility.md),AT-SPI 在 KDE/X11 机器上针对 libatspi 检查。Linux 后端通过 Ubuntu arm64 Xvfb/llvmpipe 的 M0 和 Debian amd64 X11/Lavapipe 的保留式场景冒烟测试,包括中英混排文本和局部场景更新。macOS 运行时测试和基准在 arm64 上运行。

原生标签渲染器绘制单行标签。浏览器目标运行在 Canvas2D 后端;能力矩阵、生命周期与静态托管要求见 [Web 部署](docs/web-deployment.md)。
原生标签渲染器绘制单行标签。浏览器目标运行在 WebGL2 后端,WebGL2 不可用时回退 Canvas2D;能力矩阵、生命周期与静态托管要求见 [Web 部署](docs/web-deployment.md)。

## 运行这个仓库

Expand All @@ -96,7 +96,7 @@ tools/build_web.sh # viva build --target web,然后服务 http://127
go run ./tools/docs -check # 网站生成的 API 与组件数据
```

浏览器构建通过 Canvas2D WebAssembly 后端绘制相同的 Go 组件,并且是正式发布目标:文件选择、拖放、剪贴板、通知、加密密钥存储和内置字体都有类型化的异步 API。视觉方向与测量成本记录在 `docs/benchmarks/m3-gallery-style-darwin-arm64.md`。
浏览器构建通过 WebGL2(不可用时回退 Canvas2D)WebAssembly 后端绘制相同的 Go 组件,并且是正式发布目标:文件选择、拖放、剪贴板、通知、加密密钥存储和内置字体都有类型化的异步 API。视觉方向与测量成本记录在 `docs/benchmarks/m3-gallery-style-darwin-arm64.md`。

## 文档网站

Expand Down
18 changes: 18 additions & 0 deletions app/accessibility_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,24 @@ func TestAccessibilityNodesCarryWhatAssistiveTechnologyNeeds(t *testing.T) {
}
}

func TestAccessibilityNodesCarryInvalid(t *testing.T) {
var canvas gfx.Canvas
config := Config{Title: "invalid", Width: 200, Height: 120}
config.Paint = func(canvas *gfx.Canvas, size gfx.Size) {
canvas.HitWithOptions(gfx.Item(1), gfx.Rect{Width: 100, Height: 24}, "Email", gfx.HitOptions{
Role: gfx.RoleTextField, Invalid: true,
})
}
painter := newTestPainter(t, &canvas, config)
if len(painter.accessibility) != 1 || !painter.accessibility[0].Invalid {
t.Fatalf("accessibility = %+v", painter.accessibility)
}
node, ok := painter.semantics.Get(painter.semanticIDs[0])
if !ok || !node.Invalid {
t.Fatalf("semantic node = %+v", node)
}
}

func TestAccessibilityPressClicksOnceAndIgnoresDisabledControls(t *testing.T) {
var canvas gfx.Canvas
var clicks []gfx.ID
Expand Down
4 changes: 3 additions & 1 deletion app/accessnodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ type AccessNode struct {
Expanded bool
Multiline bool
ReadOnly bool
// Invalid marks a control whose value failed validation.
Invalid bool
Secure bool
Focusable bool
// Expandable marks a control that opens and closes something, whatever its
Expand Down Expand Up @@ -77,7 +79,7 @@ func (driver *Driver) Accessibility() []AccessNode {
Label: node.Label, Value: node.Value, Hint: node.Hint, Description: node.Description,
Focused: node.Focused, Disabled: node.Disabled, Checked: node.Checked, Mixed: node.Mixed,
Selected: node.Selected, Expanded: node.Expanded, Multiline: node.Multiline,
ReadOnly: node.ReadOnly, Secure: node.Secure, Focusable: node.Focusable,
ReadOnly: node.ReadOnly, Invalid: node.Invalid, Secure: node.Secure, Focusable: node.Focusable,
Expandable: node.Expandable, Level: node.Level, PosInSet: node.PosInSet, SetSize: node.SetSize,
Live: node.Live, Range: node.Range,
Selection: AccessSelection{Start: node.Selection.Start, End: node.Selection.End, Valid: node.Selection.Valid},
Expand Down
6 changes: 6 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,12 @@ type Config struct {
// OnScroll receives normalized pixel deltas and the hovered hit target.
// Handled suppresses the window's default canvas scroll offset.
OnScroll func(event gfx.ScrollEvent) gfx.EventResult
// ForwardWheel, when set, receives a wheel gesture the application did not
// use, so an embedding page can scroll instead. Setting it makes the page
// own the default scroll: only a gesture the application handled scrolls
// the canvas. It is a browser deployment option and is ignored on native
// platforms.
ForwardWheel func(deltaX, deltaY float32)
// OnFileDrop receives files dragged from the system over this window: the
// pointer entering and moving with them (FileDropOver), leaving
// (FileDropLeave), and the drop. Each event carries the hit under the point;
Expand Down
66 changes: 66 additions & 0 deletions app/application_native.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,79 @@ type resultWindow struct {
waker *platform.Waker
}

// The embedded WindowControl intentionally exposes only the methods every
// native window has. Forward optional capabilities explicitly so wrapping a
// window for event-result handling does not hide resize, fullscreen,
// always-on-top, or shortcut capture support.
var _ platform.WindowSizer = resultWindow{}
var _ fullscreenControl = resultWindow{}
var _ alwaysOnTopControl = resultWindow{}
var _ shortcutCapturer = resultWindow{}
var _ titleControl = resultWindow{}
var _ platform.WindowMover = resultWindow{}

// What OpenWindow looks for in a host's window control.
var _ interface {
applyResult(gfx.EventResult) bool
requestRedraw()
runShortcut(keymap.Chord) (gfx.EventResult, bool)
} = resultWindow{}

func (window resultWindow) SetSize(width, height int) error {
sizer, ok := window.WindowControl.(platform.WindowSizer)
if !ok {
return platform.ErrWindowSizeUnsupported
}
return sizer.SetSize(width, height)
}

func (window resultWindow) SetFullscreen(fullscreen bool) error {
control, ok := window.WindowControl.(fullscreenControl)
if !ok {
return platform.ErrFullscreenUnsupported
}
return control.SetFullscreen(fullscreen)
}

func (window resultWindow) Fullscreen() bool {
control, ok := window.WindowControl.(fullscreenControl)
return ok && control.Fullscreen()
}

func (window resultWindow) SetTitle(title string) error {
control, ok := window.WindowControl.(titleControl)
if !ok {
return fmt.Errorf("%w: window titles", ErrUnsupported)
}
return control.SetTitle(title)
}

func (window resultWindow) SetAlwaysOnTop(enabled bool) error {
control, ok := window.WindowControl.(alwaysOnTopControl)
if !ok {
return platform.ErrAlwaysOnTopUnsupported
}
return control.SetAlwaysOnTop(enabled)
}

func (window resultWindow) MoveTo(origin gfx.Point) {
if control, ok := window.WindowControl.(platform.WindowMover); ok {
control.MoveTo(origin)
}
}

func (window resultWindow) unwrapWindowControl() WindowControl {
return window.WindowControl
}

func (window resultWindow) CaptureSystemShortcuts(capture bool) error {
control, ok := window.WindowControl.(shortcutCapturer)
if !ok {
return fmt.Errorf("%w: this platform keeps the system's shortcuts", ErrUnsupported)
}
return control.CaptureSystemShortcuts(capture)
}

func (window resultWindow) applyResult(result gfx.EventResult) bool {
return window.painter.applyEventResult(result)
}
Expand Down
56 changes: 56 additions & 0 deletions app/application_native_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
//go:build darwin || windows || linux

package app

import (
"errors"
"testing"
)

func TestResultWindowForwardsSetSize(t *testing.T) {
native := &sizingWindow{}
window := &Window{control: resultWindow{WindowControl: native}}
if err := window.SetSize(1280, 720); err != nil {
t.Fatal(err)
}
if native.width != 1280 || native.height != 720 {
t.Fatalf("SetSize = %dx%d", native.width, native.height)
}

unsupported := &Window{control: resultWindow{WindowControl: struct{ WindowControl }{}}}
if err := unsupported.SetSize(800, 600); !errors.Is(err, ErrUnsupported) {
t.Fatalf("wrapped unsupported window error = %v", err)
}
}

func TestResultWindowForwardsAlwaysOnTop(t *testing.T) {
native := &topmostTestControl{}
window := &Window{control: resultWindow{WindowControl: native}}
if err := window.SetAlwaysOnTop(true); err != nil {
t.Fatal(err)
}
if !window.AlwaysOnTop() || len(native.requests) != 1 || !native.requests[0] {
t.Fatalf("always-on-top request did not reach the native window: requests=%v", native.requests)
}

unsupported := &Window{control: resultWindow{WindowControl: &fakeWindow{}}}
if err := unsupported.SetAlwaysOnTop(true); !errors.Is(err, ErrUnsupported) {
t.Fatalf("wrapped unsupported window error = %v", err)
}
}

func TestResultWindowForwardsSetTitle(t *testing.T) {
native := &titleTestControl{}
window := &Window{control: resultWindow{WindowControl: native}}
if err := window.SetTitle("project – main.go"); err != nil {
t.Fatal(err)
}
if len(native.titles) != 1 || native.titles[0] != "project – main.go" {
t.Fatalf("titles = %q", native.titles)
}

unsupported := &Window{control: resultWindow{WindowControl: &fakeWindow{}}}
if err := unsupported.SetTitle("x"); !errors.Is(err, ErrUnsupported) {
t.Fatalf("wrapped unsupported window error = %v", err)
}
}
Loading
Loading