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
+3
View File
@@ -650,6 +650,9 @@ func (w *window) ReadClipboard() {
})
}
// Close the window. Not implemented for Android.
func (w *window) Close() {}
// RunOnMain is the exported version of runOnMain without a JNI
// environement.
func RunOnMain(f func()) {
+3
View File
@@ -299,6 +299,9 @@ func (w *window) ShowTextInput(show bool) {
})
}
// Close the window. Not implemented for iOS.
func (w *window) Close() {}
func NewWindow(win Callbacks, opts *Options) error {
mainWindow.in <- windowAndOptions{win, opts}
return <-mainWindow.errs
+3
View File
@@ -406,6 +406,9 @@ func (w *window) ShowTextInput(show bool) {
}()
}
// Close the window. Not implemented for js.
func (w *window) Close() {}
func (w *window) draw(sync bool) {
width, height, scale, cfg := w.config()
if cfg == (unit.Metric{}) || width == 0 || height == 0 {
+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
+5
View File
@@ -153,6 +153,11 @@ void gio_appTerminate(void) {
}
}
void gio_close(CFTypeRef windowRef) {
NSWindow* window = (__bridge NSWindow *)windowRef;
[window performClose:nil];
}
@implementation GioAppDelegate
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
[[NSRunningApplication currentApplication] activateWithOptions:(NSApplicationActivateAllWindows | NSApplicationActivateIgnoringOtherApps)];
+3
View File
@@ -1426,6 +1426,9 @@ func (w *window) surface() (*C.struct_wl_surface, int, int) {
func (w *window) ShowTextInput(show bool) {}
// Close the window. Not implemented for Wayland.
func (w *window) Close() {}
// detectUIScale reports the system UI scale, or 1.0 if it fails.
func detectUIScale() float32 {
// TODO: What about other window environments?
+3
View File
@@ -501,6 +501,9 @@ func (w *window) HWND() (syscall.Handle, int, int) {
return w.hwnd, w.width, w.height
}
// Close the window. Not implemented for Windows.
func (w *window) Close() {}
func convertKeyCode(code uintptr) (string, bool) {
if '0' <= code && code <= '9' || 'A' <= code && code <= 'Z' {
return string(rune(code)), true
+3
View File
@@ -110,6 +110,9 @@ func (w *x11Window) WriteClipboard(s string) {
func (w *x11Window) ShowTextInput(show bool) {}
// Close the window. Not implemented for X11.
func (w *x11Window) Close() {}
var x11OneByte = make([]byte, 1)
func (w *x11Window) wakeup() {
+3
View File
@@ -57,6 +57,9 @@ type Driver interface {
ReadClipboard()
// WriteClipboard requests a clipboard write.
WriteClipboard(s string)
// Close the window.
Close()
}
type windowRendezvous struct {
+11
View File
@@ -208,6 +208,17 @@ func (w *Window) WriteClipboard(s string) {
})
}
// Close the window. The window's event loop should exit when it receives
// system.DestroyEvent.
//
// Currently, only the macOS driver implements this functionality, all others
// are stubbed.
func (w *Window) Close() {
w.driverDo(func() {
w.driver.Close()
})
}
// driverDo calls f as soon as the window has a valid driver attached,
// or does nothing if the window is destroyed while waiting.
func (w *Window) driverDo(f func()) {