Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
0a34cde
perf(linux): record a Vulkan image's commands only when they are stale
t8y2 Nov 22, 2026
a813f1e
fix(linux): give every window and renderer its own copy of the shared…
t8y2 Nov 22, 2026
aaa3a7a
perf(linux): stage label uploads through kept buffers, without idling…
t8y2 Nov 22, 2026
4d7ef07
perf(linux): sub-allocate label image memory from blocks
t8y2 Nov 22, 2026
1b627a4
perf(linux): read selections over one kept connection
t8y2 Nov 22, 2026
b108bb1
refactor(text): reach the editor's runes through a store
t8y2 Nov 22, 2026
59c733f
perf(text): keep the editor's text as UTF-8 leaves
t8y2 Nov 22, 2026
932c9aa
perf(components): lay out only the lines an edit touched in CodeEditor
t8y2 Nov 22, 2026
b2bc112
fix(text): build a new editor's text with one copy and keep it inlinable
t8y2 Nov 22, 2026
488544f
fix(app): show a focus change the paint itself made in the same frame
t8y2 Nov 22, 2026
0747528
perf(interaction): keep the input regions once, in the router
t8y2 Nov 22, 2026
6c33891
perf(linux): let every window draw with one Vulkan device
t8y2 Nov 22, 2026
a96c673
feat(base): respond to the window's and a container's width with From
t8y2 Nov 22, 2026
05804ab
feat(base): hide an element with Hide, show it again with Show
t8y2 Nov 22, 2026
75a5070
fix(app): read the titlebar insets from the window, not the platform
t8y2 Nov 22, 2026
e52205d
fix(cmd/viva): regenerate the component recipes
t8y2 Nov 22, 2026
6915b4a
fix(input): keep the focus on its region when the regions are set again
t8y2 Nov 22, 2026
a274103
feat(app): read fingers as touch screens do: taps, pans, flings, long…
t8y2 Nov 22, 2026
961088c
fix(dmg): convert the image only once the disk image service let go o…
t8y2 Nov 22, 2026
5021f7b
build: keep macOS-only code out of iOS builds
t8y2 Nov 22, 2026
838a96b
refactor(darwin): split the text and rendering core out of native.m
t8y2 Nov 22, 2026
3f592fa
refactor(darwin): draw a window's scene through a surface-independent…
t8y2 Nov 22, 2026
386b6a6
feat(ios): run an application in a UIKit window drawn by the Metal re…
t8y2 Nov 22, 2026
9b8a4ae
docs(guides): sync the windows guide with its example
t8y2 Nov 22, 2026
d87693b
feat(cmd/viva): build for the iOS simulator and run there with viva run
t8y2 Nov 22, 2026
2d099b2
build(android): add the environment script for the Android toolchain
t8y2 Nov 22, 2026
6d2fd9b
refactor(platform): move the Vulkan renderer out of the Linux backend
t8y2 Nov 22, 2026
4472fc8
refactor(text): share the line engine between the browser and other p…
t8y2 Nov 22, 2026
7bae397
feat(android): run an application in an Android process, drawn with V…
t8y2 Nov 22, 2026
9fafb62
fix(ci): follow the Vulkan shaders and layers tests, and detach the w…
t8y2 Nov 22, 2026
b214e5a
feat(ios): keep the surface inside the safe area and the keyboard, fo…
t8y2 Nov 22, 2026
9d8c9cc
feat(android): the input method, keyboards, mouse and the surface's size
t8y2 Nov 22, 2026
cfab9e2
feat(android,ios): the system's clipboard, links, theme and screen re…
t8y2 Nov 22, 2026
5db1b3c
fix(ios): hand the keys the text system takes back to it
t8y2 Nov 22, 2026
9ca247d
feat(ios): show the program's accessibility tree to VoiceOver
t8y2 Nov 22, 2026
9b57ae2
feat(examples): add a touch example for checking fingers on phones
t8y2 Nov 22, 2026
62cc40c
fix(showcase): drop the breadcrumb when the toolbar is too narrow for it
t8y2 Nov 22, 2026
90459cb
feat(ios): provide the pasteboard, links, languages, motion and appea…
t8y2 Nov 22, 2026
847e49e
fix(dmg): detach the disk even when its volume is already unmounted
t8y2 Nov 22, 2026
353980c
feat(scroll): let a finger carry content past its end and spring it back
t8y2 Nov 22, 2026
de5389a
feat(touch): let a fingertip reach controls smaller than 44 px
t8y2 Nov 22, 2026
f85bd1b
fix(dmg): keep detaching until the disk is no longer attached
t8y2 Nov 22, 2026
2fd1447
feat(windows): read a finger as a touch pointer, not as a mouse
t8y2 Nov 22, 2026
44f0e98
feat(linux): read a finger as X Input touch events on X11
t8y2 Nov 22, 2026
dbb487f
fix(dmg): run hdiutil create again when the service loses the staged …
t8y2 Nov 22, 2026
2d473fb
fix(dmg): detach the disk again while its image stays attached
t8y2 Nov 22, 2026
148d6dc
fix(markdown): decode inline character references
Mucheen Nov 22, 2026
5446861
docs(guides): name c.TitlebarInsets in the Windows guide
caichangqing1120 Nov 22, 2026
cb5b31f
feat(tooltip): open a control's tooltip when a finger holds it
t8y2 Nov 22, 2026
1ded51e
feat(mobile): draw under the system bars and report lifecycle events
t8y2 Nov 22, 2026
c6f78b4
chore(viva): regenerate the tooltip template
t8y2 Nov 22, 2026
e038753
fix(touch): ask for the pointer event pass only after a finger has to…
t8y2 Nov 23, 2026
f087410
fix(app): keep the window when the platform has no pointer to shape
t8y2 Nov 23, 2026
4b1c981
fix(dmg): keep image builds from exposing an installable app
caichangqing1120 Nov 23, 2026
992a278
docs(base): explain click delivery for self-painted pages
MYCF711 Nov 23, 2026
936f6a6
docs(readme): name Fcitx 4 in the Chinese overview
t8y2 Nov 23, 2026
0f959e5
windows: preserve IME composition while a menu captures keys
lijhnihaoa Nov 23, 2026
37fd9d7
fix(android): draw a new surface before it is shown and drop the spla…
t8y2 Nov 23, 2026
1f0bf02
feat(touch): place the caret with a tap and select a word with a held…
t8y2 Nov 23, 2026
302faef
fix(components): keep graphemes whole in CodeEditor placement
caichangqing1120 Nov 23, 2026
eccbe2e
feat(gfx): keep the visual caret edge of a text hit
caichangqing1120 Nov 23, 2026
e320ba5
feat(components): keep fitted bidi caret placement in CodeEditor
caichangqing1120 Nov 23, 2026
ee7ba13
feat(components): keep shaped bidi placement across wraps and tabs
caichangqing1120 Nov 23, 2026
68be843
feat(components): preserve shaped bidi geometry under syntax styles
caichangqing1120 Nov 23, 2026
f7d601e
Merge remote-tracking branch 'origin/main' into sync/upstream-68be843c
xiaoyumuxi Nov 23, 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: 17 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,16 @@ jobs:
wait "$pid" || status=1
done
exit "$status"
# The Android build is the real thing: the program as a shared library with
# the NDK's compiler, the host's Java, and an APK around them with the SDK's
# tools, all of which the runner's image has. It is not run here; the
# runner has no device.
- name: Android build
run: |
export ANDROID_HOME="${ANDROID_HOME:-/usr/local/lib/android/sdk}"
export ANDROID_NDK_HOME="${ANDROID_NDK_HOME:-$(ls -d "$ANDROID_HOME"/ndk/* | sort -V | tail -1)}"
go run ./cmd/viva build --target android ./examples/guides/hello
go run ./cmd/viva build --target android --arch amd64 ./examples/guides/hello
- name: Native Linux text rasterization
run: |
sudo apt-get install -y libpangocairo-1.0-0 fonts-noto-color-emoji ||
Expand Down Expand Up @@ -340,6 +350,12 @@ jobs:
VIVA_NATIVE_GLOBAL_SHORTCUT_TEST: '1'
run: go test ./internal/platform/darwin -run '^TestNativeCarbonGlobalShortcut$' -count=1 -v

