Skip to content

Commit

Permalink
add AndroidWindowContext with window pointer
Browse files Browse the repository at this point in the history
  • Loading branch information
dweymouth committed Jun 8, 2024
1 parent e42783d commit 4681657
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 6 deletions.
14 changes: 12 additions & 2 deletions driver/native.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,23 @@ type NativeWindow interface {
}

// 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.
// The VM, Env and Ctx pointers are required to make various calls into JVM methods.
//
// Since: 2.3
type AndroidContext struct {
VM, Env, Ctx uintptr
}

// AndroidWindowContext is passed to the NativeWindow.RunNative callback when it is executed
// on an Android device. The NativeWindow field is of type `*C.ANativeWindow`.
// The VM, Env and Ctx pointers are required to make various calls into JVM methods.
//
// Since: 2.5
type AndroidWindowContext struct {
AndroidContext
NativeWindow uintptr
}

// UnknownContext is passed to the RunNative callback when it is executed
// on devices or windows without special native context.
//
Expand All @@ -34,7 +44,7 @@ type WindowsWindowContext struct {
}

// MacWindowContext is passed to the NativeWindow.RunNative callback
// when it is executed on a Mac OS device.
// when it is executed on a macOS device.
//
// Since: 2.5
type MacWindowContext struct {
Expand Down
2 changes: 1 addition & 1 deletion internal/driver/mobile/app/android.go
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ func mainUI(vm, jniEnv, ctx uintptr) error {
DarkMode: darkMode,
}
theApp.events.In() <- currentSize
theApp.events.In() <- paint.Event{External: true}
theApp.events.In() <- paint.Event{External: true, Window: uintptr(unsafe.Pointer(w))}
case <-windowDestroyed:
if C.surface != nil {
if errStr := C.destroyEGLSurface(); errStr != nil {
Expand Down
5 changes: 4 additions & 1 deletion internal/driver/mobile/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,11 @@ func (d *driver) handleLifecycle(e lifecycle.Event, w *window) {
}
}

func (d *driver) handlePaint(e paint.Event, w fyne.Window) {
func (d *driver) handlePaint(e paint.Event, w *window) {
c := w.Canvas().(*canvas)
if e.Window != 0 { // not all paint events come from hardware
w.handle = e.Window
}
d.painting = false
if d.glctx == nil || e.External {
return
Expand Down
3 changes: 3 additions & 0 deletions internal/driver/mobile/event/paint/paint.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,7 @@ type Event struct {
// should ignore external paint events to avoid a backlog of paint
// events building up.
External bool

// Window specifies a native handle for the window being painted into.
Window uintptr
}
1 change: 1 addition & 0 deletions internal/driver/mobile/window.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type window struct {
canvas *canvas
icon fyne.Resource
menu *fyne.MainMenu
handle uintptr // the window handle - currently just Android
}

func (w *window) Title() string {
Expand Down
10 changes: 8 additions & 2 deletions internal/driver/mobile/window_android.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,14 @@ var _ driver.NativeWindow = (*window)(nil)

func (w *window) RunNative(f func(context any) error) error {
return app.RunOnJVM(func(vm, env, ctx uintptr) error {
// TODO: define driver.AndroidWindowContext that also includes the View
data := &driver.AndroidContext{VM: vm, Env: env, Ctx: ctx}
data := &driver.AndroidWindowContext{
NativeWindow: w.handle,
AndroidContext: driver.AndroidContext{
VM: vm,
Env: env,
Ctx: ctx,
},
}
return f(data)
})
}

0 comments on commit 4681657

Please sign in to comment.