Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
d38d685
fix(darwin): keep the system from moving the window on a press in the…
t8y2 Dec 1, 2026
0ccdbe5
feat(app): support selecting multiple local directories
ken0912 Dec 1, 2026
e73ff60
fix(components): draw a scrolled field's line to the field's edge
t8y2 Dec 1, 2026
a3b9ea1
fix(ui): start a Drawer below the titlebar strip
t8y2 Dec 1, 2026
429e7dd
fix(ui): keep a drawer full height and clear the titlebar in its header
t8y2 Dec 1, 2026
4a08d96
feat(windows): expose terminal selection bounds to UI Automation
ken0912 Dec 1, 2026
543a386
feat(windows): make low-memory D3D11 uploads opt-in
lijhnihaoa Dec 1, 2026
599b689
fix(darwin): draw the window on the CPU when Metal is unavailable
t8y2 Dec 1, 2026
9ee57b9
fix(darwin): report accessibility frames in screen coordinates
t8y2 Dec 1, 2026
30ca2d6
test(darwin): stub the text overlay callback in the native tests
t8y2 Dec 1, 2026
e0b8cac
feat(darwin): render headless frames on the CPU without Metal
t8y2 Dec 1, 2026
68f33d7
fix(framebuild): leave room for glyphs overhanging a grid line's ends
t8y2 Dec 1, 2026
8f5b957
fix(darwin): report the display scale with the window's size
t8y2 Dec 1, 2026
4b00f75
feat(singleinstance): let a Windows launch grant foreground to the pr…
ken0912 Dec 2, 2026
2bff845
feat(keymap): bind shortcuts to the middle and side mouse buttons
xiaoyumuxi Dec 2, 2026
dd048cd
fix(base): keep on-screen list rows still when rows above are measured
xiaoyumuxi Dec 2, 2026
148791c
feat(app): add Window.RequestAttention for a background window
woliubang256 Dec 2, 2026
a50a9d1
fix(base): keep a splitter's keys under its renamed hit and its ratio…
t8y2 Dec 2, 2026
0fb56e9
revert(base): drop the splitter ratio hold in rooms too tight for the…
t8y2 Dec 2, 2026
9bdf2a6
feat(headless): deliver assistive-technology requests in tests
t8y2 Dec 2, 2026
8a56383
feat(app): trace why each frame is painted with VIVA_TRACE=1
t8y2 Dec 2, 2026
ebebb0b
feat(a11y): expose column header sort and multi-select lists
t8y2 Dec 2, 2026
64b6dd8
feat(ui): choose several Table rows and cycle header sort to unsorted
t8y2 Dec 2, 2026
49947f7
feat(raster): track damage as a region and present it through IOSurfaces
t8y2 Dec 2, 2026
8e64737
fix(darwin): keep resize reporting out of AppKit's layout pass
t8y2 Dec 2, 2026
23e5b1e
Merge remote-tracking branch 'upstream/main' into sync/upstream-8e647374
1lck Dec 2, 2026
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
13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
<a href="https://docs.qq.com/doc/DVXZWdWFscGxjaWVP"><img src="https://img.shields.io/badge/Viva_交流群-扫码加入-07C160?style=for-the-badge&logo=wechat&logoColor=white" alt="Viva 交流群" /></a>
</p>

