Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move NativeWindow interface to driver package
Browse files Browse the repository at this point in the history
dweymouth committed May 23, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 7b8939c commit e25be3e
Showing 8 changed files with 26 additions and 31 deletions.
18 changes: 14 additions & 4 deletions driver/native.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
package driver

// AndroidContext is passed to the `driver.RunNative` callback when it is executed on an Android device.
// NativeWindow is an extension interface for `fyne.Window` that gives access
// to platform-native features of application windows.
//
// Since: 2.5
type NativeWindow interface {
// RunNative provides a way to execute code within the platform-specific runtime context for a window.
// The context types are defined in the `driver` package and the specific context passed will differ by platform.
RunNative(func(context any) error) error
}

// AndroidContext is passed to the RunNative callback when it is executed on an Android device.
// The VM, Env and Ctx pointers are reqiured to make various calls into JVM methods.
//
// Since: 2.3
@@ -14,7 +24,7 @@ type AndroidContext struct {
// Since: 2.3
type UnknownContext struct{}

// WindowsWindowContext is passed to the `(fyne.NativeWindow).RunNative` callback
// WindowsWindowContext is passed to the NativeWindow.RunNative callback
// when it is executed on a Microsoft Windows device.
//
// Since: 2.5
@@ -23,7 +33,7 @@ type WindowsWindowContext struct {
HWND uintptr
}

// MacWindowContext is passed to the `(fyne.NativeWindow).RunNative` callback
// MacWindowContext is passed to the NativeWindow.RunNative callback
// when it is executed on a Mac OS device.
//
// Since: 2.5
@@ -32,7 +42,7 @@ type MacWindowContext struct {
NSWindow uintptr
}

// X11WindowContext is passed to the `(fyne.NativeWindow).RunNative` callback
// X11WindowContext is passed to the NativeWindow.RunNative callback
// when it is executed on a device with the X11 windowing system.
//
// Since: 2.5
5 changes: 2 additions & 3 deletions internal/driver/glfw/window_darwin.go
Original file line number Diff line number Diff line change
@@ -3,12 +3,11 @@
package glfw

import (
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/driver"
)

// assert we are implementing fyne.NativeWindow
var _ fyne.NativeWindow = (*window)(nil)
// assert we are implementing driver.NativeWindow
var _ driver.NativeWindow = (*window)(nil)

func (w *window) RunNative(f func(any) error) error {
var err error
5 changes: 2 additions & 3 deletions internal/driver/glfw/window_wayland.go
Original file line number Diff line number Diff line change
@@ -3,7 +3,6 @@
package glfw

import (
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/driver"
)

@@ -12,8 +11,8 @@ func (w *window) GetWindowHandle() string {
return "" // TODO: Find a way to get the Wayland handle for xdg_foreign protocol. Return "wayland:{id}".
}

// assert we are implementing fyne.NativeWindow
var _ fyne.NativeWindow = (*window)(nil)
// assert we are implementing driver.NativeWindow
var _ driver.NativeWindow = (*window)(nil)

func (w *window) RunNative(f func(any) error) error {
var err error
4 changes: 2 additions & 2 deletions internal/driver/glfw/window_windows.go
Original file line number Diff line number Diff line change
@@ -52,8 +52,8 @@ func (w *window) computeCanvasSize(width, height int) fyne.Size {
return fyne.NewSize(scale.ToFyneCoordinate(w.canvas, width), scale.ToFyneCoordinate(w.canvas, height))
}

// assert we are implementing fyne.NativeWindow
var _ fyne.NativeWindow = (*window)(nil)
// assert we are implementing driver.NativeWindow
var _ driver.NativeWindow = (*window)(nil)

func (w *window) RunNative(f func(any) error) error {
var err error
5 changes: 2 additions & 3 deletions internal/driver/glfw/window_x11.go
Original file line number Diff line number Diff line change
@@ -5,7 +5,6 @@ package glfw
import (
"strconv"

"fyne.io/fyne/v2"
"fyne.io/fyne/v2/driver"
)

@@ -15,8 +14,8 @@ func (w *window) GetWindowHandle() string {
return "x11:" + strconv.FormatUint(uint64(xid), 16)
}

// assert we are implementing fyne.NativeWindow
var _ fyne.NativeWindow = (*window)(nil)
// assert we are implementing driver.NativeWindow
var _ driver.NativeWindow = (*window)(nil)

func (w *window) RunNative(f func(any) error) error {
var err error
5 changes: 2 additions & 3 deletions internal/driver/mobile/window_android.go
Original file line number Diff line number Diff line change
@@ -3,13 +3,12 @@
package mobile

import (
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/driver"
"fyne.io/fyne/v2/internal/driver/mobile/app"
)

// Assert we are satisfying the NativeWindow interface
var _ fyne.NativeWindow = (*window)(nil)
// Assert we are satisfying the driver.NativeWindow interface
var _ driver.NativeWindow = (*window)(nil)

func (w *window) RunNative(f func(context any) error) error {
return app.RunOnJVM(func(vm, env, ctx uintptr) error {
5 changes: 2 additions & 3 deletions internal/driver/mobile/window_ios.go
Original file line number Diff line number Diff line change
@@ -3,12 +3,11 @@
package mobile

import (
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/driver"
)

// Assert we are satisfying the NativeWindow interface
var _ fyne.NativeWindow = (*window)(nil)
// Assert we are satisfying the driver.NativeWindow interface
var _ driver.NativeWindow = (*window)(nil)

func (w *window) RunNative(fn func(context any) error) error {
return fn(&driver.UnknownContext{})
10 changes: 0 additions & 10 deletions window.go
Original file line number Diff line number Diff line change
@@ -103,13 +103,3 @@ type Window interface {
// Clipboard returns the system clipboard
Clipboard() Clipboard
}

// NativeWindow is an extension interface for Window that gives access
// to platform-native features of application windows.
//
// Since: 2.5
type NativeWindow interface {
// RunNative provides a way to execute code within the platform-specific runtime context for a window.
// The context types are defined in the `driver` package and the specific context passed will differ by platform.
RunNative(func(context any) error) error
}

0 comments on commit e25be3e

Please sign in to comment.