~mil/sxmo-devel

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

[PATCH sxmo-utils] Close windows in a more "graceful" way.

Details
Message ID
<20210227222049.167177-1-greenfoo@u92.eu>
DKIM signature
pass
Download raw message
Patch: +1 -1
---
It turns out "xdotool killwindow" simply calls "XKillClient()", as you can see
on xdotool's repo ("https://github1s.com/jordansissel/xdotool") here:
"cmd_windowkill.c:40" --> "xdo.c:1845".

This doesn't give the application inside the window any chance to do anything
which, in the case of Firefox, causes the "restore session" message to pop-up
the next time it runs (but, for some reason, not always).

I found out that using "xdotool key shift+alt+c" also closes the window while
giving the application an opportunity to gracefully shut down (this happens
because wdm sends the WM_DELETE_WINDOW message before killing the X window).

WARNING: While this new command is "nicer", it also does *not* immediately close
the window (ex: in the case of Firefox, a confirmation popup appears first).
This might *not* be what the "two fingers gesture" is meant to do. If so, feel
free to ignore this patch :)

 scripts/core/sxmo_killwindow.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/scripts/core/sxmo_killwindow.sh b/scripts/core/sxmo_killwindow.sh
index f55a076..d48f306 100755
--- a/scripts/core/sxmo_killwindow.sh
+++ b/scripts/core/sxmo_killwindow.sh
@@ -4,4 +4,4 @@
# shellcheck source=scripts/core/sxmo_common.sh
. "$(dirname "$0")/sxmo_common.sh"

xdotool windowkill "$(xdotool getactivewindow)"
xdotool key shift+alt+c
-- 
2.30.1

[sxmo-utils/patches/.build.yml] build success

builds.sr.ht
Details
Message ID
<C9KNW5TGLQ9Y.17JHHLH486B1D@cirno2>
In-Reply-To
<20210227222049.167177-1-greenfoo@u92.eu> (view parent)
DKIM signature
missing
Download raw message
sxmo-utils/patches/.build.yml: SUCCESS in 21s

[Close windows in a more "graceful" way.][0] from [Fernando Ramos][1]

[0]: https://lists.sr.ht/~mil/sxmo-devel/patches/20662
[1]: greenfoo@u92.eu

✓ #442794 SUCCESS sxmo-utils/patches/.build.yml https://builds.sr.ht/~mil/job/442794
Details
Message ID
<87eeh0ej23.fsf@momi.ca>
In-Reply-To
<20210227222049.167177-1-greenfoo@u92.eu> (view parent)
DKIM signature
pass
Download raw message
> This doesn't give the application inside the window any chance to do anything
> which, in the case of Firefox, causes the "restore session" message to pop-up
> the next time it runs (but, for some reason, not always).
>
> I found out that using "xdotool key shift+alt+c" also closes the window while
> giving the application an opportunity to gracefully shut down (this happens
> because wdm sends the WM_DELETE_WINDOW message before killing the X window).

The two finger swipe should close windows in a graceful way in my
opinion and this patch looks good to me. I will wait till ~proycon
weighs in though to see if I am missing a use case.

> WARNING: While this new command is "nicer", it also does *not* immediately close
> the window (ex: in the case of Firefox, a confirmation popup appears first).
> This might *not* be what the "two fingers gesture" is meant to do. If so, feel
> free to ignore this patch :)

I think if users don't like that behavior, they can disable "warn me if
I am closing multiple tabs" in firefox.

Thanks!
Details
Message ID
<20210228100028.bxgus5soc5paboh5@worker.anaproy.lxd>
In-Reply-To
<87eeh0ej23.fsf@momi.ca> (view parent)
DKIM signature
missing
Download raw message
On 21-02-28 02:40, Anjandev Momi wrote:
> > This doesn't give the application inside the window any chance to do anything
> > which, in the case of Firefox, causes the "restore session" message to pop-up
> > the next time it runs (but, for some reason, not always).
> >
> > I found out that using "xdotool key shift+alt+c" also closes the window while
> > giving the application an opportunity to gracefully shut down (this happens
> > because wdm sends the WM_DELETE_WINDOW message before killing the X window).
>
> The two finger swipe should close windows in a graceful way in my
> opinion and this patch looks good to me. I will wait till ~proycon
> weighs in though to see if I am missing a use case.

I agree! This patch looks like an improvement to me.

--

