awesome

Welcome to awesome bug tracking system.
Tasklist

FS#738 - awesome should close all applications before exiting

Attached to Project: awesome
Opened by Adam (g4c9z) - Tuesday, 09 March 2010, 13:55 GMT
Last edited by Uli Schlachter (psychon) - Sunday, 15 August 2010, 17:16 GMT
Task Type Feature Request
Category Lua libraries → awful
Status Closed
Assigned To Julien Danjou (jd)
Operating System Linux
Severity Medium
Priority Normal
Reported Version git/master
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 0
Private No

Details

When awesome.quit() is called, windows are forced-closed, which means if you were
editing a text file and had unsaved changes, etc., these changes would be lost.
I think it would be nicer if the window manager attempted to close each window
first, just as if the window had been closed manually, so that if the app wants
to ask the user for confirmation before exiting, it can. Then it should exit only when all windows have actually been closed.

There should probaby be another API function which does this, or at least the default "quit" option in rc.lua should do it. The code to close all windows is fairly straightforward:

for i, c in pairs(awful.client.visible(nil)) do
c:kill()
end

However, I'm not sure how to wait until all windows have been closed before calling awesome.quit().

I'm using version 3.3.4, which isn't an option in the "Reported version".
This task depends upon

Closed by  Uli Schlachter (psychon)
Sunday, 15 August 2010, 17:16 GMT
Reason for closing:  Won't implement
Additional comments about closing:  It's not the window manager's job to kill apps.
Comment by Uli Schlachter (psychon) - Tuesday, 09 March 2010, 15:17 GMT
What if I want to close awesome without having all clients killed? It's really not awesome's job to take everything down with it...

I think if you really want this, you can do it in your rc.lua. Just create a timer which fires every 0.1s and checks if there are any clients left, I guess.
Comment by Uli Schlachter (psychon) - Tuesday, 09 March 2010, 15:18 GMT
Also, why are you only killing the visible clients? I'd propose to use client.get() instead of awful.client.visible(nil).
Comment by Adam (g4c9z) - Tuesday, 09 March 2010, 15:27 GMT
"What if I want to close awesome without having all clients killed?"

Under what circumstances would that happen? Awesome manages windows; I'm proposing that all windows that were opened under its control should be closed when it exits.

Currently, this already happens - when I call awesome.quit(), all my windows that were opened go away, and I don't know how to get them back. They shouldn't go away if they don't want to.

Yes, I can and did find a way to make it happen for me, but it took too much effort. In the majority of use cases, the window manager exits when the computer is being shut down or the user is logging out, so there should at least be an API function to make such use cases nicer.
Comment by Adam (g4c9z) - Tuesday, 09 March 2010, 15:35 GMT
And yeah, you're right about client.get() being better.
Comment by scio (scio) - Tuesday, 09 March 2010, 17:57 GMT
How are you defining things that awesome launched? From a terminal that was created in awesome? By exec calls in lua? I sometimes launch daemons in awesome and want them still running when I switch to KDE.

It seems like you already know how to do what you want in your rc.lua, and the current default is what I like. Just my 2 cents.
Comment by anrxc (anrxc) - Tuesday, 09 March 2010, 20:27 GMT
...and if there is a dialog waiting a click or a prompt waiting an answer, then awesome blocks system shutdown?
Comment by Adam (g4c9z) - Tuesday, 09 March 2010, 22:38 GMT
"How are you defining things that awesome launched?"

/Windows/ that awesome launched. Daemons don't count. I believe that's what client.get() returns anyway.

"...and if there is a dialog waiting a click or a prompt waiting an answer, then awesome blocks system shutdown?"

Yes.

On Windows and Mac, this has "just worked" for years. It's the job of the window manager to make sure you don't lose any unsaved changes when you shutdown or logoff. It's not relevant that I already know how to do it; many other users want to do it too.
Comment by Julien Danjou (jd) - Wednesday, 10 March 2010, 08:56 GMT
> It's the job of the window manager to make sure you don't lose any unsaved

No. Really.
Comment by Gregor Best (farhaven) - Wednesday, 10 March 2010, 15:33 GMT
Also, the precedence is kinda wrong. It's not Awesome that is closing anything. It's your X server shutting down because something like `exec awesome` was the last thing in your xsession/xinitrc. IMHO, it'd be horrible if Awesome closed windows "it opened" (which is also wrong, the clients returned by client.get() could equally as well have existed before Awesome was started or they could have been started from another machine on the network). That'd make things like

while true; do
awesome
done

