diff --git a/internal/ui/ui_glfw.go b/internal/ui/ui_glfw.go index c475380ac..55347d6cc 100644 --- a/internal/ui/ui_glfw.go +++ b/internal/ui/ui_glfw.go @@ -311,6 +311,16 @@ func IsRunnableInBackground() bool { return currentUI.isRunnableInBackground() } +func SetWindowTitle(title string) { + if !currentUI.isRunning() { + return + } + _ = currentUI.runOnMainThread(func() error { + currentUI.window.SetTitle(title) + return nil + }) +} + func SetWindowIcon(iconImages []image.Image) { if !currentUI.isRunning() { currentUI.setInitIconImages(iconImages) diff --git a/internal/ui/ui_js.go b/internal/ui/ui_js.go index 7c545a29d..449597504 100644 --- a/internal/ui/ui_js.go +++ b/internal/ui/ui_js.go @@ -112,6 +112,11 @@ func SetCursorVisible(visible bool) { } } +func SetWindowTitle(title string) { + doc := js.Global.Get("document") + doc.Set("title", title) +} + func SetWindowIcon(iconImages []image.Image) { // Do nothing } diff --git a/internal/ui/ui_mobile.go b/internal/ui/ui_mobile.go index b2f3326f7..21aa70d85 100644 --- a/internal/ui/ui_mobile.go +++ b/internal/ui/ui_mobile.go @@ -360,6 +360,10 @@ func SetRunnableInBackground(runnableInBackground bool) { // Do nothing } +func SetWindowTitle(title string) { + // Do nothing +} + func SetWindowIcon(iconImages []image.Image) { // Do nothing } diff --git a/run.go b/run.go index d5258d492..07b156ce3 100644 --- a/run.go +++ b/run.go @@ -428,6 +428,15 @@ func SetRunnableInBackground(runnableInBackground bool) { ui.SetRunnableInBackground(runnableInBackground) } +// SetWindowTitle sets the title of the window. +// +// SetWindowTitle does nothing on mobiles. +// +// SetWindowTitle is concurrent-safe. +func SetWindowTitle(title string) { + ui.SetWindowTitle(title) +} + // SetWindowIcon sets the icon of the game window. // // If len(iconImages) is 0, SetWindowIcon reverts the icon to the default one.