Maarten van Gompel (proycon)
https://proycon.anaproy.nl
Details
Message ID
<20210228155147.GA29604@mail.hallyn.com>
In-Reply-To
<87eeh0ej23.fsf@momi.ca> (view parent)
DKIM signature
missing
Download raw message
On Sun, Feb 28, 2021 at 02:40:52AM -0500, Anjandev Momi wrote:
> > This doesn't give the application inside the window any chance to do anything
> > which, in the case of Firefox, causes the "restore session" message to pop-up
> > the next time it runs (but, for some reason, not always).
> >
> > I found out that using "xdotool key shift+alt+c" also closes the window while
> > giving the application an opportunity to gracefully shut down (this happens
> > because wdm sends the WM_DELETE_WINDOW message before killing the X window).
> 
> The two finger swipe should close windows in a graceful way in my
> opinion and this patch looks good to me. I will wait till ~proycon
> weighs in though to see if I am missing a use case.
> 
> > WARNING: While this new command is "nicer", it also does *not* immediately close
> > the window (ex: in the case of Firefox, a confirmation popup appears first).
> > This might *not* be what the "two fingers gesture" is meant to do. If so, feel
> > free to ignore this patch :)
> 
> I think if users don't like that behavior, they can disable "warn me if
> I am closing multiple tabs" in firefox.

Why not get the PID and send it a sigterm, then after 2s kill it harder?
Details
Message ID
<0781508a-f99c-48ba-9eae-80e28459cb40@www.fastmail.com>
In-Reply-To
<20210228155147.GA29604@mail.hallyn.com> (view parent)
DKIM signature
pass
Download raw message
On Sun, Feb 28, 2021, at 9:51 AM, Serge E. Hallyn wrote:
> On Sun, Feb 28, 2021 at 02:40:52AM -0500, Anjandev Momi wrote:
> > > This doesn't give the application inside the window any chance to do anything
> > > which, in the case of Firefox, causes the "restore session" message to pop-up
> > > the next time it runs (but, for some reason, not always).
> > >

The original intent behind the force killwindow was that there are
certain applications that will occasionally freeze up and don't obey
SIGTERM / Shft-Alt-C. I've seen this happen with mpv in the past as
well as firefox on musl on the Pinephone. I guess I wanted to err on
the side of "always obeying the user" since normal killing occasionally
can fail.

Serge's idea isn't bad about TERM and then KILL 2s later.

I'm also wondering about just adding a separate binding rather then
eliminating the functionality. Force-killing is occasionally helpful
(or regularly if you like the brute force approach :).

We could do:
- 3 taps vol down force kill
- 4 taps vol down (or hold) for graceful kill

And:
- 2 finger swipe down graceful kill
- 3 finger swipe down forceful kill

Just an idea.

Miles
Fernando Ramos
Details
Message ID
<YDvdDwMBZq/6Xx/d@zacax395.localdomain>
In-Reply-To
<20210228155147.GA29604@mail.hallyn.com> (view parent)
DKIM signature
pass
Download raw message
On 21/02/28 09:51AM, Serge E. Hallyn wrote:
> 
> Why not get the PID and send it a sigterm, then after 2s kill it harder?

That is (more or less) what happens when you use the "Shift+Alt+C" combo,
except that "Shift+Alt+C" could be considered a more general solution because,
instead of always using SIGTERM, it might trigger a different action that is
better suited for the underlying process.

In particular, this is what happens when you use "Shift+Alt+C":

  1. DWM sends the "WM_DELETE_WINDOW" to the X server, who forwards it to the X
     client.

  2. The X client takes care of the message "in the best possible way" (which
     might be different for each type of process).
     For example, the "st" terminal, who uses xlib directly, calls "ttyhangup()"
     and then "exit()"; but Firefox, who uses GTK, probably registers a callback
     which is the one that triggers the "close confirmation pop-up".
     I guess (but I haven't confirmed) that other clients that use GTK/Qt and
     don't register a callback will simply receive a SIGKILL from Xlib.

  3. *BUT* if the client does not have a response to "WM_DELETE_WINDOW", DWM
     will then directly call "XkillClient()", which tells the client to
     terminate the underlying process "the hard way".
Details
Message ID
<20210228231157.GA2077@mail.hallyn.com>
In-Reply-To
<YDvdDwMBZq/6Xx/d@zacax395.localdomain> (view parent)
DKIM signature
missing
Download raw message
On Sun, Feb 28, 2021 at 07:12:31PM +0100, Fernando Ramos wrote:
> On 21/02/28 09:51AM, Serge E. Hallyn wrote:
> > 
> > Why not get the PID and send it a sigterm, then after 2s kill it harder?
> 
> That is (more or less) what happens when you use the "Shift+Alt+C" combo,
> except that "Shift+Alt+C" could be considered a more general solution because,
> instead of always using SIGTERM, it might trigger a different action that is
> better suited for the underlying process.
> 
> In particular, this is what happens when you use "Shift+Alt+C":
> 
>   1. DWM sends the "WM_DELETE_WINDOW" to the X server, who forwards it to the X
>      client.
> 
>   2. The X client takes care of the message "in the best possible way" (which
>      might be different for each type of process).
>      For example, the "st" terminal, who uses xlib directly, calls "ttyhangup()"
>      and then "exit()"; but Firefox, who uses GTK, probably registers a callback
>      which is the one that triggers the "close confirmation pop-up".
>      I guess (but I haven't confirmed) that other clients that use GTK/Qt and
>      don't register a callback will simply receive a SIGKILL from Xlib.

Whoa

I would not want a popup in response to a swipe gesture to make a window
go away.  When I think of what an application can do when I've asked it to
shut down, that's things like close your db cleanly, save what you haven't.
Not nag the user.

What even is that.

>   3. *BUT* if the client does not have a response to "WM_DELETE_WINDOW", DWM
>      will then directly call "XkillClient()", which tells the client to
>      terminate the underlying process "the hard way".
Details
Message ID
<069ff023-f00d-4b89-a62a-94eb2e3076da@www.fastmail.com>
In-Reply-To
<20210228231157.GA2077@mail.hallyn.com> (view parent)
DKIM signature
pass
Download raw message
> I would not want a popup in response to a swipe gesture to make a window
> go away.

But that is exactly what some applications might decide to do when
receiving a "SIGTERM".

The only difference between directly sending a SIGTERM and using
the WM_DELETE_WINDOW event is that you are using a different
callback (one that is more likely to have been registered by the
underlying toolkit the application is linked against) *and* that you
don't have to figure out the process ID (from the several that the
application might have created, such as in the case of Firefox).


> When I think of what an application can do when I've asked it to
> shut down, that's things like close your db cleanly, save what you haven't.
> Not nag the user.

You can either kill the application at the OS level (SIGKILL) or ask it
to gracefully shutdown (SIGTERM or WM_DELETE_WINDOW), but there
is no way  to tell the application something like "gracefully shutdown
but don't show me any window", that is for each application to decide.

Each application will do a different thing.

For example, "st" will close the terminal process and exit immediately,
while Firefox will warn you when you are about to close many tabs (note
this, in the case of Firefox, as Anjandev noted on the first email of
this thread, you can disable this behavior so that the pop up window
will not be presented in the future).

If we don't really want to show any window (but we still want to give
each application the opportunity to gracefully shutdown), one option
would be to have xsmo include modified configuration files for each
of the shipped applications that instruct it not to show any pop up
window when closing... but this would obviously only work when the
application includes such a configuration option.


