From 57d527bea25e17561624775aba17a885e46223f4 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sun, 22 Dec 2019 01:41:51 +0900 Subject: [PATCH] driver: Remove 'title' argument from UI.Run --- internal/driver/ui.go | 2 +- internal/uidriver/glfw/ui.go | 25 ++++++++++++++++++++----- internal/uidriver/js/ui.go | 3 +-- internal/uidriver/mobile/ui.go | 10 +++++----- run.go | 3 ++- 5 files changed, 29 insertions(+), 14 deletions(-) diff --git a/internal/driver/ui.go b/internal/driver/ui.go index 04772e860..6287cb5bd 100644 --- a/internal/driver/ui.go +++ b/internal/driver/ui.go @@ -31,7 +31,7 @@ type UIContext interface { var RegularTermination = errors.New("regular termination") type UI interface { - Run(title string, context UIContext, graphics Graphics) error + Run(context UIContext, graphics Graphics) error RunWithoutMainLoop(width, height int, scale float64, title string, context UIContext, graphics Graphics) <-chan error DeviceScaleFactor() float64 diff --git a/internal/uidriver/glfw/ui.go b/internal/uidriver/glfw/ui.go index 260a5e081..edc8983b3 100644 --- a/internal/uidriver/glfw/ui.go +++ b/internal/uidriver/glfw/ui.go @@ -55,6 +55,7 @@ type UserInterface struct { lastDeviceScaleFactor float64 initMonitor *glfw.Monitor + initTitle string initFullscreenWidthInDP int initFullscreenHeightInDP int initFullscreen bool @@ -194,6 +195,19 @@ func (u *UserInterface) setRunning(running bool) { u.m.Unlock() } +func (u *UserInterface) getInitTitle() string { + u.m.RLock() + v := u.initTitle + u.m.RUnlock() + return v +} + +func (u *UserInterface) setInitTitle(title string) { + u.m.RLock() + u.initTitle = title + u.m.RUnlock() +} + func (u *UserInterface) isInitFullscreen() bool { u.m.RLock() v := u.initFullscreen @@ -406,6 +420,7 @@ func (u *UserInterface) IsVsyncEnabled() bool { func (u *UserInterface) SetWindowTitle(title string) { if !u.isRunning() { + u.setInitTitle(title) return } u.title = title @@ -554,7 +569,7 @@ func init() { runtime.LockOSThread() } -func (u *UserInterface) Run(title string, uicontext driver.UIContext, graphics driver.Graphics) error { +func (u *UserInterface) Run(uicontext driver.UIContext, graphics driver.Graphics) error { // Initialize the main thread first so the thread is available at u.run (#809). u.t = thread.New() u.graphics = graphics @@ -566,7 +581,7 @@ func (u *UserInterface) Run(title string, uicontext driver.UIContext, graphics d go func() { defer cancel() defer close(ch) - if err := u.run(title, uicontext); err != nil { + if err := u.run(uicontext); err != nil { ch <- err } }() @@ -630,7 +645,7 @@ func (u *UserInterface) createWindow() error { return nil } -func (u *UserInterface) run(title string, context driver.UIContext) error { +func (u *UserInterface) run(context driver.UIContext) error { if err := u.t.Call(func() error { // The window is created at initialize(). u.window.Destroy() @@ -682,8 +697,8 @@ func (u *UserInterface) run(title string, context driver.UIContext) error { u.SetWindowPosition(u.getInitWindowPosition()) _ = u.t.Call(func() error { - u.title = title - u.window.SetTitle(title) + u.title = u.getInitTitle() + u.window.SetTitle(u.title) u.window.Show() return nil diff --git a/internal/uidriver/js/ui.go b/internal/uidriver/js/ui.go index 63b3da7d3..be26e740a 100644 --- a/internal/uidriver/js/ui.go +++ b/internal/uidriver/js/ui.go @@ -403,8 +403,7 @@ func init() { })) } -func (u *UserInterface) Run(title string, context driver.UIContext, graphics driver.Graphics) error { - document.Set("title", title) +func (u *UserInterface) Run(context driver.UIContext, graphics driver.Graphics) error { canvas.Call("focus") u.running = true ch := u.loop(context) diff --git a/internal/uidriver/mobile/ui.go b/internal/uidriver/mobile/ui.go index 0fbeceaa8..22b29b993 100644 --- a/internal/uidriver/mobile/ui.go +++ b/internal/uidriver/mobile/ui.go @@ -183,12 +183,12 @@ func (u *UserInterface) appMain(a app.App) { } } -func (u *UserInterface) Run(title string, context driver.UIContext, graphics driver.Graphics) error { +func (u *UserInterface) Run(context driver.UIContext, graphics driver.Graphics) error { // TODO: Remove width/height/scale arguments. They are not used from gomobile-build. u.setGBuildSizeCh = make(chan struct{}) go func() { - if err := u.run(16, 16, 1, title, context, graphics, true); err != nil { + if err := u.run(16, 16, 1, context, graphics, true); err != nil { // As mobile apps never ends, Loop can't return. Just panic here. panic(err) } @@ -201,7 +201,8 @@ func (u *UserInterface) RunWithoutMainLoop(width, height int, scale float64, tit ch := make(chan error) go func() { defer close(ch) - if err := u.run(width, height, scale, title, context, graphics, false); err != nil { + // title is ignored? + if err := u.run(width, height, scale, context, graphics, false); err != nil { ch <- err } }() @@ -209,7 +210,7 @@ func (u *UserInterface) RunWithoutMainLoop(width, height int, scale float64, tit return ch } -func (u *UserInterface) run(width, height int, scale float64, title string, context driver.UIContext, graphics driver.Graphics, mainloop bool) (err error) { +func (u *UserInterface) run(width, height int, scale float64, context driver.UIContext, graphics driver.Graphics, mainloop bool) (err error) { // Convert the panic to a regular error so that Java/Objective-C layer can treat this easily e.g., for // Crashlytics. A panic is treated as SIGABRT, and there is no way to handle this on Java/Objective-C layer // unfortunately. @@ -228,7 +229,6 @@ func (u *UserInterface) run(width, height int, scale float64, title string, cont u.context = context u.graphics = graphics u.m.Unlock() - // title is ignored? if graphics.IsGL() { var ctx gl.Context diff --git a/run.go b/run.go index eb9023a80..ef5060424 100644 --- a/run.go +++ b/run.go @@ -157,7 +157,8 @@ func Run(f func(*Image) error, width, height int, scale float64, title string) e theUIContext = newUIContext(game, scale) fixWindowPosition(int(float64(width)*scale), int(float64(height)*scale)) - if err := uiDriver().Run(title, theUIContext, graphicsDriver()); err != nil { + SetWindowTitle(title) + if err := uiDriver().Run(theUIContext, graphicsDriver()); err != nil { if err == driver.RegularTermination { return nil }