~eliasnaur/gio

7 5

programmatically closing a window

Sebastien Binet
Details
Message ID
<6usX8KrMNH3yaH3bfcaMSxmFREmKp9ouSQ2zg5D7cu6DLOHEWb39qcMN7O-vyq1qkzoAIO9zTIrV1R_wO42eNHJZwil3XzVwq6P-t3tLCSU=@sbinet.org>
DKIM signature
missing
Download raw message
hi there,

I probably missed something but I didn't figure out a way to programmatically close an *app.Window.

https://play.golang.org/p/kP-E3MV4VS8

The program above will launch a new "bouncing square" window whenever one hits "enter", and will exit the program when Esc or Q are pressed.

but I'd like the following behaviour: when "enter" is pressed, the current "win" window is closed (and disappears) and a new one is created anew.

is there a way to programmatically send a "system.DestroyEvent" to the current window?

thanks,
-s
Details
Message ID
<CAE_4BPBtqH3-7ObFabWpbMFtETUkwJnbL6P+YesYmujNzvXDhA@mail.gmail.com>
In-Reply-To
<6usX8KrMNH3yaH3bfcaMSxmFREmKp9ouSQ2zg5D7cu6DLOHEWb39qcMN7O-vyq1qkzoAIO9zTIrV1R_wO42eNHJZwil3XzVwq6P-t3tLCSU=@sbinet.org> (view parent)
DKIM signature
missing
Download raw message
A patch[1] was merged just this morning adding app.Window.Close().
Update to the latest Gio and give that a shot.

-- Larry Clapp

[1] from me! :)

On Thu, Jun 18, 2020 at 4:29 PM Sebastien Binet <s@sbinet.org> wrote:
>
> hi there,
>
> I probably missed something but I didn't figure out a way to programmatically close an *app.Window.
>
> https://play.golang.org/p/kP-E3MV4VS8
>
> The program above will launch a new "bouncing square" window whenever one hits "enter", and will exit the program when Esc or Q are pressed.
>
> but I'd like the following behaviour: when "enter" is pressed, the current "win" window is closed (and disappears) and a new one is created anew.
>
> is there a way to programmatically send a "system.DestroyEvent" to the current window?
>
> thanks,
> -s
Sebastien Binet
Details
Message ID
<d_vdqUFs4G3mDjlGLRE5Glh_cw8RfZ8rMh0OuzcNlB13TZw244jDmBoe9pdorr9RUH5rPd9fVrky9R3K-FRHjJCtxiRE91eZ-N435vglgVs=@sbinet.org>
In-Reply-To
<CAE_4BPBtqH3-7ObFabWpbMFtETUkwJnbL6P+YesYmujNzvXDhA@mail.gmail.com> (view parent)
DKIM signature
missing
Download raw message
Hi Larry,


‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
On Thursday, June 18, 2020 11:09 PM, Larry Clapp <larry@theclapp.org> wrote:

> A patch[1] was merged just this morning adding app.Window.Close().
> Update to the latest Gio and give that a shot.

thanks.
I actually make use of this new method in my program.
but perhaps I am holding it wrong?
(I defer win.Close() and return when "enter" is pressed.)

-s
Sebastien Binet
Details
Message ID
<PBsLKxyRAhStpy2DaQnx7Clwy9ktHVUucCnR13Ba0B5gwo6gg-C9wFM7sQpelNXobbCj-KBZcxLxhty1XDu-nsyPLGLEnDtB_AJia0a6l8w=@sbinet.org>
In-Reply-To
<d_vdqUFs4G3mDjlGLRE5Glh_cw8RfZ8rMh0OuzcNlB13TZw244jDmBoe9pdorr9RUH5rPd9fVrky9R3K-FRHjJCtxiRE91eZ-N435vglgVs=@sbinet.org> (view parent)
DKIM signature
missing
Download raw message
oh! I see, it's only implemented on macOS :)




‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
On Thursday, June 18, 2020 11:24 PM, Sebastien Binet <s@sbinet.org> wrote:

> Hi Larry,
>
> ‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
> On Thursday, June 18, 2020 11:09 PM, Larry Clapp larry@theclapp.org wrote:
>
> > A patch[1] was merged just this morning adding app.Window.Close().
> > Update to the latest Gio and give that a shot.
>
> thanks.
> I actually make use of this new method in my program.
> but perhaps I am holding it wrong?
> (I defer win.Close() and return when "enter" is pressed.)
>
> -s
Details
Message ID
<AV1kRoz9pNVz0vqBUvHeA0ZgxPa1wVJDYfwwrA2LdUVn_jqjH_FLBkY_haXiTuTSyXSD7jBFEwxTzoEBFy2fFiPs77ewRP0qyWr0kJ6rbPg=@sbinet.org>
In-Reply-To
<PBsLKxyRAhStpy2DaQnx7Clwy9ktHVUucCnR13Ba0B5gwo6gg-C9wFM7sQpelNXobbCj-KBZcxLxhty1XDu-nsyPLGLEnDtB_AJia0a6l8w=@sbinet.org> (view parent)
DKIM signature
missing
Download raw message
Patch: +12 -3




‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
On Friday, June 19, 2020 10:04 AM, Sebastien Binet <dev@sbinet.org> wrote:

> oh! I see, it's only implemented on macOS :)


not an X11 expert -by any stretch of the imagination- but here is what I could come up with:

diff --git a/app/internal/window/os_x11.go b/app/internal/window/os_x11.go
index 4f6706a..4c14efe 100644
--- a/app/internal/window/os_x11.go
+++ b/app/internal/window/os_x11.go
@@ -71,7 +71,8 @@ type x11Window struct {
       notify struct {
               read, write int
       }
       dead bool
       closed bool
       dead   bool

       mu        sync.Mutex
       animating bool
@@ -110,8 +111,16 @@ func (w *x11Window) WriteClipboard(s string) {

func (w *x11Window) ShowTextInput(show bool) {}

// Close the window. Not implemented for X11.
func (w *x11Window) Close() {}
// Close the window.
func (w *x11Window) Close() {
       w.mu.Lock()
       defer w.mu.Unlock()
       if w.closed {
               return
       }
       w.closed = true
       C.XDestroyWindow(w.x, w.xw)
}

var x11OneByte = make([]byte, 1)


any one care to foolproof this?

s
Details
Message ID
<C3KZZUEYDEMQ.Y0CK5DHSN1IC@themachine>
In-Reply-To
<AV1kRoz9pNVz0vqBUvHeA0ZgxPa1wVJDYfwwrA2LdUVn_jqjH_FLBkY_haXiTuTSyXSD7jBFEwxTzoEBFy2fFiPs77ewRP0qyWr0kJ6rbPg=@sbinet.org> (view parent)
DKIM signature
pass
Download raw message
On Fri Jun 19, 2020 at 09:55, Sebastien Binet wrote:
>
>
>
>
>
> ‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
> On Friday, June 19, 2020 10:04 AM, Sebastien Binet <dev@sbinet.org> wrote:
>
> > oh! I see, it's only implemented on macOS :)
>
>
> not an X11 expert -by any stretch of the imagination- but here is what I could come up with:
>
> diff --git a/app/internal/window/os_x11.go b/app/internal/window/os_x11.go
> index 4f6706a..4c14efe 100644
> --- a/app/internal/window/os_x11.go
> +++ b/app/internal/window/os_x11.go
> @@ -71,7 +71,8 @@ type x11Window struct {
>         notify struct {
>                 read, write int
>         }
> -       dead bool
> +       closed bool
> +       dead   bool
>
>         mu        sync.Mutex
>         animating bool
> @@ -110,8 +111,16 @@ func (w *x11Window) WriteClipboard(s string) {
>
>  func (w *x11Window) ShowTextInput(show bool) {}
>
> -// Close the window. Not implemented for X11.
> -func (w *x11Window) Close() {}
> +// Close the window.
> +func (w *x11Window) Close() {
> +       w.mu.Lock()
> +       defer w.mu.Unlock()
> +       if w.closed {
> +               return
> +       }
> +       w.closed = true
> +       C.XDestroyWindow(w.x, w.xw)

XDestroyWindow destroys the window immediately, leaving the window reference
dead. Isn't there a way in X11 for asking the window to close itself? I can't
imagine pressing the "X" button in X11 calls XDestroyWindow.

-- elias
Details
Message ID
<EX46CQ.N8GM7ZLSXTR53@sweatyballs.es>
In-Reply-To
<C3KZZUEYDEMQ.Y0CK5DHSN1IC@themachine> (view parent)
DKIM signature
missing
Download raw message

On Fri, 19 Jun, 2020 at 12:14, Elias Naur <mail@eliasnaur.com> wrote:
> On Fri Jun 19, 2020 at 09:55, Sebastien Binet wrote:
>> 
>> 
>> 
>> 
>> 
>>  ‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
>>  On Friday, June 19, 2020 10:04 AM, Sebastien Binet <dev@sbinet.org> 
>> wrote:
>> 
>>  > oh! I see, it's only implemented on macOS :)
>> 
>> 
>>  not an X11 expert -by any stretch of the imagination- but here is 
>> what I could come up with:
>> 
>>  diff --git a/app/internal/window/os_x11.go 
>> b/app/internal/window/os_x11.go
>>  index 4f6706a..4c14efe 100644
>>  --- a/app/internal/window/os_x11.go
>>  +++ b/app/internal/window/os_x11.go
>>  @@ -71,7 +71,8 @@ type x11Window struct {
>>          notify struct {
>>                  read, write int
>>          }
>>  -       dead bool
>>  +       closed bool
>>  +       dead   bool
>> 
>>          mu        sync.Mutex
>>          animating bool
>>  @@ -110,8 +111,16 @@ func (w *x11Window) WriteClipboard(s string) {
>> 
>>   func (w *x11Window) ShowTextInput(show bool) {}
>> 
>>  -// Close the window. Not implemented for X11.
>>  -func (w *x11Window) Close() {}
>>  +// Close the window.
>>  +func (w *x11Window) Close() {
>>  +       w.mu.Lock()
>>  +       defer w.mu.Unlock()
>>  +       if w.closed {
>>  +               return
>>  +       }
>>  +       w.closed = true
>>  +       C.XDestroyWindow(w.x, w.xw)
> 
> XDestroyWindow destroys the window immediately, leaving the window 
> reference
> dead. Isn't there a way in X11 for asking the window to close itself? 
> I can't
> imagine pressing the "X" button in X11 calls XDestroyWindow.
> 

Perhaps XUnmapWindow first? See here:
https://gitlab.gnome.org/GNOME/mutter/-/blob/master/src/x11/meta-x11-display.c#L161

> -- elias
Details
Message ID
<OrfXY6NrBZjs5xWMonz6zuhQ4ULqnsUAWjUAr5iQ-giT4WOOLxMAhNRJVkEv0pj8UGWg6WElZrSgOopzmvTC275sB8nGHS9u2z6blk5UXzw=@sbinet.org>
In-Reply-To
<EX46CQ.N8GM7ZLSXTR53@sweatyballs.es> (view parent)
DKIM signature
missing
Download raw message
Patch: +6 -2




‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
On Friday, June 19, 2020 12:24 PM, Jason <sourcehut@sweatyballs.es> wrote:

>
>
> On Fri, 19 Jun, 2020 at 12:14, Elias Naurmail@eliasnaur.com wrote:
>
> > On Fri Jun 19, 2020 at 09:55, Sebastien Binet wrote:
> >
> > > ‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
> > > On Friday, June 19, 2020 10:04 AM, Sebastien Binet dev@sbinet.org
> > > wrote:
> > >
> > > > oh! I see, it's only implemented on macOS :)
> > >
> > > not an X11 expert -by any stretch of the imagination- but here is
> > > what I could come up with:
> > > diff --git a/app/internal/window/os_x11.go
> > > b/app/internal/window/os_x11.go
> > > index 4f6706a..4c14efe 100644
> > > --- a/app/internal/window/os_x11.go
> > > +++ b/app/internal/window/os_x11.go
> > > @@ -71,7 +71,8 @@ type x11Window struct {
> > > notify struct {
> > > read, write int
> > > }
> > >
> > > -         dead bool
> > >
> > >
> > >
> > > -         closed bool
> > >
> > >
> > > -         dead   bool
> > >
> > >           mu        sync.Mutex
> > >           animating bool
> > >
> > >
> > >
> > > @@ -110,8 +111,16 @@ func (w *x11Window) WriteClipboard(s string) {
> > > func (w *x11Window) ShowTextInput(show bool) {}
> > > -// Close the window. Not implemented for X11.
> > > -func (w *x11Window) Close() {}
> > > +// Close the window.
> > > +func (w *x11Window) Close() {
> > >
> > > -         w.mu.Lock()
> > >
> > >
> > > -         defer w.mu.Unlock()
> > >
> > >
> > > -         if w.closed {
> > >
> > >
> > > -                 return
> > >
> > >
> > > -         }
> > >
> > >
> > > -         w.closed = true
> > >
> > >
> > > -         C.XDestroyWindow(w.x, w.xw)
> > >
> > >
> >
> > XDestroyWindow destroys the window immediately, leaving the window
> > reference
> > dead. Isn't there a way in X11 for asking the window to close itself?
> > I can't
> > imagine pressing the "X" button in X11 calls XDestroyWindow.
>
> Perhaps XUnmapWindow first? See here:
> https://gitlab.gnome.org/GNOME/mutter/-/blob/master/src/x11/meta-x11-display.c#L161

yes. that worked as well.

diff --git a/app/internal/window/os_x11.go b/app/internal/window/os_x11.go
index 4f6706a..7a9452e 100644
--- a/app/internal/window/os_x11.go
+++ b/app/internal/window/os_x11.go
@@ -110,8 +110,12 @@ func (w *x11Window) WriteClipboard(s string) {

func (w *x11Window) ShowTextInput(show bool) {}

// Close the window. Not implemented for X11.
func (w *x11Window) Close() {}
// Close the window.
func (w *x11Window) Close() {
       w.mu.Lock()
       C.XUnmapWindow(w.x, w.xw)
       w.mu.Unlock()
}

var x11OneByte = make([]byte, 1)


I'll send a patch (I'll try) w/ examples updated w/ calls to win.Close.

thanks,
s
Export thread (mbox)