# The iOS build compiles the Metal and UIKit bridge against the simulator
# SDK; it is not run here, since the runner cannot show a simulator.
- name: iOS simulator build
run: go run ./cmd/viva build --target ios-sim ./examples/guides/hello



windows-materials:
needs: changes
Expand All @@ -357,7 +373,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|OpeningMaximized|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
run: go test ./internal/platform/windows ./ui ./components ./headless ./app -run 'Test(Backdrop|WindowBackdrop|OpeningMaximized|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|QueuedMenuKeysLeaveTerminalCompositionWithItsOwner|MenuKeysPreserveSystemChordsAndShift|TerminalMenuStopsCapturingWhenWindowLosesFocus|DisabledIMEOffersMenuShortcutDuringComposition)' -count=1 -v
- name: Web view partitions
run: go test ./internal/platform/windows -run '^Test(APageWithoutAPartitionAsksForNoProfileOfItsOwn|APartitionNamesTheWebView2Profile|AnEphemeralPartitionIsAnOffTheRecordProfile|EphemeralPagesWithoutAPartitionEachGetAProfileOfTheirOwn)$' -count=1 -v
- name: Terminal keyboard routing
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/text-input.yml
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,9 @@ jobs:
run: go test -tags vivagtk ./internal/platform/linux -run '^TestGTKDestroyDetachesInputMethodBeforeNativeWidget$' -count=1 -v
- name: Linux clipboard, compositing and icon contracts
if: runner.os == 'Linux'
run: go test -tags vivagtk ./internal/platform/linux -run '^Test(AClipboardHTML|SetClipboardHTML|GTKClipboardHTML|CompositingLayers|NetWMIcon)' -count=1 -v
run: |
go test -tags vivagtk ./internal/platform/linux -run '^Test(AClipboardHTML|SetClipboardHTML|GTKClipboardHTML|NetWMIcon)' -count=1 -v
go test ./internal/platform/vulkan -run '^TestCompositingLayers' -count=1 -v
# A terminal input is a preedit surface with a cursor of its own: the native
# editor must draw no caret or selection over it, and blink none.
- name: Windows terminal preedit draws no native caret
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/vector-coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ jobs:
# bash on every runner: the Windows default shell is PowerShell.
shell: bash
run: |
if git diff --quiet -- internal/platform/darwin/shaders internal/platform/linux/shaders internal/platform/windows/shaders; then
if git diff --quiet -- internal/platform/darwin/shaders internal/platform/vulkan/shaders internal/platform/windows/shaders; then
echo "the shipped shaders are what the sources compile to"
echo changed=false >> "$GITHUB_OUTPUT"
else
git diff --stat -- internal/platform/darwin/shaders internal/platform/linux/shaders internal/platform/windows/shaders
git diff --stat -- internal/platform/darwin/shaders internal/platform/vulkan/shaders internal/platform/windows/shaders
echo changed=true >> "$GITHUB_OUTPUT"
fi
- name: Native pixel coverage with the rebuilt shaders
Expand All @@ -82,6 +82,6 @@ jobs:
name: vector-shaders-${{ runner.os }}
path: |
internal/platform/darwin/shaders/scene.metallib
internal/platform/linux/shaders/*.spv
internal/platform/vulkan/shaders/*.spv
internal/platform/windows/shaders/*.dxbc
internal/platform/windows/shaders/manifest.json
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@

# A signing key written by viva update-keygen in the project root.
/update.key
tools/android/local.sh
2 changes: 1 addition & 1 deletion README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ Viva 面向 macOS、Windows 和 Linux 上的原生桌面应用,同时把 WebAs
- 保留式 Row/Column/Stack/Flex 布局,布局不变时 O(1) 检查。
- 按绘制顺序的指针路由、稳定的键盘焦点和 Tab 遍历。
- macOS 原生 `NSTextInputClient` 集成,支持真实的中文输入法候选组合、按字素编辑和 UTF-16 映射。
- macOS、Windows 和 Linux 上由焦点驱动的动态原生文本编辑器,带显式的启用/替换/禁用帧更新。macOS 和 Windows 的光标定时器只在可编辑字段获得焦点时存在。Linux 通过 IBus 协议组字(IBus 以及 Fcitx5 的 IBus 前端);XIM 仍未支持。
- macOS、Windows 和 Linux 上由焦点驱动的动态原生文本编辑器,带显式的启用/替换/禁用帧更新。macOS 和 Windows 的光标定时器只在可编辑字段获得焦点时存在。Linux 通过 IBus 协议(IBus 以及 Fcitx5 的 IBus 前端)或 Fcitx 4 自己的协议组字;XIM 仍未支持。
- 一棵独立的保留式语义无障碍树。
- 直接 CoreText 整形、系统字体回退、GPU 合成的文本纹理,以及有上限的测量缓存。
- 实验性的 Windows shell:Win32 事件、D3D11 保留式渲染、内嵌 DXBC 着色器、DirectWrite 测量,以及有上限的 GDI 标签纹理;原生构建不加载着色器编译器。
Expand Down
34 changes: 33 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,22 @@ type Config struct {
// so Control+Enter still reaches the field as before. Other named keys
// remain OnKey events. On Windows an ordinary (non-terminal, non-Placed)
// text field that has focus takes the standard editing and clipboard chords
// first, so the application does not see them there.
// first, so the application does not see them there. While CaptureMenuKeys
// reports true, a captured key is not passed on to text or the input method
// when this callback returns unhandled, and unmodified keys are offered
// during a composition too.
// This callback runs on the window thread.
OnShortcut func(event gfx.KeyEvent) gfx.EventResult
// CaptureMenuKeys reports whether a transient menu owns the keyboard.
// Windows routes its keys to OnShortcut (printable) or OnKey (named)
// before IME processing, keeping the underlying text input and its
// composition installed until the menu closes. A captured key never
// reaches text or the input method: an unhandled key is dropped, a held
// key repeats with Repeat set, and a named key the runtime cannot express
// is swallowed. The callback runs on the window thread and must not change
// state. It does nothing outside Windows, and if the system refuses the
// keyboard hook the keys are delivered as usual. Also supported by Driver.
CaptureMenuKeys func() bool
// OnModifierTap receives a modifier key that was pressed and released on its
// own (see gfx.ModifierTapEvent), which OnKey never sees outside a terminal
// that asked for the whole keyboard. It is how an application builds
Expand Down Expand Up @@ -213,6 +226,12 @@ type Config struct {
// application stop work nobody can see, such as a remote desktop stream.
// Hide is the application's own request and is not reported here.
OnMinimize func(minimized bool)
// OnLifecycle runs on the window thread when the system moves a phone application
// between the foreground and the background, or asks it for memory. A desktop window
// never gets one. A phone may end a backgrounded application without further notice, so
// Background is when to save what the user would miss; a MemoryWarning is when to drop
// caches that can be rebuilt.
OnLifecycle func(LifecycleEvent)
// OnActivate runs on the window thread when the top-level window becomes
// the active window, including when the user switches back from another
// application. Moving focus between editors inside the window does not
Expand Down Expand Up @@ -341,3 +360,16 @@ func (config Config) originPoint() gfx.Point {
}
return *config.Origin
}

// LifecycleEvent is a change the system makes to the state of a phone application (see
// Config.OnLifecycle).
type LifecycleEvent uint8

const (
// LifecycleBackground says the application went behind another.
LifecycleBackground LifecycleEvent = iota + 1
// LifecycleForeground says it came back to the front.
LifecycleForeground
// LifecycleMemoryWarning says the system wants memory back.
LifecycleMemoryWarning
)
2 changes: 1 addition & 1 deletion app/application_reopen_darwin.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build darwin
//go:build darwin && !ios

package app

Expand Down
13 changes: 13 additions & 0 deletions app/backend_android.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//go:build android

package app

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

func runNative(config platform.Config) error { return android.Run(config) }
func runNativeApplication(start platform.ApplicationStart) error {
return android.RunApplication(start)
}
2 changes: 2 additions & 0 deletions app/backend_darwin.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build !ios

package app

import (
Expand Down
13 changes: 13 additions & 0 deletions app/backend_ios.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//go:build ios

package app

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

func runNative(config platform.Config) error { return darwin.Run(config) }
func runNativeApplication(start platform.ApplicationStart) error {
return darwin.RunApplication(start)
}
2 changes: 1 addition & 1 deletion app/backend_linux.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build linux && !vivagtk
//go:build linux && !vivagtk && !android

package app

Expand Down
2 changes: 1 addition & 1 deletion app/clipboard_html_darwin.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build darwin
//go:build darwin && !ios

package app

Expand Down
2 changes: 1 addition & 1 deletion app/clipboard_html_linux.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build linux
//go:build linux && !android

package app

Expand Down
2 changes: 1 addition & 1 deletion app/desktop_settings_linux.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build linux
//go:build linux && !android

package app

Expand Down
2 changes: 1 addition & 1 deletion app/desktop_settings_other.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build !linux
//go:build !linux || android

package app

Expand Down
88 changes: 88 additions & 0 deletions app/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ type Driver struct {
// modifierKeys is the modifier keys KeyDown holds, one bit per
// gfx.KeyShiftLeft..ui.KeyMetaRight.
modifierKeys uint8
// A menu press may close the menu. Its repeats and release still belong to it.
menuKeys map[uint32]bool

clipboard string
notifications []Notification
Expand Down Expand Up @@ -291,6 +293,25 @@ func (driver *Driver) Resize(width, height int) error {
return err
}

// Lifecycle tells the application the system did something to it, as a phone does when it
// moves the application to the background or asks it for memory.
func (driver *Driver) Lifecycle(event LifecycleEvent) {
if driver.config.OnLifecycle != nil {
driver.config.OnLifecycle(event)
}
}

// SetSafeArea says the system covers the window's edges by insets, as a phone's status bar,
// sensor housing and home indicator do, and lets the page lay out again inside what is left.
func (driver *Driver) SetSafeArea(insets gfx.Insets) error {
if err := driver.Pump(); err != nil {
return err
}
size := driver.painter.size
_, err := driver.painter.resize(platform.Size{Width: size.Width, Height: size.Height, Scale: driver.painter.scale, SafeArea: insets})
return err
}

func (driver *Driver) pointer(kind platform.PointerEventKind, x, y float32, button gfx.PointerButton, clicks int) error {
if err := driver.Pump(); err != nil {
return err
Expand Down Expand Up @@ -420,6 +441,37 @@ func (driver *Driver) Cancel() error {
return driver.pointer(platform.PointerCancel, 0, 0, gfx.PointerButtonNone, 0)
}

// TouchDown puts finger id on the screen at a point, TouchMove moves it and
// TouchUp lifts it: the touches a phone or a touch screen reports. The runtime
// reads them as it reads a finger in a window: a press waits for its tap
// timeout, a finger that moves pans and flings, and one held still is a
// secondary press. Advance moves the time a finger is held.
func (driver *Driver) TouchDown(id int32, x, y float32) error {
return driver.touch(platform.PointerDown, id, x, y)
}

// TouchMove moves finger id to a point.
func (driver *Driver) TouchMove(id int32, x, y float32) error {
return driver.touch(platform.PointerMove, id, x, y)
}

// TouchUp lifts finger id at a point.
func (driver *Driver) TouchUp(id int32, x, y float32) error {
return driver.touch(platform.PointerUp, id, x, y)
}

func (driver *Driver) touch(kind platform.PointerEventKind, id int32, x, y float32) error {
if err := driver.Pump(); err != nil {
return err
}
origin := driver.origin
_, err := driver.painter.pointerEvent(platform.PointerEvent{
Kind: kind, Button: gfx.PointerButtonPrimary, Modifiers: driver.heldModifiers(), X: x, Y: y,
ScreenX: origin.X + x, ScreenY: origin.Y + y, Device: gfx.PointerTouch, PointerID: id,
})
return err
}

// Press presses a pointer button at a point (moving there first) as a lone
// click.
func (driver *Driver) Press(x, y float32, button gfx.PointerButton) error {
Expand Down Expand Up @@ -552,6 +604,16 @@ func driverTyped(key gfx.Key, character string, modifiers gfx.Modifiers) string
return character
}

func (driver *Driver) menuKey(key gfx.Key, character string, modifiers gfx.Modifiers) error {
event := platform.KeyEvent{Key: key, Modifiers: modifiers, Text: strings.ToLower(character)}
if key == gfx.KeyUnknown {
_, _, err := driver.painter.shortcut(event)
return err
}
_, err := driver.painter.key(event)
return err
}

// KeyDown presses a key and keeps it down until KeyUp, as a person holding it
// would. Modifier keys (gfx.KeyShiftLeft and the like) stay held for every pointer,
// scroll and key the driver delivers meanwhile, so Shift-click and Ctrl-click
Expand All @@ -567,6 +629,17 @@ func (driver *Driver) KeyDown(key gfx.Key, character string) error {
driver.modifierKeys |= 1 << (key - gfx.KeyShiftLeft)
}
modifiers := driver.heldModifiers()
code := driverKeyCode(key, character)
if driver.menuKeys[code] {
return nil
}
if driver.painter.menuCapturesKeys() && !key.IsModifier() {
if driver.menuKeys == nil {
driver.menuKeys = make(map[uint32]bool)
}
driver.menuKeys[code] = true
return driver.menuKey(key, character, modifiers)
}
if !driver.HoldsKeys() {
switch {
case key.IsModifier():
Expand Down Expand Up @@ -618,6 +691,11 @@ func (driver *Driver) KeyUp(key gfx.Key, character string) error {
if key.IsModifier() {
driver.modifierKeys &^= 1 << (key - gfx.KeyShiftLeft)
}
code := driverKeyCode(key, character)
if driver.menuKeys[code] {
delete(driver.menuKeys, code)
return nil
}
if !driver.HoldsKeys() && !(key.IsModifier() && driver.painter.onModifierTap != nil) {
return nil
}
Expand Down Expand Up @@ -649,6 +727,7 @@ func (driver *Driver) LoseFocus() error {
return err
}
driver.modifierKeys = 0
clear(driver.menuKeys)
_, err := driver.painter.focusLost()
return err
}
Expand All @@ -667,6 +746,9 @@ func (driver *Driver) Key(key gfx.Key, modifiers gfx.Modifiers) error {
return err
}
modifiers |= driver.heldModifiers()
if driver.painter.menuCapturesKeys() {
return driver.menuKey(key, "", modifiers)
}
if key == gfx.KeySpace && driver.config.OnShortcut != nil && !driver.painter.nativeText.State.Composing {
_, handled, err := driver.painter.shortcut(platform.KeyEvent{Modifiers: modifiers, Text: " "})
if err != nil || handled {
Expand Down Expand Up @@ -762,6 +844,9 @@ func (driver *Driver) Chord(modifiers gfx.Modifiers, character string) error {
if err := driver.Pump(); err != nil {
return err
}
if driver.painter.menuCapturesKeys() {
return driver.menuKey(gfx.KeyUnknown, character, modifiers)
}
if driver.config.OnShortcut != nil && !driver.painter.nativeText.State.Composing {
_, handled, err := driver.painter.shortcut(platform.KeyEvent{Modifiers: modifiers, Text: strings.ToLower(character)})
if err != nil || handled {
Expand Down Expand Up @@ -895,6 +980,9 @@ func (driver *Driver) ShortcutChord(modifiers gfx.Modifiers, character rune) (bo
return false, err
}
shortcut := shortcutText(character)
if driver.painter.menuCapturesKeys() {
return true, driver.menuKey(gfx.KeyUnknown, shortcut, modifiers)
}
if driver.editing() && !driver.terminal() {
event := platform.KeyEvent{Modifiers: input.Modifiers(modifiers), Text: shortcut}
if command, ok := platform.TextEditingCommand(event); ok {
Expand Down
22 changes: 22 additions & 0 deletions app/driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1196,6 +1196,28 @@ func TestDriverShowsAHitsCursorImageAndRestoresTheArrow(t *testing.T) {
}
}

// A target with no pointer to shape, a phone, goes on when a control asks for a pointer
// shape: holding a text field used to end the window there.
func TestAnUnsupportedCursorDoesNotEndTheWindow(t *testing.T) {
config := Config{Title: "no pointer", Width: 100, Height: 100}
config.Paint = func(canvas *gfx.Canvas, _ gfx.Size) {
canvas.HitWithOptions(gfx.Item(1), gfx.Rect{Width: 100, Height: 100}, "field", gfx.HitOptions{Cursor: gfx.PointerCursorText})
}
driver, err := NewDriver(config, nil)
if err != nil {
t.Fatal(err)
}
defer driver.Close()
asked := 0
driver.painter.setCursor = func(Cursor) error { asked++; return fmt.Errorf("no pointer: %w", ErrUnsupported) }
if err := driver.Move(10, 10); err != nil {
t.Fatalf("an unsupported pointer shape failed the move: %v", err)
}
if err := driver.Move(11, 10); err != nil || asked != 1 {
t.Fatalf("the shape was asked for %d times (%v), want once", asked, err)
}
}

// A target that cannot draw application pointers keeps the arrow instead of failing the pointer.
func TestAnUnsupportedCursorImageFallsBackToTheArrow(t *testing.T) {
image, err := gfx.NewCursorImage(1, 1, 0, 0, 1, make([]byte, 4))
Expand Down
Loading
Loading