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
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,8 @@ jobs:
# on Windows.
- name: directory picker initial location
run: go test ./internal/platform/windows ./app -run '^Test(FileDialogInitialDirectory|DriverInterceptsOpenDirectory)$' -count=1 -v
- name: Native directory watches
run: go test ./internal/filewatch -count=1 -timeout=1m
- 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|QueuedMenuKeysLeaveTerminalCompositionWithItsOwner|MenuKeysPreserveSystemChordsAndShift|TerminalMenuStopsCapturingWhenWindowLosesFocus|DisabledIMEOffersMenuShortcutDuringComposition)' -count=1 -v
- name: Offscreen incremental frame pixels
Expand Down
8 changes: 8 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ type Config struct {
// at window creation, even if it initially returns BackdropNone, allowing
// later material changes without rebuilding the application.
WindowBackdrop func() BackdropStyle
// Watermark is an input-transparent native overlay above all content, including
// web views. Unsupported native platforms ignore it; see CapabilityWindowWatermark.
Watermark Watermark
// OnBackdropChange reports API activation initially and when it changes.
// Windows may still substitute a solid color. Other platforms do not call
// it. Update paint state without blocking; a change schedules a repaint.
Expand Down Expand Up @@ -333,6 +336,11 @@ type StateSlot struct {
}

func (config Config) normalize() (Config, error) {
watermark, err := config.Watermark.normalized()
if err != nil {
return Config{}, err
}
config.Watermark = watermark
if config.Title == "" {
config.Title = defaultTitle
}
Expand Down
10 changes: 8 additions & 2 deletions app/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ var ErrNoWindows = errors.New("app: application opened no windows")
// before resize/frame callbacks and repaints afterward.
// An always-on-top host additionally implements SetAlwaysOnTop(bool) error.
// A size-capable host additionally implements SetSize(int, int) error.
// A watermark-capable host additionally implements SetWatermark(Watermark) error.
// A decoration-capable host additionally implements SetDecorated(bool, func(error)) error.
type WindowControl interface {
Close()
Expand All @@ -36,6 +37,8 @@ type WindowControl interface {
// Host is the event loop an Application runs on. The native backends provide
// one over their platform adapters; a development runner such as package
// headless provides one to drive an application without a window.
// A host may additionally implement ShowNotification(Notification,
// NotificationEvents) (NotificationControl, error) for interactive notifications.
type Host interface {
// OpenWindow creates and presents a window. closed must be called exactly
// once, after the window has released its resources.
Expand Down Expand Up @@ -248,8 +251,10 @@ type Application struct {
// active is the window that last became the one the user works in, which is
// where the application menu bar's commands take effect, as a native menu's
// key equivalents do.
active *Window
openedAny bool
active *Window
openedAny bool
notifications map[*NotificationHandle]struct{}
notificationsClosed bool
}

// OpenWindow creates and presents one independent retained window.
Expand Down Expand Up @@ -434,6 +439,7 @@ func (application *Application) SetProgress(fraction float32) {
// goroutine.
func (application *Application) Quit() {
if application != nil && application.host != nil {
application.closeNotifications()
application.host.Quit()
}
}
Expand Down
32 changes: 32 additions & 0 deletions app/application_native.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,16 @@ import (
// start the native application from main to satisfy AppKit's main-thread requirement.
func RunApplication(start func(*Application) error) error {
attendFaults()
var owned *Application
defer func() {
if owned != nil {
owned.closeNotifications()
}
}()
if applicationRunner != nil {
return applicationRunner(func(host Host) error {
application := &Application{host: host}
owned = application
if err := start(application); err != nil {
return err
}
Expand All @@ -35,6 +42,7 @@ func RunApplication(start func(*Application) error) error {
defer runtime.UnlockOSThread()
return runNativeApplication(func(native platform.Application) error {
application := &Application{host: nativeHost{native}}
owned = application
if err := start(application); err != nil {
return err
}
Expand All @@ -48,6 +56,8 @@ func RunApplication(start func(*Application) error) error {
// nativeHost is the Host over a platform adapter.
type nativeHost struct{ native platform.Application }

var _ notificationHost = nativeHost{}

func (host nativeHost) OpenWindow(config Config, canvas *gfx.Canvas, closed func()) (WindowControl, error) {
windowConfig, painter, cleanup, err := prepareNativeWindow(config, canvas)
if err != nil {
Expand All @@ -66,6 +76,11 @@ func (host nativeHost) OpenWindow(config Config, canvas *gfx.Canvas, closed func
cleanup()
return nil, err
}
if config.Watermark.Text != "" {
if _, ok := window.(nativeWatermarkControl); !ok {
reportUnsupportedWatermark()
}
}
// A command the runtime did not receive through an event handler, such as a
// menu action, hands its result here: the painter carries it out and the
// window's waker asks for the frame that shows it.
Expand All @@ -89,6 +104,7 @@ var _ fullscreenControl = resultWindow{}
var _ alwaysOnTopControl = resultWindow{}
var _ shortcutCapturer = resultWindow{}
var _ titleControl = resultWindow{}
var _ watermarkControl = resultWindow{}
var _ windowIconControl = resultWindow{}
var _ platform.WindowMover = resultWindow{}

Expand Down Expand Up @@ -266,6 +282,14 @@ func (host nativeHost) Quit() { host.native.Quit() }

func (host nativeHost) Post(fn func()) { host.native.Post(fn) }

func (window resultWindow) SetWatermark(value Watermark) error {
control, ok := window.WindowControl.(nativeWatermarkControl)
if !ok {
return fmt.Errorf("%w: window watermarks", ErrUnsupported)
}
return control.SetWatermark(value.platform())
}

type nativeStatusItem struct{ item platform.StatusItem }

func (item nativeStatusItem) SetIcon(icon StatusIcon) error {
Expand All @@ -282,3 +306,11 @@ func (item nativeStatusItem) SetStatusHover(handler func(StatusAnchor, bool)) bo
})
}
func (item nativeStatusItem) RefreshMenu() { item.item.RefreshMenu() }

func (host nativeHost) ShowNotification(value Notification, events NotificationEvents) (NotificationControl, error) {
cancel, err := nativeShowNotification(value, events)
if err != nil {
return nil, err
}
return &nativeNotificationControl{cancel: cancel}, nil
}
6 changes: 6 additions & 0 deletions app/capabilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ const (
// them. Only Windows takes them; macOS and Linux file managers read files
// by path and cannot ask for a paste's content later.
CapabilityClipboardFilePromise
// CapabilityNotificationActivation means an application can own cancellable
// system notifications and receive activation while its loop is running.
CapabilityNotificationActivation
// CapabilityWindowWatermark means native text patterns can cover canvas and
// embedded native views without receiving input.
CapabilityWindowWatermark
)

// Capabilities is a set of platform integrations.
Expand Down
2 changes: 1 addition & 1 deletion app/capabilities_native.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@ func nativeCapabilities() Capabilities {
} else {
capabilities |= CapabilityWindowMaximize
}
capabilities |= capabilityTransparentWindow
capabilities |= capabilityTransparentWindow | capabilityNotificationActivation | capabilityWindowWatermark
return Capabilities(capabilities)
}
5 changes: 5 additions & 0 deletions app/capability_notification_native.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//go:build (darwin && !ios) || windows

package app

const capabilityNotificationActivation = CapabilityNotificationActivation
5 changes: 5 additions & 0 deletions app/capability_notification_other.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//go:build (!darwin && !windows) || ios

package app

const capabilityNotificationActivation Capability = 0
5 changes: 5 additions & 0 deletions app/capability_watermark_native.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//go:build (darwin && !ios) || windows

package app

const capabilityWindowWatermark = CapabilityWindowWatermark
5 changes: 5 additions & 0 deletions app/capability_watermark_other.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//go:build (!darwin && !windows) || ios

package app

const capabilityWindowWatermark Capability = 0
8 changes: 8 additions & 0 deletions app/content_window.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,11 @@ func (content *ContentWindow) RequestClose() {
content.Close()
}
}

// SetWatermark updates the content window's native overlay, as Window.SetWatermark.
func (content *ContentWindow) SetWatermark(value Watermark) error {
if content == nil || content.window == nil {
return fmt.Errorf("app: content window is closed")
}
return content.window.SetWatermark(value)
}
7 changes: 4 additions & 3 deletions app/directory_watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ type DirectoryChanges struct {
// DirectoryWatch reports changes to the entries of one directory from the
// operating system's own notification (inotify, FSEvents, ReadDirectoryChangesW).
//
// It does not poll and keeps no timer. An open watch holds one system
// registration and one goroutine blocked on it; closing it releases both, and an
// application that opens none pays nothing. A change wakes the window thread
// It does not poll and keeps no timer. An open watch holds system registrations
// and one goroutine blocked on them. On Windows the watch also follows changes
// to the directory's name when the system lets it watch the parent directory.
// Closing the watch releases these resources. A change wakes the window thread
// through the function given at the start, which only hands the news on (for
// example Invalidator.Invalidate, whose Config.OnWake then reads it with
// Changes).
Expand Down
11 changes: 10 additions & 1 deletion app/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ func (driver *Driver) Scroll(event gfx.ScrollEvent) error {
}
_, err := driver.painter.scroll(platform.ScrollEvent{
Modifiers: event.Modifiers | driver.heldModifiers(), X: event.X, Y: event.Y,
DeltaX: event.DeltaX, DeltaY: event.DeltaY, Precise: event.Precise,
DeltaX: event.DeltaX, DeltaY: event.DeltaY, Pages: event.Pages, Precise: event.Precise,
})
return err
}
Expand Down Expand Up @@ -1123,6 +1123,8 @@ type Primitive struct {
Layer uint16
// EdgeMask selects the boundary edges feathered for TrianglePrimitive.
EdgeMask uint8
// Coverage carries the original silhouette for a clipped stroke quad.
Coverage *gfx.StrokeCoverage
// Shaded gives a TrianglePrimitive the colors Shade[0] and Shade[1] at
// Points[1] and Points[2], Color being that of Points[0]; the color varies
// linearly between them.
Expand Down Expand Up @@ -1318,6 +1320,13 @@ func (driver *Driver) Snapshot() Snapshot {
if rectangle.Kind == scene.KindTriangle {
primitive.Kind = TrianglePrimitive
primitive.EdgeMask = rectangle.EdgeMask
if source, ok := rectangle.StrokeCoverage(); ok {
coverage := &gfx.StrokeCoverage{EdgeMask: source.EdgeMask}
for index, point := range source.Points {
coverage.Points[index] = gfx.Point(point)
}
primitive.Coverage = coverage
}
if rectangle.Shade.On {
primitive.Shaded = true
for index, color := range rectangle.Shade.Colors {
Expand Down
Loading
Loading