From 856b339298bc19ccd814c8ed2dd283ab4a028e2d Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Wed, 31 Jul 2024 23:54:16 +0900 Subject: [PATCH] internal/ui: bug fix: show a black dot at the red button when needed When SetWindowClosingHandled(true) is called, a black dot should be shown at the red button to close the window. Closes #3020 --- internal/ui/ui_darwin.go | 11 +++++++++++ internal/ui/ui_glfw.go | 23 +++++++++++++++++++++++ internal/ui/ui_linbsd.go | 4 ++++ internal/ui/ui_windows.go | 4 ++++ 4 files changed, 42 insertions(+) diff --git a/internal/ui/ui_darwin.go b/internal/ui/ui_darwin.go index f1fd13f3f..ed4ff8fe6 100644 --- a/internal/ui/ui_darwin.go +++ b/internal/ui/ui_darwin.go @@ -238,6 +238,7 @@ var ( sel_origResizable = objc.RegisterName("isOrigResizable") sel_setCollectionBehavior = objc.RegisterName("setCollectionBehavior:") sel_setDelegate = objc.RegisterName("setDelegate:") + sel_setDocumentEdited = objc.RegisterName("setDocumentEdited:") sel_setOrigDelegate = objc.RegisterName("setOrigDelegate:") sel_setOrigResizable = objc.RegisterName("setOrigResizable:") sel_toggleFullScreen = objc.RegisterName("toggleFullScreen:") @@ -433,3 +434,13 @@ func initializeWindowAfterCreation(w *glfw.Window) error { func (u *UserInterface) skipTaskbar() error { return nil } + +// setDocumentEdited must be called from the main thread. +func (u *UserInterface) setDocumentEdited(edited bool) error { + w, err := u.window.GetCocoaWindow() + if err != nil { + return err + } + objc.ID(w).Send(sel_setDocumentEdited, edited) + return nil +} diff --git a/internal/ui/ui_glfw.go b/internal/ui/ui_glfw.go index 368d7a102..28dc21df3 100644 --- a/internal/ui/ui_glfw.go +++ b/internal/ui/ui_glfw.go @@ -568,6 +568,22 @@ func (u *UserInterface) setWindowClosingHandled(handled bool) { u.m.Lock() u.windowClosingHandled = handled u.m.Unlock() + + if !u.isRunning() { + return + } + if u.isTerminated() { + return + } + u.mainThread.Call(func() { + if u.isTerminated() { + return + } + if err := u.setDocumentEdited(handled); err != nil { + u.setError(err) + return + } + }) } // isFullscreen must be called from the main thread. @@ -874,6 +890,13 @@ func (u *UserInterface) createWindow() error { return err } + u.m.Lock() + closingHandled := u.windowClosingHandled + u.m.Unlock() + if err := u.setDocumentEdited(closingHandled); err != nil { + return err + } + return nil } diff --git a/internal/ui/ui_linbsd.go b/internal/ui/ui_linbsd.go index 378f27f35..7d07f2bc3 100644 --- a/internal/ui/ui_linbsd.go +++ b/internal/ui/ui_linbsd.go @@ -200,3 +200,7 @@ func initializeWindowAfterCreation(w *glfw.Window) error { func (u *UserInterface) skipTaskbar() error { return nil } + +func (u *UserInterface) setDocumentEdited(edited bool) error { + return nil +} diff --git a/internal/ui/ui_windows.go b/internal/ui/ui_windows.go index 4d5d821ef..b9bdf9ef0 100644 --- a/internal/ui/ui_windows.go +++ b/internal/ui/ui_windows.go @@ -242,6 +242,10 @@ func (u *UserInterface) skipTaskbar() error { return nil } +func (u *UserInterface) setDocumentEdited(edited bool) error { + return nil +} + func init() { if microsoftgdk.IsXbox() { // TimeBeginPeriod might not be defined in Xbox.