migrate to eventbus, add support to macos

This commit is contained in:
aynakeya
2025-10-02 21:57:22 +08:00
parent a81eb4a131
commit 918e2e81b3
49 changed files with 251 additions and 236 deletions

26
gui/gutil/window.go Normal file
View File

@@ -0,0 +1,26 @@
//go:build darwin || windows || linux
package gutil
import (
"fyne.io/fyne/v2"
"github.com/go-gl/glfw/v3.3/glfw"
"reflect"
"unsafe"
)
// getGlfwWindow returns the glfw.Window pointer from a fyne.Window.
// very unsafe and ugly hacks. but it works.
// todo: replace with LifeCycle https://github.com/fyne-io/fyne/issues/4483
func getGlfwWindow(window fyne.Window) *glfw.Window {
rv := reflect.ValueOf(window)
if rv.Type().String() != "*glfw.window" {
return nil
}
rv = rv.Elem()
var glfwWindowPtr uintptr = rv.FieldByName("viewport").Pointer()
for glfwWindowPtr == 0 {
glfwWindowPtr = rv.FieldByName("viewport").Pointer()
}
return (*glfw.Window)(unsafe.Pointer(glfwWindowPtr))
}

View File

@@ -0,0 +1,15 @@
//go:build darwin
package gutil
import (
"fyne.io/fyne/v2"
)
func GetWindowHandle(window fyne.Window) uintptr {
glfwWindow := getGlfwWindow(window)
if glfwWindow == nil {
return 0
}
return uintptr(glfwWindow.GetCocoaWindow())
}

15
gui/gutil/window_linux.go Normal file
View File

@@ -0,0 +1,15 @@
//go:build linux
package gutil
import (
"fyne.io/fyne/v2"
)
func GetWindowHandle(window fyne.Window) uintptr {
glfwWindow := getGlfwWindow(window)
if glfwWindow == nil {
return 0
}
return uintptr(glfwWindow.GetX11Window())
}

View File

@@ -0,0 +1,9 @@
//go:build !darwin && !windows && !linux
package gutil
import "fyne.io/fyne/v2"
func GetWindowHandle(window fyne.Window) uintptr {
return 0
}

View File

@@ -0,0 +1,16 @@
//go:build windows
package gutil
import (
"fyne.io/fyne/v2"
"unsafe"
)
func GetWindowHandle(window fyne.Window) uintptr {
glfwWindow := getGlfwWindow(window)
if glfwWindow == nil {
return 0
}
return uintptr(unsafe.Pointer(glfwWindow.GetWin32Window()))
}