Reputation: 21
I'd like to write a function that closes all open applications before quitting. This is to make sure I haven't forgotten to save a modified file.
If I use the Super+Shift+q shortcut, awesome forces all applications to close and I lose any unsaved changes.
Here's what I was able to do:
awful.spawn.easy_async('/home/fabrice/.config/rofi/rofi-query.sh "Eteindre ? "',
function(_, _, _, exitcode)
if exitcode == 0 then
for _, c in ipairs(client.get()) do
c:kill()
end
end
-- Wait for all windows to close
-- Then exit AwesomeWM
end)
What I can't do is wait until all the windows are closed before leaving. In fact, if a modified file has not been saved, the application asks me if I want to save it before closing the application. Only after I've answered all the applications for unsaved files would I want to quit awesome.
I tried to handle the "unmanage" signal (because it is the signal that is emitted when a window is closed) like this:
client.connect_signal("unmanage",
function ()
if client.instances() == 0 then
awesome.quit()
end
end)
but I'm not leaving awesome. What I understand is that when the unmanage signal is processed, there is always a window open.
Is there a signal that is called after all the windows are closed? Or is there another way to close all windows and then exit awesome?
Upvotes: 1
Views: 124
Reputation: 21
I found the solution :
awful.spawn.easy_async('/home/fabrice/.config/rofi/rofi-query.sh "Eteindre ?"',
function(_, _, _, exitcode)
if exitcode == 0 then
local nb = 0
for _, c in ipairs(client.get()) do
nb = nb + 1
end
if nb == 0 then
awesome.quit()
else
client.connect_signal("unmanage",
function ()
local nb = 0
for _, c in ipairs(client.get()) do
nb = nb + 1
end
if nb == 0 then
awesome.quit()
end
end)
for _, c in ipairs(client.get()) do
c:kill()
end
end
end
end)
The mistake I was making was to use client.instances() to get the number of open windows.
Here's how it works:
If no window is open then I immediately quit awesome.
Otherwise, I define a function to handle the signal (unmanage) that is emitted when windows are closed, and then request that all windows be closed.
In the unmanage signal function, I count the number of windows still open and when no window is open, I quit awesome.
Upvotes: 1