mirror of
https://github.com/AynaLivePlayer/AynaLivePlayer.git
synced 2025-12-07 10:52:49 +08:00
migrate to eventbus, add support to macos
This commit is contained in:
26
gui/gutil/window.go
Normal file
26
gui/gutil/window.go
Normal 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))
|
||||
}
|
||||
15
gui/gutil/window_darwin.go
Normal file
15
gui/gutil/window_darwin.go
Normal 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
15
gui/gutil/window_linux.go
Normal 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())
|
||||
}
|
||||
9
gui/gutil/window_other.go
Normal file
9
gui/gutil/window_other.go
Normal 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
|
||||
}
|
||||
16
gui/gutil/window_windows.go
Normal file
16
gui/gutil/window_windows.go
Normal 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()))
|
||||
}
|
||||
Reference in New Issue
Block a user