mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-05 09:25:38 +00:00
ui/app,apps/gophers,apps/hello: replace CreateWindow with NewWindow
Gio doesn't support multiple windows anyway, so get rid of the app.Windows channel and use NewWindow call for the mobile platforms as well. Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
+15
-20
@@ -15,7 +15,6 @@ import (
|
||||
"errors"
|
||||
"image"
|
||||
"runtime"
|
||||
"sync"
|
||||
"time"
|
||||
"unsafe"
|
||||
|
||||
@@ -36,13 +35,15 @@ type window struct {
|
||||
stage Stage
|
||||
}
|
||||
|
||||
// Only support one main window for now.
|
||||
var singleWindow struct {
|
||||
mu sync.Mutex
|
||||
hasOpts bool
|
||||
opts WindowOptions
|
||||
type windowError struct {
|
||||
window *Window
|
||||
err error
|
||||
}
|
||||
|
||||
var windowOpts = make(chan WindowOptions)
|
||||
|
||||
var windows = make(chan windowError)
|
||||
|
||||
var viewFactory func() uintptr
|
||||
|
||||
var views = make(map[C.CFTypeRef]*window)
|
||||
@@ -162,7 +163,6 @@ func gio_onTerminate(view C.CFTypeRef) {
|
||||
w := views[view]
|
||||
delete(views, view)
|
||||
w.setStage(StageDead)
|
||||
close(windows)
|
||||
}
|
||||
|
||||
//export gio_onHide
|
||||
@@ -185,28 +185,23 @@ func gio_onCreate(view C.CFTypeRef) {
|
||||
ow := newWindow(w)
|
||||
w.w = ow
|
||||
views[view] = w
|
||||
windows <- ow
|
||||
windows <- windowError{window: ow}
|
||||
}
|
||||
|
||||
func createWindow(opts WindowOptions) error {
|
||||
singleWindow.mu.Lock()
|
||||
defer singleWindow.mu.Unlock()
|
||||
if singleWindow.hasOpts {
|
||||
panic("only one window supported")
|
||||
}
|
||||
singleWindow.opts = opts
|
||||
singleWindow.hasOpts = true
|
||||
return nil
|
||||
func createWindow(opts WindowOptions) (*Window, error) {
|
||||
windowOpts <- opts
|
||||
werr := <-windows
|
||||
return werr.window, werr.err
|
||||
}
|
||||
|
||||
func Main() {
|
||||
view := C.CFTypeRef(viewFactory())
|
||||
if view == 0 {
|
||||
// TODO: return this error from CreateWindow.
|
||||
panic(errors.New("CreateWindow: failed to create view"))
|
||||
windows <- windowError{err: errors.New("CreateWindow: failed to create view")}
|
||||
return
|
||||
}
|
||||
cfg := getConfig()
|
||||
opts := singleWindow.opts
|
||||
opts := <-windowOpts
|
||||
w := cfg.Pixels(opts.Width)
|
||||
h := cfg.Pixels(opts.Height)
|
||||
title := C.CString(opts.Title)
|
||||
|
||||
Reference in New Issue
Block a user