app,app/internal/window: [macOS] add app.Window.Close for closing a window

Recently support was added for multiple top-level windows. Add support
for closing those windows.

macOS only; all others stubbed out.

Signed-off-by: Larry Clapp <larry@theclapp.org>
This commit is contained in:
Larry Clapp
2020-06-17 09:10:48 -04:00
committed by Elias Naur
parent 7f836fa627
commit 602d54dc5e
10 changed files with 49 additions and 0 deletions
+12
View File
@@ -44,6 +44,7 @@ __attribute__ ((visibility ("hidden"))) void gio_appTerminate(void);
__attribute__ ((visibility ("hidden"))) CFTypeRef gio_createWindow(CFTypeRef viewRef, const char *title, CGFloat width, CGFloat height);
__attribute__ ((visibility ("hidden"))) void gio_makeKeyAndOrderFront(CFTypeRef windowRef);
__attribute__ ((visibility ("hidden"))) NSPoint gio_cascadeTopLeftFromPoint(CFTypeRef windowRef, NSPoint topLeft);
__attribute__ ((visibility ("hidden"))) void gio_close(CFTypeRef windowRef);
*/
import "C"
@@ -132,6 +133,17 @@ func (w *window) SetAnimating(anim bool) {
}
}
// Close the window. Only implemented for macOS.
func (w *window) Close() {
runOnMain(func() {
// Make sure the view is still valid. The window might've been closed
// during the switch to the main thread.
if w.view != 0 {
C.gio_close(w.window)
}
})
}
func (w *window) setStage(stage system.Stage) {
if stage == w.stage {
return