app/internal/window: [macOS] delay window creation until ready

Fixes #128

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2020-06-07 08:42:36 +02:00
parent 0749afc13c
commit 483084f4be
+10 -10
View File
@@ -301,9 +301,16 @@ func NewWindow(win Callbacks, opts *Options) error {
if err := <-errch; err != nil { if err := <-errch; err != nil {
return err return err
} }
go func() { runOnMain(func() {
// Window sizes is in unscaled screen coordinates, not device pixels.
cfg := configFor(1.0)
width := cfg.Px(opts.Width)
height := cfg.Px(opts.Height)
title := C.CString(opts.Title)
defer C.free(unsafe.Pointer(title))
nextTopLeft = C.gio_createWindow(window.view, title, C.CGFloat(width), C.CGFloat(height), nextTopLeft)
win.SetDriver(window) win.SetDriver(window)
}() })
return nil return nil
} }
@@ -316,6 +323,7 @@ func newWindow(win Callbacks, opts *Options) (*window, error) {
w := &window{ w := &window{
view: view, view: view,
scale: scale, scale: scale,
w: win,
} }
dl, err := NewDisplayLink(func() { dl, err := NewDisplayLink(func() {
runOnMain(func() { runOnMain(func() {
@@ -329,14 +337,6 @@ func newWindow(win Callbacks, opts *Options) (*window, error) {
C.CFRelease(view) C.CFRelease(view)
return nil, err return nil, err
} }
// Window sizes is in unscaled screen coordinates, not device pixels.
cfg := configFor(1.0)
width := cfg.Px(opts.Width)
height := cfg.Px(opts.Height)
title := C.CString(opts.Title)
defer C.free(unsafe.Pointer(title))
nextTopLeft = C.gio_createWindow(view, title, C.CGFloat(width), C.CGFloat(height), nextTopLeft)
w.w = win
insertView(view, w) insertView(view, w)
return w, nil return w, nil
} }