> What even is that.

The WM_DELETE_WINDOW event is generated by DWM when the
user decides to close the window. You can check it out here:

    https://git.suckless.org/dwm/file/dwm.c.html#l1003

This event will be forwarded by the X server to the X client, which
will understand that it means "shutdown the application grecefully"
and do whatever it considers is the best option (send a SIGTERM
to the underlying process, call something else to initiate an
ordered shutdown, etc...).

That's why I said this is a "more general" approach to the SIGTERM
option.
Fernando
Details
Message ID
<fd5a9090-1c2b-4847-b2e2-d789f4b8a5e9@www.fastmail.com>
In-Reply-To
<069ff023-f00d-4b89-a62a-94eb2e3076da@www.fastmail.com> (view parent)
DKIM signature
pass
Download raw message
On Sun, Feb 28, 2021, Miles Alan Wrote:

> We could do:
> - 3 taps vol down force kill
> - 4 taps vol down (or hold) for graceful kill
> 
> And:
> - 2 finger swipe down graceful kill
> - 3 finger swipe down forceful kill

I also agree that this would be the perfect solution :)
Details
Message ID
<20210301142656.GA10739@mail.hallyn.com>
In-Reply-To
<069ff023-f00d-4b89-a62a-94eb2e3076da@www.fastmail.com> (view parent)
DKIM signature
missing
Download raw message
On Mon, Mar 01, 2021 at 09:25:12AM +0100, Fernando wrote:
> > I would not want a popup in response to a swipe gesture to make a window
> > go away.
> 
> But that is exactly what some applications might decide to do when
> receiving a "SIGTERM".
> 
> The only difference between directly sending a SIGTERM and using
> the WM_DELETE_WINDOW event is that you are using a different
> callback (one that is more likely to have been registered by the
> underlying toolkit the application is linked against) *and* that you

Right but the *are* different callbacks.  And while I don't know what
the cool kids do these days, I would think I'd have treated them
differently "back in the day" - you get a sigterm, you don't nag the
user.

But, I'm sure you're right.  So yeah, Miles' solution sounds best.
Details
Message ID
<20210301201635.7o4ahzvan7ln4b64@worker.anaproy.lxd>
In-Reply-To
<0781508a-f99c-48ba-9eae-80e28459cb40@www.fastmail.com> (view parent)
DKIM signature
missing
Download raw message
On 21-02-28 10:07, Miles Alan wrote:
> I'm also wondering about just adding a separate binding rather then
> eliminating the functionality. Force-killing is occasionally helpful
> (or regularly if you like the brute force approach :).
>
> We could do:
> - 3 taps vol down force kill
> - 4 taps vol down (or hold) for graceful kill
>
> And:
> - 2 finger swipe down graceful kill
> - 3 finger swipe down forceful kill
>
> Just an idea.

I like this idea yes, it's probably better to explicit than implicit.
And the old 2-finger swipe can do the graceful thing. Let's implement
this.

--

Maarten van Gompel (proycon)
https://proycon.anaproy.nl
Reply to thread Export thread (mbox)