Skip to content
Merged
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
6 changes: 5 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ jobs:
run: |
go vet -tags vivagtk ./app ./internal/platform/linux
go test -tags vivagtk ./internal/platform/linux -run '^TestGTK(WaylandAlwaysOnTopReportsUnsupported|ClipboardFileWriteReportsUnsupportedWithoutASetter)$' -count=1
# The Linux package is not part of the sharded run (it drives X11), so the
# titlebar contracts that do not need a server name their tests here.
- name: Titlebar and window contracts
run: go test ./internal/platform/linux -run '^TestMaximizeButtonSetsBothDirections$' -count=1 -v
- name: Native X11 global shortcut
env:
VIVA_NATIVE_GLOBAL_SHORTCUT_TEST: '1'
Expand Down Expand Up @@ -289,7 +293,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|EngineReportsTheFontsUnderline|AlwaysOnTop|SaveDialogCheckbox|FileIcon|NativeStructureABI)' -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|MonoWeights|InterfaceWeights|EveryListedFamilyResolves|EngineReportsTheFontsUnderline|AlwaysOnTop|SaveDialogCheckbox|FileIcon|NativeStructureABI)' -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
24 changes: 21 additions & 3 deletions .github/workflows/text-input.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,30 @@ jobs:
}
- name: Application input lifecycle
run: go test ./app -count=1
- name: GTK native probe dependencies
- name: Windows column clipboard protocol
if: runner.os == 'Windows'
env:
VIVA_WINDOWS_CLIPBOARD: '1'
run: |
git rev-parse HEAD
go version
go test ./internal/platform/windows -run '^TestColumnClipboardNative' -count=1 -v -timeout=90s
- name: Linux native probe dependencies
if: runner.os == 'Linux'
run: |
sudo apt-get update
sudo apt-get install -y --no-install-recommends libgtk-3-0t64 xvfb xauth dbus-x11
dpkg-query -W libgtk-3-0t64 xvfb xauth dbus-x11
sudo apt-get install -y --no-install-recommends libgtk-3-0t64 xvfb xauth dbus-x11 at-spi2-core
dpkg-query -W libgtk-3-0t64 xvfb xauth dbus-x11 at-spi2-core
- name: AT-SPI native lifecycle
if: runner.os == 'Linux'
run: |
binary="$RUNNER_TEMP/viva-atspi.test"
profile="$(mktemp -d "$RUNNER_TEMP/viva-atspi.XXXXXX")"
trap 'rm -rf "$profile" "$binary"' EXIT
go test -c -o "$binary" ./internal/platform/linux
mkdir -p "$profile"/{home,config,cache,data,runtime}
chmod 0700 "$profile/runtime"
xvfb-run -a env HOME="$profile/home" XDG_CONFIG_HOME="$profile/config" XDG_CACHE_HOME="$profile/cache" XDG_DATA_HOME="$profile/data" XDG_RUNTIME_DIR="$profile/runtime" VIVA_ATSPI_NATIVE_ROOT="$profile" VIVA_ATSPI_NATIVE=1 NO_AT_BRIDGE=1 dbus-run-session -- "$binary" -test.run='^TestAtspiNative(FirstWindowPolling|ResizePublishesFrames)$' -test.count=1 -test.v -test.timeout=45s
- name: GTK native composition lifecycle
if: runner.os == 'Linux'
run: dbus-run-session -- xvfb-run -a env VIVA_GTK_IME_NATIVE=1 GTK_IM_MODULE=gtk-im-context-simple GDK_BACKEND=x11 NO_AT_BRIDGE=1 G_DEBUG=fatal-criticals go test -tags vivagtk ./internal/platform/linux -run '^(TestGTKNativeComposition|TestGTKNativeTentative.*|TestGTKNativeSameTargetOwnership)$' -count=1 -v -timeout=90s
Expand Down
3 changes: 2 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ type Config struct {
// be coalesced to the latest queued position, as the platform does natively,
// so a handler follows the coordinates rather than the number of calls.
// Returning Repaint asks for one synchronous paint; Handled suppresses the
// click that press would complete.
// click that press would complete and default caret placement for the event,
// ending any pending default selection drag.
OnPointer func(event gfx.PointerEvent) gfx.EventResult
// OnKey receives normalized keyboard events for the focused hit target.
// Handled suppresses built-in traversal, activation, and Escape dismissal.
Expand Down
27 changes: 27 additions & 0 deletions app/clipboard_rectangular.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package app

import (
"fmt"
"strings"
)

// SetRectangularClipboardText writes text with column-selection metadata on
// Windows. Other native targets retain the plain-text clipboard fallback.
func SetRectangularClipboardText(value string) error {
if strings.IndexByte(value, 0) >= 0 {
return fmt.Errorf("app: clipboard text contains NUL")
}
if err, handled := driverSetRectangularClipboardText(value); handled {
return err
}
return nativeSetRectangularClipboardText(value)
}

// ClipboardTextWithFormat reads text and its rectangular-selection marker from
// one clipboard snapshot. A target without that format returns false.
func ClipboardTextWithFormat() (value string, rectangular bool, err error) {
if value, rectangular, err, handled := driverClipboardTextWithFormat(); handled {
return value, rectangular, err
}
return nativeClipboardTextWithFormat()
}
12 changes: 12 additions & 0 deletions app/clipboard_rectangular_other.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//go:build !windows

package app

func nativeSetRectangularClipboardText(value string) error {
return nativeSetClipboardText(value)
}

func nativeClipboardTextWithFormat() (string, bool, error) {
value, err := nativeClipboardText()
return value, false, err
}
231 changes: 231 additions & 0 deletions app/clipboard_rectangular_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,231 @@
//go:build darwin || windows || linux

package app

import (
"path/filepath"
"testing"

"github.com/vivaui/viva/gfx"
"github.com/vivaui/viva/text"
)

func assertClipboardTextFormat(t *testing.T, want string, rectangular bool) {
t.Helper()
value, column, err := ClipboardTextWithFormat()
if err != nil || value != want || column != rectangular {
t.Fatalf("clipboard snapshot = %q, rectangular=%v, err=%v; want %q, rectangular=%v", value, column, err, want, rectangular)
}
}

func TestDriverRectangularClipboardCopyCutAndPaste(t *testing.T) {
editor := text.NewEditor("primary")
const copied = "\u00e9\r\n\u6f22\r\n"
calls := 0
var events []TextEvent
config := Config{Title: "column clipboard", Width: 300, Height: 120}
config.Paint = func(canvas *gfx.Canvas, _ gfx.Size) {
canvas.HitWithOptions(gfx.Item(1), gfx.Rect{X: 10, Y: 10, Width: 220, Height: 30}, "editor", gfx.HitOptions{Role: gfx.RoleTextField, Multiline: true})
}
config.TextInput = func(TextInputContext) *TextInput {
return &TextInput{State: TextStateOf(editor), CopyOverride: true, CopyRectangular: true, CopyText: func() string {
calls++
return copied
}, OnEvent: func(event TextEvent) (TextState, error) {
events = append(events, event)
return TextStateOf(editor), nil
}}
}
driver, err := NewDriver(config, nil)
if err != nil {
t.Fatal(err)
}
defer driver.Close()
if err := driver.Click(20, 20); err != nil {
t.Fatal(err)
}
if err := driver.Resize(301, 120); err != nil {
t.Fatal(err)
}
if calls != 0 {
t.Fatalf("paint eagerly evaluated copy text %d times", calls)
}
for index, action := range []rune{'c', 'x', 'v'} {
if handled, err := driver.ShortcutChord(gfx.ModifierControl, action); !handled || err != nil {
t.Fatalf("shortcut %c: handled=%v err=%v", action, handled, err)
}
assertClipboardTextFormat(t, copied, true)
wantCalls := index + 1
if action == 'v' {
wantCalls = 2
}
if calls != wantCalls {
t.Fatalf("shortcut %c evaluated copy text %d times, want %d", action, calls, wantCalls)
}
}
if len(events) != 2 || events[0].Kind != TextPaste || events[0].Text != "" || events[0].Rectangular ||
events[1].Kind != TextPaste || events[1].Text != copied || !events[1].Rectangular {
t.Fatalf("copy/cut/paste events = %+v", events)
}
if editor.String() != "primary" {
t.Fatal("clipboard metadata changed the application-owned editor")
}
if err := SetClipboardText("stream"); err != nil {
t.Fatal(err)
}
assertClipboardTextFormat(t, "stream", false)
if handled, err := driver.ShortcutChord(gfx.ModifierControl, 'v'); !handled || err != nil {
t.Fatalf("plain paste: handled=%v err=%v", handled, err)
}
if event := events[len(events)-1]; event.Kind != TextPaste || event.Text != "stream" || event.Rectangular {
t.Fatalf("plain paste borrowed a stale column marker: %+v", event)
}
}

func TestDriverRectangularClipboardReplacementsClearMetadata(t *testing.T) {
for _, kind := range []string{"plain", "html", "image", "files"} {
t.Run(kind, func(t *testing.T) {
driver := newFilesDriver(t)
if err := SetRectangularClipboardText("column\n"); err != nil {
t.Fatal(err)
}
assertClipboardTextFormat(t, "column\n", true)
want := "plain"
switch kind {
case "plain":
driver.SetClipboard(want)
case "html":
want = "rich"
driver.SetClipboardHTML("<b>rich</b>", want)
case "image":
want = ""
if err := driver.SetClipboardImage(onePixelPNG(t)); err != nil {
t.Fatal(err)
}
case "files":
want = "file.txt"
driver.SetClipboardFiles([]string{filepath.Join(t.TempDir(), want)})
}
assertClipboardTextFormat(t, want, false)
})
}
}

func TestDriverRectangularClipboardRefusalsLeaveTextUntouched(t *testing.T) {
for _, secure := range []bool{false, true} {
name := "empty override"
if secure {
name = "secure"
}
t.Run(name, func(t *testing.T) {
calls, mutations := 0, 0
config := Config{Title: "refused column copy", Width: 300, Height: 120}
config.Paint = func(canvas *gfx.Canvas, _ gfx.Size) {
canvas.HitWithOptions(gfx.Item(1), gfx.Rect{X: 10, Y: 10, Width: 220, Height: 30}, "editor", gfx.HitOptions{Role: gfx.RoleTextField, Secure: secure})
}
config.TextInput = func(TextInputContext) *TextInput {
return &TextInput{State: TextState{Value: "private"}, CopyOverride: true, CopyRectangular: true, CopyText: func() string {
calls++
if secure {
return "secret"
}
return ""
}, OnEvent: func(TextEvent) (TextState, error) {
mutations++
return TextState{Value: "private"}, nil
}}
}
driver, err := NewDriver(config, nil)
if err != nil {
t.Fatal(err)
}
defer driver.Close()
if err := driver.Click(20, 20); err != nil {
t.Fatal(err)
}
driver.SetClipboard("sentinel")
for _, action := range []rune{'c', 'x'} {
if handled, err := driver.ShortcutChord(gfx.ModifierControl, action); !handled || err != nil {
t.Fatalf("refused shortcut %c: handled=%v err=%v", action, handled, err)
}
assertClipboardTextFormat(t, "sentinel", false)
}
wantCalls := 2
if secure {
wantCalls = 0
}
if mutations != 0 || calls != wantCalls {
t.Fatalf("refused copy/cut: mutations=%d calls=%d, want 0/%d", mutations, calls, wantCalls)
}
if err := SetRectangularClipboardText("invalid\x00column"); err == nil {
t.Fatal("NUL-bearing column text was accepted")
}
assertClipboardTextFormat(t, "sentinel", false)
})
}
}

func TestDriverRectangularClipboardCallbackHandoffDoesNotCutTheReplacement(t *testing.T) {
for _, mode := range []string{"same cached input", "replacement", "metadata changed"} {
for _, action := range []rune{'c', 'x'} {
t.Run(mode+"/"+string(action), func(t *testing.T) {
incoming := text.NewEditor("abc")
incoming.SetSelection(text.Range{Start: 1, End: 2})
oldEvents := 0
current := &TextInput{State: TextState{Value: "outgoing"}, CopyOverride: true, CopyRectangular: true,
OnEvent: func(TextEvent) (TextState, error) {
oldEvents++
return TextState{Value: "outgoing"}, nil
}}
var driver *Driver
current.CopyText = func() string {
if mode == "replacement" {
current = &TextInput{Editor: incoming}
} else if mode == "metadata changed" {
current.CopyRectangular = false
}
if err := driver.Resize(301, 120); err != nil {
t.Fatal(err)
}
return "rows\n"
}
config := Config{Title: "column callback handoff", Width: 300, Height: 120}
config.Paint = func(canvas *gfx.Canvas, _ gfx.Size) {
canvas.HitWithOptions(gfx.Item(1), gfx.Rect{X: 10, Y: 10, Width: 220, Height: 30}, "editor", gfx.HitOptions{Role: gfx.RoleTextField, Multiline: true})
}
config.TextInput = func(TextInputContext) *TextInput { return current }
var err error
driver, err = NewDriver(config, nil)
if err != nil {
t.Fatal(err)
}
defer driver.Close()
if err := driver.Click(20, 20); err != nil {
t.Fatal(err)
}
driver.SetClipboard("sentinel")
if handled, err := driver.ShortcutChord(gfx.ModifierControl, action); !handled || err != nil {
t.Fatalf("shortcut %c: handled=%v err=%v", action, handled, err)
}
if incoming.String() != "abc" || incoming.Selection() != (text.Range{Start: 1, End: 2}) {
t.Fatalf("old clipboard callback edited the replacement: text=%q selection=%+v", incoming.String(), incoming.Selection())
}
if mode != "same cached input" {
assertClipboardTextFormat(t, "sentinel", false)
if oldEvents != 0 {
t.Fatalf("retired callback received %d edits", oldEvents)
}
} else {
assertClipboardTextFormat(t, "rows\n", true)
wantEvents := 0
if action == 'x' {
wantEvents = 1
}
if oldEvents != wantEvents {
t.Fatalf("same cached owner received %d edits, want %d", oldEvents, wantEvents)
}
}
})
}
}
}
11 changes: 11 additions & 0 deletions app/clipboard_rectangular_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package app

import windowsplatform "github.com/vivaui/viva/internal/platform/windows"

func nativeSetRectangularClipboardText(value string) error {
return windowsplatform.SetClipboardRectangularText(value)
}

func nativeClipboardTextWithFormat() (string, bool, error) {
return windowsplatform.ClipboardTextWithFormat()
}
4 changes: 4 additions & 0 deletions app/composition_dispatch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ func TestNativeTextEventAdapterPreservesTaggedFields(t *testing.T) {
if got := appTextEvent(event); got != want {
t.Fatalf("native event adaptation = %+v, want %+v", got, want)
}
paste := platform.TextEvent{Kind: platform.TextPaste, Text: "column\r\n", Rectangular: true}
if got := appTextEvent(paste); got != (TextEvent{Kind: TextPaste, Text: "column\r\n", Rectangular: true}) {
t.Fatalf("native column paste adaptation = %+v", got)
}
}

func TestTextStateOfTentativeCompositionSnapshot(t *testing.T) {
Expand Down
Loading
Loading