Viva is a Go-first, GPU-native desktop framework. Applications draw through
the platform's own window and GPU APIs — Cocoa and Metal, Win32 and Direct3D 11,
XCB and Vulkan — with no WebView, no browser engine, and no bundled runtime. It
Viva is a Go-first desktop framework. Applications draw through the platform's
own window and GPU APIs — Cocoa and Metal, Win32 and Direct3D 11, XCB and
Vulkan — and, on a machine with no graphics device, with Viva's own CPU
rasterizer. There is no WebView, no browser engine, and no bundled runtime. It
is aimed at small binaries, low idle resource usage, and direct access to native
platform capabilities. An application that needs web content can host the
system's own web view beside Viva's drawing (WebKitGTK, WKWebView, WebView2): it
Expand Down Expand Up @@ -50,7 +51,8 @@ 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,
Viva reaches Cocoa and Metal through cgo (a Mac with no Metal device, like an
Intel virtual machine, draws on the CPU); on Linux, X11 with the system XCB,
Pango and Cairo libraries (the opt-in GTK 3 shell, `-tags vivagtk`, is a native
Wayland client and needs the system's GTK 3), and a Vulkan loader and driver for GPU acceleration
(a machine without them draws on the CPU); on Windows, Win32 with Direct3D 11
Expand Down Expand Up @@ -170,6 +172,9 @@ WebView and no bundled rendering runtime.
- A separate retained semantic accessibility tree.
- Direct CoreText shaping, system-font fallback, GPU-composited text textures,
and a bounded measurement cache.
- A CPU renderer for a Mac with no Metal device (an Intel virtual machine): the
window and headless screenshots are drawn by the same retained scene and
CoreText rasterizer, and `VIVA_SOFTWARE_RENDERING=1` asks for it on any Mac.
- Experimental Windows shell with Win32 events, D3D11 retained rendering,
embedded DXBC shaders, DirectWrite measurement, and bounded GDI label
textures; native builds do not load a shader compiler.
Expand Down
5 changes: 3 additions & 2 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<a href="https://docs.qq.com/doc/DVXZWdWFscGxjaWVP"><img src="https://img.shields.io/badge/Viva_交流群-扫码加入-07C160?style=for-the-badge&logo=wechat&logoColor=white" alt="Viva 交流群" /></a>
</p>

Viva 是一个 Go 优先、GPU 原生的桌面框架。应用通过操作系统自己的窗口和 GPU API 绘制——Cocoa 与 Metal、Win32 与 Direct3D 11、XCB 与 Vulkan——不使用 WebView,不捆绑浏览器引擎,也不捆绑运行时。它追求小的二进制产物、低的空闲资源占用,以及对原生平台能力的直接访问。需要展示网页内容的应用可以在 Viva 的绘制旁边承载系统自带的网页视图(WebKitGTK、WKWebView、WebView2):它是可选的,第一个页面打开时才加载,不捆绑任何东西。
Viva 是一个 Go 优先的桌面框架。应用通过操作系统自己的窗口和 GPU API 绘制——Cocoa 与 Metal、Win32 与 Direct3D 11、XCB 与 Vulkan——在没有图形设备的机器上,则用 Viva 自带的 CPU 光栅器绘制。它不使用 WebView,不捆绑浏览器引擎,也不捆绑运行时。它追求小的二进制产物、低的空闲资源占用,以及对原生平台能力的直接访问。需要展示网页内容的应用可以在 Viva 的绘制旁边承载系统自带的网页视图(WebKitGTK、WKWebView、WebView2):它是可选的,第一个页面打开时才加载,不捆绑任何东西。

下面的状态列表是今天实际能跑的东西。

Expand All @@ -32,7 +32,7 @@ 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、Pango 和 Cairo 库的 X11(可选的 GTK 3 外壳用 `-tags vivagtk` 构建,是原生 Wayland 客户端,需要系统的 GTK 3),Vulkan 加载库和驱动用于 GPU 加速,缺失时窗口用 CPU 渲染;Windows 上需要 Win32、Direct3D 11 和 DirectWrite。Viva 在运行时加载系统库,自身不捆绑任何一个。
环境要求:Go 1.26 或更新版本(缺失时 viva 会自己下载)。macOS 上需要 Xcode 命令行工具,因为 Viva 通过 cgo 访问 Cocoa 和 Metal(没有 Metal 设备的 Mac,例如 Intel 虚拟机,用 CPU 绘制);Linux 上需要带系统 XCB、Pango 和 Cairo 库的 X11(可选的 GTK 3 外壳用 `-tags vivagtk` 构建,是原生 Wayland 客户端,需要系统的 GTK 3),Vulkan 加载库和驱动用于 GPU 加速,缺失时窗口用 CPU 渲染;Windows 上需要 Win32、Direct3D 11 和 DirectWrite。Viva 在运行时加载系统库,自身不捆绑任何一个。

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

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

- macOS 原生窗口与事件循环。
- 直接 Metal 清屏与呈现。
- 没有 Metal 设备的 Mac(例如 Intel 虚拟机)由 CPU 渲染器绘制窗口和无头截图:与 GPU 路径共用同一套保留场景,文字由 CoreText 给出;`VIVA_SOFTWARE_RENDERING=1` 可在任何 Mac 上强制使用它。
- 扁平的分代保留式场景,节点标识稳定。
- 合并后的 O(1) 局部矩形更新,热路径零分配。
- 预编译 Metal 着色器与实例化矩形渲染。
Expand Down
11 changes: 8 additions & 3 deletions app/accessibility.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"unicode/utf8"

"github.com/vivaui/viva/gfx"
"github.com/vivaui/viva/internal/frametrace"
"github.com/vivaui/viva/internal/input"
"github.com/vivaui/viva/internal/interaction"
"github.com/vivaui/viva/internal/platform"
Expand All @@ -21,15 +22,19 @@ func (painter *painter) accessibilityHandler(config *Config) platform.Accessibil
}

