Skip to content

Commit 8014d5c

Browse files
authored
Merge pull request #53 from Lithe-IDEA/codex/sync-viva-1fd4b51
Sync upstream Viva main through 59a696e
2 parents 909613b + 1fd17f2 commit 8014d5c

199 files changed

Lines changed: 10256 additions & 969 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/workflows/ci.yml‎

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,42 @@ jobs:
9090
- name: API discipline
9191
run: go run ./tools/apicheck ./ui ./components ./app ./gfx
9292

93+
# The attribute rules (ADR 0089 stage 3) exist only in the dev build: they
94+
# report a generic attribute that an element cannot use instead of letting it
95+
# be silently ignored. The release build must not carry the rules or their
96+
# messages, so this job tests the dev variant and proves the release one has
97+
# neither.
98+
dev-attributes:
99+
needs: changes
100+
if: needs.changes.outputs.code == 'true'
101+
runs-on: ubuntu-latest
102+
steps:
103+
- uses: actions/checkout@v4
104+
- uses: actions/setup-go@v5
105+
with:
106+
go-version-file: go.mod
107+
cache: true
108+
- name: vet the dev build
109+
run: go vet -tags dev ./...
110+
- name: test the dev build
111+
run: go test -tags dev ./base ./ui ./components -count=1
112+
- name: prove the release build has no attribute rules
113+
run: |
114+
if go list -f '{{.GoFiles}}' ./base | grep -q attrcheck_dev.go; then
115+
echo "the release build compiles the dev attribute rules" >&2
116+
exit 1
117+
fi
118+
go build -o /tmp/base-release.a ./base
119+
if grep -aq 'does not support' /tmp/base-release.a; then
120+
echo "the release build carries the dev attribute messages" >&2
121+
exit 1
122+
fi
123+
go build -tags dev -o /tmp/base-dev.a ./base
124+
if ! grep -aq 'does not support' /tmp/base-dev.a; then
125+
echo "the dev build does not carry the attribute rules" >&2
126+
exit 1
127+
fi
128+
93129
# Every target Viva ships for must at least type-check, tests included. The
94130
# targets do not depend on each other, so they run at the same time on one
95131
# runner: asking for four runners to do what one can finish in the same minute
@@ -125,14 +161,21 @@ jobs:
125161
# The Linux package is not part of the sharded run (it drives X11), so the
126162
# titlebar contracts that do not need a server name their tests here.
127163
- name: Titlebar and window contracts
128-
run: go test ./internal/platform/linux -run '^TestMaximizeButtonSetsBothDirections$' -count=1 -v
164+
run: go test ./internal/platform/linux -run '^Test(MaximizeButtonSetsBothDirections|PreviewMovePreservesSizeAndFocus)$' -count=1 -v
165+
- name: Native X11 drag preview
166+
env:
167+
VIVA_TEST_PREVIEW_XVFB: '1'
168+
run: |
169+
sudo apt-get install -y xvfb libxcb-shape0 ||
170+
{ sudo apt-get update && sudo apt-get install -y xvfb libxcb-shape0; }
171+
xvfb-run -a go test ./internal/platform/linux -run '^TestPreviewNativeX11Contract$' -count=1 -v
129172
- name: Native X11 global shortcut
130173
env:
131174
VIVA_NATIVE_GLOBAL_SHORTCUT_TEST: '1'
132175
run: |
133176
sudo apt-get install -y xvfb xdotool libx11-xcb1 ||
134177
{ sudo apt-get update && sudo apt-get install -y xvfb xdotool libx11-xcb1; }
135-
xvfb-run -a go test ./internal/platform/linux -run '^TestNativeX11GlobalShortcut$' -count=1 -v
178+
xvfb-run -a go test ./internal/platform/linux -run '^TestNativeX11(GlobalShortcut|WindowIconPropertyUpdates)$' -count=1 -v
136179
137180
# The browser target is a release target: it compiles every package, runs the
138181
# shared tests under GOOS=js, and builds the browser entry points and a guide.
@@ -304,6 +347,8 @@ jobs:
304347
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
305348
- name: Terminal keyboard routing
306349
run: go test ./internal/platform/windows -run '^TestATerminalGetsEditingKeysAndChordsAsRawKeys$' -count=1 -v
350+
- name: Native window and grouped taskbar icons
351+
run: go test ./internal/platform/windows -run '^TestWindowIconUpdatesOnTheWindowThread$' -count=1 -v
307352
- name: Native Windows global shortcut
308353
env:
309354
VIVA_NATIVE_GLOBAL_SHORTCUT_TEST: '1'
@@ -372,7 +417,7 @@ jobs:
372417
passed:
373418
name: ci passed
374419
if: always()
375-
needs: [changes, lint, cross-vet, web, web-browser, test, darwin, windows-materials, windows-arm64-text, benchmarks]
420+
needs: [changes, lint, dev-attributes, cross-vet, web, web-browser, test, darwin, windows-materials, windows-arm64-text, benchmarks]
376421
runs-on: ubuntu-latest
377422
steps:
378423
- name: every job this change needed passed