as the last thing in the xinitrc (for crash recovery/debugging/whatever you fancy) a horrible mess to use. If you _really_ want to have all clients killed when Awesome exits, it's just a matter of a few lines of Lua in your rc.lua, but I (which doesn't represent the official Awesome statement in any way) am totally against this. It's way too much interference into other apps.
Comment by Adam (g4c9z) - Wednesday, 10 March 2010, 22:14 GMT
OK, good point. But I have no objection to such behaviour not being the default. I just think it should be available for those who want it, for example in a separate API function called "closeAndQuit()". There's just no other easy way to accomplish this outside of the window manager.

"If you _really_ want to have all clients killed when Awesome exits, it's just a matter of a few lines of Lua in your rc.lua"

Not true - it's more complicated than that. My code only closes the windows. There's still the difficulty of how do you exit awesome only after all windows have actually closed. I imagine someone who knows lua better than me could do something with threads, but I'm just not interested in figuring that out if only I can benefit from it. I've now abandoned awesome, concluding that tiling window managers make sense, but usable ones with quality design don't yet exist.
Comment by anrxc (anrxc) - Wednesday, 10 March 2010, 22:20 GMT
> I've now abandoned awesome, concluding that tiling window managers make sense, but usable ones with quality design don't yet exist.

Awesome is a window manager, not a session manager, desktop manager or whatever else. X11 window managers control placement and appearance of windows, so good luck with stacking window managers, you will need it.
Comment by Matti (voneiden) - Friday, 12 March 2010, 01:25 GMT
> On Windows and Mac

Interestingly enough, I've always hated it when a computer gets stuck in log off/reboot/shutdown because of a bunch of programs asking if I really want to quit. This is worst in places such as university computers where you hit log off and rush away from the computer without realizing that firefox is crying about your session - which cancels the log off process leaving the next person with full access to your account.

In my opinion computers are supposed to do what you tell them to do --- not the opposite, that be one reason I like Awesome.
Comment by Adam (g4c9z) - Friday, 12 March 2010, 01:32 GMT
Yeah, I also hate it when apps ask you if you really want to quit. I can't understand why they can't just save a backup or something and exit. Too bad they can't do that if they aren't shut down cleanly.
Comment by Uli Schlachter (psychon) - Friday, 12 March 2010, 10:39 GMT
Those apps aren't killed, they just lose their connection to the X server, so they could save a backup.

@Adam:
Since you seem to have this code more or less working, would you mind sharing it with us? (or did I misread something?)
It could be added to awful and if someone then wants this behavior, he can call that function instead of awesome.quit().
(I wouldnt want to use such a function, but that's just me...)
Comment by Adam (g4c9z) - Friday, 12 March 2010, 14:21 GMT
Really? You'd put it in if I implemented it and shared it?

In that case, let me elaborate on what I've got working. I personally don't exit from my window manager by selecting "Quit" from the menu, but by pressing my power button to exit and shutdown. I've written 2 scripts which happen when the power button is pressed (or happened, when I was using awesome). One closes all windows, which is the code I shared above. The next asks whether all windows are closed, which is called repeatedly until it returns true. This code is essentially the same loop, which returns false if it gets in the loop and true if it doesn't:

#!/bin/bash
rm /tmp/windowOpen
awesome-client << EOF
for i, c in pairs(client.get()) do awful.util.spawn("touch /tmp/windowOpen") end
EOF

I then check whether /tmp/windowOpen exists. This works for me, but obviously it's an ugly hack and you don't want to put code like that in awesome. As I mentioned, I'm sure there's a proper way to do it all within lua code, using threads or coroutines or something. I thought someone who was involved in writing awesome could implement a proper solution in a few minutes using this as a starting point, but for me it would take a few hours for little to no gain.

"Those apps aren't killed, they just lose their connection to the X server, so they could save a backup."

That's interesting - I didn't know that. Why then do so many apps do different stuff when you click to close the window compared to when they lose connection to the X server? Even vim deletes its .swp file when you close it, but not when it loses connection to the X server (even if the file being edited has been saved). If there were a way to make all the apps behave as if you had clicked the "close" button, by installing a program separate from awesome, then I would agree that that's the program users should install. I just thought there's no way for another program to "click the close button" when there aren't even any more windows because the window manager exited.
Comment by Uli Schlachter (psychon) - Friday, 12 March 2010, 15:14 GMT
Here's the patch.
Comment by Adam (g4c9z) - Saturday, 13 March 2010, 14:25 GMT
That's great! Thanks!
Comment by Adam (g4c9z) - Friday, 02 April 2010, 16:21 GMT
I've discovered that there's a program called "wmctrl" which can close windows (and manipulate them other ways too). So perhaps it isn't a good idea to put this feature in awesome after all.

Loading...