// accessibleHit finds the control a request names. Labels share their control's
// ID and are not controls, and a region declared by Container has no ID.
// ID and are not controls, a region declared by Container has no ID, and a
// control behind an open modal is not there for assistive technology.
func (painter *painter) accessibleHit(id gfx.ID) (gfx.Hit, bool) {
return interaction.Control(painter.canvas.Hits(), id)
return interaction.Control(painter.canvas.Hits(), painter.canvas.TrappedFocusScope(), id)
}

// accessibilityRequest carries out one request the way the keyboard or the
// mouse would, through the same paths, so a control cannot tell assistive
// technology from a person.
func (painter *painter) accessibilityRequest(request platform.AccessibilityRequest, present func(platform.Frame) error) (bool, error) {
if painter.trace != nil {
painter.trace.Event(frametrace.Accessibility, "")
}
hit, ok := painter.accessibleHit(request.Node)
if !ok || (hit.Disabled && !(request.Action == platform.AccessibilityFocus && hit.FocusableDisabled)) {
return false, nil
Expand Down Expand Up @@ -154,7 +159,7 @@ func (painter *painter) editText(hit gfx.Hit, request platform.AccessibilityRequ
}

func (painter *painter) presentRepaint(present func(platform.Frame) error) error {
frame, err := painter.repaint()
frame, err := painter.repaint(frametrace.Accessibility)
if err != nil {
return err
}
Expand Down
32 changes: 31 additions & 1 deletion app/accessibility_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"testing"

"github.com/vivaui/viva/gfx"
"github.com/vivaui/viva/internal/frametrace"
"github.com/vivaui/viva/internal/platform"
"github.com/vivaui/viva/text"
)
Expand All @@ -16,6 +17,35 @@ func (p *presented) present(frame platform.Frame) error {
return nil
}

func TestTerminalPublishesSelectedTextAndItsChangingBounds(t *testing.T) {
var canvas gfx.Canvas
selection := &gfx.TextSelection{Text: "界a", Bounds: []gfx.Rect{{X: 8, Y: 12, Width: 24, Height: 16}}}
secure := false
config := Config{Width: 200, Height: 100}
config.Paint = func(canvas *gfx.Canvas, size gfx.Size) {
canvas.HitWithOptions(gfx.Item(1), gfx.Rect{Width: size.Width, Height: size.Height}, "Terminal",
gfx.HitOptions{Role: gfx.RoleTerminal, Autofocus: true, Secure: secure, TextSelection: selection})
}
p := newTestPainter(t, &canvas, config)
first := p.accessibility[0]
if first.Value != "界a" || !first.ReadOnly || first.TextSelection != selection ||
first.Selection != (platform.AccessibilitySelection{End: 2, Valid: true}) {
t.Fatalf("selected terminal text = %+v", first)
}
selection = &gfx.TextSelection{Text: "界a", Bounds: []gfx.Rect{{X: 8, Y: 44, Width: 24, Height: 16}}}
frame, err := p.repaint(frametrace.Invalidate)
if err != nil || len(frame.Accessibility) == 0 || frame.Accessibility[0].TextSelection != selection ||
platform.DiffAccessibility(first, frame.Accessibility[0])&platform.ChangedSelection == 0 {
t.Fatalf("moving the selection to the same word on another line did not publish it: %v, %v", frame.Accessibility, err)
}
secure = true
frame, err = p.repaint(frametrace.Invalidate)
if err != nil || len(frame.Accessibility) == 0 || frame.Accessibility[0].TextSelection != nil ||
frame.Accessibility[0].Value != "" || frame.Accessibility[0].Selection.Valid {
t.Fatalf("secure terminal exposed a selection: %v, %v", frame.Accessibility, err)
}
}

func TestAccessibilityNodesCarryWhatAssistiveTechnologyNeeds(t *testing.T) {
var canvas gfx.Canvas
config := Config{Title: "a11y", Width: 200, Height: 120}
Expand Down Expand Up @@ -254,7 +284,7 @@ func TestSyncSemanticsUpdatesZeroIDContainerOnIncrementalPaint(t *testing.T) {
width = 904
role = gfx.RoleGroup
label = "Article A"
if err := driver.redraw(); err != nil {
if err := driver.redraw(frametrace.Invalidate); err != nil {
t.Fatal(err)
}
nodes := driver.Accessibility()
Expand Down
94 changes: 93 additions & 1 deletion app/accessnodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package app

import (
"github.com/vivaui/viva/gfx"
"github.com/vivaui/viva/internal/platform"
"github.com/vivaui/viva/internal/semantic"
)

Expand Down Expand Up @@ -39,6 +40,10 @@ type AccessNode struct {
// Expandable marks a control that opens and closes something, whatever its
// state now.
Expandable bool
// MultiSelectable marks a list whose items can be chosen several at once.
MultiSelectable bool
// Sort is how a column header orders the rows of its table.
Sort gfx.SortDirection

// Level is a heading's level or a tree item's depth; zero when not stated.
Level uint8
Expand Down Expand Up @@ -81,13 +86,98 @@ func (driver *Driver) Accessibility() []AccessNode {
Selected: node.Selected, Expanded: node.Expanded, Multiline: node.Multiline,
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,
Live: node.Live, Range: node.Range, Sort: node.Sort, MultiSelectable: node.MultiSelectable,
Selection: AccessSelection{Start: node.Selection.Start, End: node.Selection.End, Valid: node.Selection.Valid},
}
}
return out
}

// AccessAction is something assistive technology asks a node to do: the
// actions every platform adapter (UI Automation patterns, AT-SPI actions and
// values, NSAccessibility actions) turns its own requests into.
type AccessAction uint8

const (
// AccessPress is the node's default action: click a button or a link,
// toggle a checkbox or a switch, choose a radio, a tab, an option or a menu
// item, open or close a disclosure; on a text field it places the caret.
AccessPress AccessAction = iota + 1
// AccessFocus gives the node the keyboard.
AccessFocus
// AccessIncrement and AccessDecrement move a slider by one step.
AccessIncrement
AccessDecrement
// AccessSetNumber moves a slider to AccessRequest.Number.
AccessSetNumber
// AccessSetText replaces the text of a text field with AccessRequest.Text.
AccessSetText
// AccessSetSelection selects the span AccessRequest.Start..End (code
// points) of a text field's text, a caret when they are equal.
AccessSetSelection
)

// AccessRequest is one request from assistive technology to the node Node
// names (AccessNode.ID).
type AccessRequest struct {
Node gfx.ID
Action AccessAction
// Number is the value of AccessSetNumber.
Number float64
// Text is the value of AccessSetText.
Text string
// Start and End are the span of AccessSetSelection, in code points.
Start, End int32
}

// platformAction is the request's action as the platform adapters deliver it.
func (action AccessAction) platformAction() (platform.AccessibilityAction, bool) {
switch action {
case AccessPress:
return platform.AccessibilityPress, true
case AccessFocus:
return platform.AccessibilityFocus, true
case AccessIncrement:
return platform.AccessibilityIncrement, true
case AccessDecrement:
return platform.AccessibilityDecrement, true
case AccessSetNumber:
return platform.AccessibilitySetNumber, true
case AccessSetText:
return platform.AccessibilitySetText, true
case AccessSetSelection:
return platform.AccessibilitySetSelection, true
}
return 0, false
}

// PerformAccess carries out request as a screen reader or another assistive
// technology would: it is handed to the same handler a window's platform
// adapter calls, so a modal that hides the node, a disabled control, a
// read-only or secure field and a role that does not take the action refuse it
// as they do on every platform. handled is false when the node is gone or
// refused; err is a failure of the repaint it caused. Background work posted
// before it is applied first, as for any other input.
func (driver *Driver) PerformAccess(request AccessRequest) (handled bool, err error) {
if err := driver.Pump(); err != nil {
return false, err
}
action, ok := request.Action.platformAction()
if !ok {
return false, nil
}
handler := driver.painter.accessibilityHandler(&driver.config)
if handler == nil {
return false, nil
}
// A window hands each repaint to the screen; the driver keeps only the
// painter's state, as it does for a key or a click.
return handler(platform.AccessibilityRequest{
Node: request.Node, Action: action, Number: request.Number,
Text: request.Text, Start: request.Start, End: request.End,
}, func(platform.Frame) error { return nil })
}

// accessRole maps the semantic role the platform adapters receive back to the
// gfx.Role the application declared. Roles that have no gfx counterpart (a
// text, an image, the application itself) are zero.
Expand Down Expand Up @@ -135,6 +225,8 @@ func accessRole(role semantic.Role) gfx.Role {
return gfx.RoleSeparator
case semantic.RoleProgress:
return gfx.RoleProgressBar
case semantic.RoleColumnHeader:
return gfx.RoleColumnHeader
}
return 0
}
6 changes: 6 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,12 @@ type Config struct {
// Without one, a WindowPanel is centered on the screen.
Anchor StatusAnchor
ClearColor Color
// D3D11LowMemoryUploads uses a reusable upload buffer for rectangles and
// maps drawing constants and mutable label textures. This can reduce the
// private working set on some Windows graphics drivers. The default uses
// UpdateSubresource. Windows reads this option when the window opens.
// Other platforms ignore it.
D3D11LowMemoryUploads bool
// Transparent composites the window over the desktop: the part of the canvas
// left at ClearColor's alpha shows what is behind the window. It makes a
// ClearColor of zero mean fully transparent instead of the default fill, and
Expand Down
50 changes: 50 additions & 0 deletions app/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ type Window struct {
control WindowControl
closed atomic.Bool
hidden atomic.Bool
// active mirrors what the platform last reported through OnActivate and
// OnDeactivate. A hidden or minimized window is not active.
active atomic.Bool
// onShow is Config.OnShow, run when Show brings back a hidden window.
onShow func()
// minimized mirrors what the platform last reported through OnMinimize.
Expand Down Expand Up @@ -159,6 +162,7 @@ func (window *Window) Hide() {
if window == nil || window.closed.Load() || window.hidden.Swap(true) {
return
}
window.active.Store(false)
window.control.Hide()
}

Expand Down Expand Up @@ -214,6 +218,40 @@ func (window *Window) Maximized() bool {
return window != nil && window.maximized.Load()
}

// attentionControl is what a window control offers when its platform can ask
// the desktop to draw the user's attention to the window.
type attentionControl interface {
RequestAttention() error
}

// RequestAttention asks the desktop to draw the user's attention to the window
// when it is in the background: the Dock tile bounces on macOS, the taskbar
// button flashes on Windows, and the taskbar entry asks for attention on Linux.
// It is meant for something that waits on the user, such as a confirmation, and
// does nothing for the window that already has the user's attention. The call
// may come from any goroutine.
//
// macOS asks for the application, not for one window: while another window of
// the application is frontmost the call returns nil and nothing is shown. A
// window that has not yet received its first activation counts as being in the
// background.
//
// An error wrapping ErrUnsupported means this platform cannot ask. A closed
// window reports that it is closed.
func (window *Window) RequestAttention() error {
if window == nil || window.closed.Load() {
return fmt.Errorf("app: window is closed")
}
if window.active.Load() && !window.minimized.Load() {
return nil
}
control, ok := window.control.(attentionControl)
if !ok {
return fmt.Errorf("%w: window attention", ErrUnsupported)
}
return control.RequestAttention()
}

// shortcutCapturer is what a window control offers when its platform can take the system's
// shortcuts for the window.
type shortcutCapturer interface {
Expand Down Expand Up @@ -289,17 +327,29 @@ func (application *Application) OpenWindow(config Config, canvas *gfx.Canvas) (*
}
onActivate := config.OnActivate
config.OnActivate = func() {
window.active.Store(true)
application.setActive(window)
if onActivate != nil {
onActivate()
}
}
onDeactivate := config.OnDeactivate
config.OnDeactivate = func() gfx.EventResult {
window.active.Store(false)
if onDeactivate != nil {
return onDeactivate()
}
return gfx.EventResult{}
}
// The runtime tracks the minimize state for every window, so Window.Minimized
// answers even when the application did not ask for OnMinimize. There is no
// minimize event during OpenWindow, so the zero value is the initial state.
onMinimize := config.OnMinimize
config.OnMinimize = func(minimized bool) {
window.minimized.Store(minimized)
if minimized {
window.active.Store(false)
}
if onMinimize != nil {
onMinimize(minimized)
}
Expand Down
Loading
Loading