This commit is contained in:
aynakeya
2024-04-10 00:42:33 -07:00
parent 8d73a3c284
commit f926f15606
145 changed files with 2852 additions and 4296 deletions

23
gui/xfyne/window.go Normal file
View File

@@ -0,0 +1,23 @@
package xfyne
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.
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,12 @@
//go:build darwin
// +build darwin
package xfyne
func GetWindowHandle(window fyne.Window) uintptr {
glfwWindow := getGlfwWindow(window)
if glfwWindow == nil {
return 0
}
return uintptr(glfwWindow.GetCocoaWindow())
}

16
gui/xfyne/window_linux.go Normal file
View File

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

10
gui/xfyne/window_other.go Normal file
View File

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

View File

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