~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
2 2

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

Details
Message ID
<20200615151235.24279-1-larry@theclapp.org>
DKIM signature
missing
Download raw message
Patch: +23 -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  | 5 +++++
 app/internal/window/window.go   | 3 +++
 app/window.go                   | 8 ++++++++
 4 files changed, 23 insertions(+)

Change since v1: Removed

  // [window setTabbingMode:2];

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..bd7ce28 100644
--- a/app/internal/window/os_macos.m
+++ b/app/internal/window/os_macos.m
@@ -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)];
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
Details
Message ID
<C3IE8J36YMF6.VXFN1X6CG9C@themachine>
In-Reply-To
<20200615151235.24279-1-larry@theclapp.org> (view parent)
DKIM signature
pass
Download raw message
Patch subject is a bit vague. How about:

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

?


On Mon Jun 15, 2020 at 11:12, Larry Clapp wrote:
> 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);

s/viewRef/windowRef/

>  */
>  import "C"
>  
> @@ -131,6 +132,12 @@ func (w *window) SetAnimating(anim bool) {
>  	}
>  }
>  
> +func (w *window) Close() {
> +	runOnMain(func() {

Check w.view != 0 before using w.window. The window may have been closed
during the switch to the main thread.

> +		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..bd7ce28 100644
> --- a/app/internal/window/os_macos.m
> +++ b/app/internal/window/os_macos.m
> @@ -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)];
> 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()

Will the other platforms still build when this patch is in?

>  }
>  
>  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.

I'm a fan of reusing the method name if possible (also one space after period):

// Close the window. The window's event loop...

> +func (w *Window) Close() {
> +	w.driverDo(func() {
> +		w.driver.Close()
> +	})
> +}
> +
Details
Message ID
<CAE_4BPCcQgBE=GarSrS6FGDdU0nciEH8x2sp=dw4hUgdyMtZ9A@mail.gmail.com>
In-Reply-To
<C3IE8J36YMF6.VXFN1X6CG9C@themachine> (view parent)
DKIM signature
missing
Download raw message
All comments addressed in the next version.

On Tue, Jun 16, 2020 at 4:46 AM Elias Naur <mail@eliasnaur.com> wrote:
> Will the other platforms still build when this patch is in?

They should in v3, though everything but macOS is stubbed out.

> (also one space after period)

D'oh!  Sorry, I thought I caught all those.

-- L
Review patch Export thread (mbox)