‎README.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,8 @@ WebView and no bundled rendering runtime.
161161
- Focus-driven dynamic native text editors on macOS, Windows, and Linux, with
162162
explicit enable/replace/disable frame updates. macOS and Windows caret timers
163163
exist only while an editable field is focused. Linux composes through the IBus
164-
protocol (IBus and Fcitx5's IBus frontend); XIM is still open.
164+
protocol (IBus and Fcitx5's IBus frontend) or Fcitx 4's own protocol; XIM is
165+
still open.
165166
- A separate retained semantic accessibility tree.
166167
- Direct CoreText shaping, system-font fallback, GPU-composited text textures,
167168
and a bounded measurement cache.

‎app/accessnodes.go‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ func accessRole(role semantic.Role) gfx.Role {
133133
return gfx.RoleStatus
134134
case semantic.RoleSeparator:
135135
return gfx.RoleSeparator
136+
case semantic.RoleProgress:
137+
return gfx.RoleProgressBar
136138
}
137139
return 0
138140
}

‎app/application_native.go‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ var _ fullscreenControl = resultWindow{}
8787
var _ alwaysOnTopControl = resultWindow{}
8888
var _ shortcutCapturer = resultWindow{}
8989
var _ titleControl = resultWindow{}
90+
var _ windowIconControl = resultWindow{}
9091
var _ platform.WindowMover = resultWindow{}
9192

9293
// What OpenWindow looks for in a host's window control.
@@ -125,6 +126,14 @@ func (window resultWindow) SetTitle(title string) error {
125126
return control.SetTitle(title)
126127
}
127128

129+
func (window resultWindow) SetIcon(icon WindowIcon) error {
130+
control, ok := window.WindowControl.(platform.WindowIconSetter)
131+
if !ok {
132+
return fmt.Errorf("%w: window icons", ErrUnsupported)
133+
}
134+
return control.SetIcon(icon.platform())
135+
}
136+
128137
func (window resultWindow) SetAlwaysOnTop(enabled bool) error {
129138
control, ok := window.WindowControl.(alwaysOnTopControl)
130139
if !ok {

‎app/driver.go‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1075,7 +1075,11 @@ type Label struct {
10751075
BitmapStride int
10761076
BitmapID uint64
10771077
BitmapVersion uint32
1078-
BitmapUpload bool
1078+
// ImageRadius and ImageFade are platform.TextLabel's: the corners of an
1079+
// image and how much of it is transparent.
1080+
ImageRadius float32
1081+
ImageFade float32
1082+
BitmapUpload bool
10791083
// Quad, while HasQuad, is where the label's picture lands: four corners in
10801084
// logical pixels with the colour multiplied into each, as gfx.Canvas.LabelQuad
10811085
// draws it. Bounds stays the box the picture was rasterised in.
@@ -1237,6 +1241,7 @@ func (driver *Driver) Snapshot() Snapshot {
12371241
Clip: label.Clip, Clipped: label.Clipped,
12381242
BitmapWidth: label.BitmapWidth, BitmapHeight: label.BitmapHeight, BitmapStride: label.BitmapStride,
12391243
BitmapID: label.BitmapID, BitmapVersion: label.BitmapVersion,
1244+
ImageRadius: label.ImageRadius, ImageFade: label.ImageFade,
12401245
BitmapUpload: label.BitmapUpload,
12411246
Quad: label.Quad, HasQuad: label.HasQuad,
12421247
}

‎app/painter.go‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1884,6 +1884,8 @@ func semanticRole(role gfx.Role) semantic.Role {
18841884
return semantic.RoleStatus
18851885
case gfx.RoleSeparator:
18861886
return semantic.RoleSeparator
1887+
case gfx.RoleProgressBar:
1888+
return semantic.RoleProgress
18871889
default:
18881890
return semantic.RoleButton
18891891
}

‎app/window_icon.go‎

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ package app
22

33
import (
44
"fmt"
5+
"path/filepath"
56
"runtime"
7+
"strings"
68

79
"github.com/vivaui/viva/internal/platform"
810
)
@@ -18,6 +20,40 @@ type WindowIcon struct {
1820
Size int
1921
// RGBA is Size*Size straight (not premultiplied) 8-bit pixels, top row first.
2022
RGBA []byte
23+
// ResourcePath optionally names a persistent, absolute .ico file on Windows.
24+
// With Config.Class set, it also supplies the taskbar group's and newly
25+
// pinned shortcut's icon. The caller owns this file and must keep it after
26+
// exit. Other platforms ignore it. Existing shortcuts are not edited.
27+
ResourcePath string
28+
}
29+
30+
type windowIconControl interface {
31+
SetIcon(WindowIcon) error
32+
}
33+
34+
// SetIcon replaces the running window's title-bar and task-switcher icon. On
35+
// macOS it replaces the application's Dock icon, including in an .app bundle;
36+
// on Windows, see ResourcePath for grouped/pinned taskbar icons; on Wayland the
37+
// compositor may keep the desktop entry's icon. Installed launchers and signed
38+
// application resources are not changed. Calls are safe
39+
// from any goroutine. The pixels are copied before returning. An empty or
40+
// invalid icon changes nothing; unsupported hosts return ErrUnsupported.
41+
func (window *Window) SetIcon(icon WindowIcon) error {
42+
if window == nil || window.closed.Load() {
43+
return fmt.Errorf("app: window is closed")
44+
}
45+
if err := icon.validate(); err != nil {
46+
return err
47+
}
48+
if icon.Size == 0 {
49+
return fmt.Errorf("app: window icon must not be empty")
50+
}
51+
control, ok := window.control.(windowIconControl)
52+
if !ok {
53+
return fmt.Errorf("%w: window icons", ErrUnsupported)
54+
}
55+
icon.RGBA = append([]byte(nil), icon.RGBA...)
56+
return control.SetIcon(icon)
2157
}
2258

2359
// StatusIcon is the picture as a status-area icon of size pixels, in the form
@@ -36,6 +72,10 @@ func (icon WindowIcon) StatusIcon(size int) StatusIcon {
3672
}
3773

3874
func (icon WindowIcon) validate() error {
75+
if runtime.GOOS == "windows" && icon.ResourcePath != "" &&
76+
(!filepath.IsAbs(icon.ResourcePath) || strings.ContainsRune(icon.ResourcePath, 0)) {
77+
return fmt.Errorf("app: icon resource must be an absolute path without NUL")
78+
}
3979
if icon.Size == 0 && len(icon.RGBA) == 0 {
4080
return nil
4181
}
@@ -46,5 +86,5 @@ func (icon WindowIcon) validate() error {
4686
}
4787

4888
func (icon WindowIcon) platform() platform.WindowIcon {
49-
return platform.WindowIcon{Size: icon.Size, RGBA: icon.RGBA}
89+
return platform.WindowIcon{Size: icon.Size, RGBA: icon.RGBA, ResourcePath: icon.ResourcePath}
5090
}

‎app/window_icon_update_test.go‎

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
//go:build darwin || windows || linux
2+
3+
package app
4+
5+
import (
6+
"errors"
7+
"path/filepath"
8+
"testing"
9+
10+
"github.com/vivaui/viva/internal/platform"
11+
)
12+
13+
type iconTestControl struct {
14+
fakeWindow
15+
icon WindowIcon
16+
}
17+
18+
func (control *iconTestControl) SetIcon(icon WindowIcon) error {
19+
control.icon = icon
20+
return nil
21+
}
22+
23+
func TestWindowIconUpdateValidatesAndCopiesPixels(t *testing.T) {
24+
control := &iconTestControl{}
25+
window := &Window{control: control}
26+
icon := WindowIcon{Size: 1, RGBA: []byte{30, 100, 220, 255}}
27+
if err := window.SetIcon(icon); err != nil {
28+
t.Fatal(err)
29+
}
30+
icon.RGBA[0] = 200
31+
if control.icon.RGBA[0] != 30 {
32+
t.Fatal("the host retained caller-owned pixels")
33+
}
34+
for _, invalid := range []WindowIcon{{}, {Size: 1}, {Size: 1025}} {
35+
if err := window.SetIcon(invalid); err == nil || control.icon.RGBA[0] != 30 {
36+
t.Fatal("an invalid update changed the icon")
37+
}
38+
}
39+
window.closed.Store(true)
40+
if err := window.SetIcon(icon); err == nil {
41+
t.Fatal("a closed window accepted an icon")
42+
}
43+
var missing *Window
44+
if err := missing.SetIcon(icon); err == nil {
45+
t.Fatal("a nil window accepted an icon")
46+
}
47+
if err := (&Window{control: &fakeWindow{}}).SetIcon(icon); !errors.Is(err, ErrUnsupported) {
48+
t.Fatalf("unsupported window: %v", err)
49+
}
50+
}
51+
52+
type nativeIconTestControl struct {
53+
fakeWindow
54+
icon platform.WindowIcon
55+
}
56+
57+
func (control *nativeIconTestControl) SetIcon(icon platform.WindowIcon) error {
58+
control.icon = icon
59+
return nil
60+
}
61+
62+
func TestResultWindowForwardsIconUpdates(t *testing.T) {
63+
native := &nativeIconTestControl{}
64+
window := &Window{control: resultWindow{WindowControl: native}}
65+
resource := filepath.Join(t.TempDir(), "logo.ico")
66+
if err := window.SetIcon(WindowIcon{Size: 1, RGBA: []byte{1, 2, 3, 255}, ResourcePath: resource}); err != nil {
67+
t.Fatal(err)
68+
}
69+
if native.icon.Size != 1 || native.icon.RGBA[2] != 3 || native.icon.ResourcePath != resource {
70+
t.Fatalf("native icon = %+v", native.icon)
71+
}
72+
window = &Window{control: resultWindow{WindowControl: &fakeWindow{}}}
73+
if err := window.SetIcon(WindowIcon{Size: 1, RGBA: make([]byte, 4)}); !errors.Is(err, ErrUnsupported) {
74+
t.Fatalf("wrapped unsupported window: %v", err)
75+
}
76+
}

‎base/accessors.go‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,12 @@ func (x *Extra) GetBorder() Color { return x.border }
240240
// GetBorderDashed reads the borderDashed of Extra for the styled painting layer.
241241
func (x *Extra) GetBorderDashed() bool { return x.borderDashed }
242242

243+
// GetSelectColors reads the colors the recipe gave the Select trigger being
244+
// painted, for the styled painting layer.
245+
func (f *Frame) GetSelectColors() (foreground, chevron Color) {
246+
return f.selectForeground, f.selectChevron
247+
}
248+
243249
// GetButtonRecipe reads the buttonRecipe of Extra for the styled painting layer.
244250
func (x *Extra) GetButtonRecipe() func(gfx.Theme, style.Variant, gfx.State) style.ButtonLook {
245251
return x.buttonRecipe
@@ -383,6 +389,14 @@ func (x *Frame) GetAddons() []FieldAddons { return x.addons }
383389
// GetBounds reads the bounds of Frame for the styled painting layer.
384390
func (x *Frame) GetBounds() Rect { return x.bounds }
385391

392+
// GetCheckboxLook reads the look the recipe gave the checkbox box being
393+
// painted, for the styled painting layer's mark.
394+
func (f *Frame) GetCheckboxLook() style.CheckboxLook { return f.checkboxPainted }
395+
396+
// GetSwitchLook reads the look the recipe gave the switch being painted, for the
397+
// styled painting layer's thumb.
398+
func (f *Frame) GetSwitchLook() style.SwitchLook { return f.switchPainted }
399+
386400
// GetCaptionFn reads the captionFn of Frame for the styled painting layer.
387401
func (x *Frame) GetCaptionFn() func(f *Frame, n *Node, control Rect) { return x.captionFn }
388402

@@ -1172,6 +1186,16 @@ func (x *TableDecl) GetRows() int { return x.rows }
11721186
// GetSpec reads the spec of TableDecl for the styled painting layer.
11731187
func (x *TableDecl) GetSpec() TableSpec { return x.spec }
11741188

1189+
// GetFontSize reads the element's font size for the table being painted: the
1190+
// explicit size when it has one, else the spec's.
1191+
func (x *TableDecl) GetFontSize() float32 { return x.fontSize }
1192+
1193+
// GetForeground reads the element's text color for the table being painted.
1194+
func (x *TableDecl) GetForeground() gfx.Color { return x.foreground }
1195+
1196+
// GetForegroundSet reports whether the element set a text color of its own.
1197+
func (x *TableDecl) GetForegroundSet() bool { return x.hasForeground }
1198+
11751199
// GetState reads the state of TableDecl for the styled painting layer.
11761200
func (x *TableDecl) GetState() *TableState { return x.state }
11771201

0 commit comments

Comments
 (0)