5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-02 14:41:29 +08:00

Move WindowGet* to main thread (#1464)

This commit is contained in:
Lea Anthony 2022-06-29 20:07:16 +10:00 committed by GitHub
parent 7cc3652a39
commit 7141c972fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -565,6 +565,7 @@ void SetWindowIcon(GtkWindow* window, const guchar* buf, gsize len) {
import "C"
import (
"strings"
"sync"
"unsafe"
"github.com/wailsapp/wails/v2/internal/frontend"
@ -707,13 +708,25 @@ func (w *Window) SetPosition(x int, y int) {
func (w *Window) Size() (int, int) {
var width, height C.int
C.gtk_window_get_size(w.asGTKWindow(), &width, &height)
var wg sync.WaitGroup
wg.Add(1)
invokeOnMainThread(func() {
C.gtk_window_get_size(w.asGTKWindow(), &width, &height)
wg.Done()
})
wg.Wait()
return int(width), int(height)
}
func (w *Window) GetPosition() (int, int) {
var width, height C.int
C.gtk_window_get_position(w.asGTKWindow(), &width, &height)
var wg sync.WaitGroup
wg.Add(1)
invokeOnMainThread(func() {
C.gtk_window_get_position(w.asGTKWindow(), &width, &height)
wg.Done()
})
wg.Wait()
return int(width), int(height)
}