~eliasnaur/gio-patches

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch

[PATCH] app/internal/window,app: [macOS] close a window

Details
Message ID
<20200615150821.24073-1-larry@theclapp.org>
DKIM signature
missing
Download raw message
Patch: +24 -0
Recently support was added for multiple top-level windows.  Add support
for closing those windows.

Signed-off-by: Larry Clapp <larry@theclapp.org>
---
 app/internal/window/os_macos.go | 7 +++++++
 app/internal/window/os_macos.m  | 6 ++++++
 app/internal/window/window.go   | 3 +++
 app/window.go                   | 8 ++++++++
 4 files changed, 24 insertions(+)

diff --git a/app/internal/window/os_macos.go b/app/internal/window/os_macos.go
index fef2acd..ca9ed56 100644
--- a/app/internal/window/os_macos.go
+++ b/app/internal/window/os_macos.go
@@ -43,6 +43,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 viewRef);
*/
import "C"

@@ -131,6 +132,12 @@ func (w *window) SetAnimating(anim bool) {
	}
}

func (w *window) Close() {
	runOnMain(func() {
		C.gio_close(w.window)
	})
}

func (w *window) setStage(stage system.Stage) {
	if stage == w.stage {
		return
diff --git a/app/internal/window/os_macos.m b/app/internal/window/os_macos.m
index 9ff1540..572572b 100644
--- a/app/internal/window/os_macos.m
+++ b/app/internal/window/os_macos.m
@@ -141,6 +141,7 @@ CFTypeRef gio_createWindow(CFTypeRef viewRef, const char *title, CGFloat width,
		NSView *view = (__bridge NSView *)viewRef;
		[window setContentView:view];
		[window makeFirstResponder:view];
		// [window setTabbingMode:2];
		window.releasedWhenClosed = NO;
		window.delegate = globalWindowDel;
		return (__bridge_retained CFTypeRef)window;
@@ -153,6 +154,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)];
diff --git a/app/internal/window/window.go b/app/internal/window/window.go
index d3b3012..412f542 100644
--- a/app/internal/window/window.go
+++ b/app/internal/window/window.go
@@ -58,6 +58,9 @@ type Driver interface {
	ReadClipboard()
	// WriteClipboard requests a clipboard write.
	WriteClipboard(s string)

	// Close closes the window.
	Close()
}

type windowRendezvous struct {
diff --git a/app/window.go b/app/window.go
index 482e233..8a5d51e 100644
--- a/app/window.go
+++ b/app/window.go
@@ -208,6 +208,14 @@ func (w *Window) WriteClipboard(s string) {
	})
}

// Close closes the window.  The window's event loop should exit when it
// receives system.DestroyEvent.
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()) {
-- 
2.26.2
Review patch Export thread (mbox)