initial implementation of Windows SMTC integration

This commit is contained in:
Drew Weymouth
2025-01-15 17:42:44 -08:00
parent 6d4d87cb66
commit cb01703776
5 changed files with 282 additions and 15 deletions
+23 -15
View File
@@ -10,6 +10,8 @@ import (
"sync"
"time"
"golang.org/x/sys/windows"
"github.com/dweymouth/supersonic/backend"
"github.com/dweymouth/supersonic/res"
"github.com/dweymouth/supersonic/ui"
@@ -87,27 +89,33 @@ func main() {
}
}()
// slightly hacky workaround for https://github.com/fyne-io/fyne/issues/4964
if runtime.GOOS == "linux" {
workaroundWindowSize := sync.OnceFunc(func() {
go func() {
isWayland := false
mainWindow.Window.(driver.NativeWindow).RunNative(func(ctx any) {
_, isWayland = ctx.(*driver.WaylandWindowContext)
})
if !isWayland {
startupOnceTasks := sync.OnceFunc(func() {
mainWindow.Window.(driver.NativeWindow).RunNative(func(ctx any) {
// intialize Windows SMTC
if runtime.GOOS == "windows" {
if maj, _, _ := windows.RtlGetNtVersionNumbers(); maj >= 10 {
// SMTC is only available from Windows 10 (10.0.10240) onward
hwnd := ctx.(driver.WindowsWindowContext).HWND
myApp.SetupWindowsSMTC(hwnd)
}
}
// slightly hacky workaround for https://github.com/fyne-io/fyne/issues/4964
_, isWayland := ctx.(*driver.WaylandWindowContext)
if runtime.GOOS == "linux" && !isWayland {
go func() {
time.Sleep(50 * time.Millisecond)
s := mainWindow.DesiredSize()
mainWindow.Window.Resize(s.Subtract(fyne.NewSize(4, 0)))
time.Sleep(50 * time.Millisecond)
mainWindow.Window.Resize(s) // back to desired size
}
}()
}()
}
})
fyneApp.Lifecycle().SetOnEnteredForeground(func() {
workaroundWindowSize()
})
}
})
fyneApp.Lifecycle().SetOnEnteredForeground(func() {
startupOnceTasks()
})
mainWindow.ShowAndRun()