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.