Graceful logout in dwm

5

0

I want dwm to close all windows gracefully when I press quit hotkey. I like Unity behaviour: it displays list of windows denying logout (for example, editors with unsaved changes) and do not logout before all issues are resolved and applications are closed. By default, dwm just end X session and all running applications are killed.

I was thinking about writing a script that will retrieve list of all windows, gracefully close them and wait for their processes to finish. But I even don't know how to close windows. The only way I know is using wmctrl, and this utility doesn't work with dwm.

Riateche

Posted 2012-06-03T09:42:06.643

Reputation: 81

since i have experience working with DWM's code, but this isn't stackoverflow so i must stay in context: you'll have to have a wrapper around dwm, that's the best you can do without having to rewrite code. I use a script that sends sigterm to everything except dwm running underneath it, and if (only if) everything was also killed, which is not the case if a program pops up a "save your document" box, then kills dwm as well (if not/no kill).You can modify such a script to do what you want however wrapping it without going into codes the real challenge. (but like i said this isnt stackoverflow) – osirisgothra – 2014-05-05T11:05:01.417

btw you can use a combination of ps, kill, grep and sed, to get the info you need about your processes when in a script, of course you can find the correct dwm instance via the DISPLAY variable – osirisgothra – 2014-05-05T11:11:10.707

Answers

0

You may need to start dwm from within a X11 session manager


Here is one way to do it with Gnome Display Manager (GDM)

Add the following to /usr/share/xsessions/dwm.desktop

 [Desktop Entry]
 Encoding=UTF-8
 Name=dwm
 Comment=This session starts dwm
 Exec=/usr/local/bin/dwm-start
 Type=Application

Create a new file at /usr/local/bin/dwm-start with 755 permissions.

 #!/bin/sh
 # You can add other programs to set the background, add autoloading
 # and add autoload for USB and such here 
 # Make sure you start dwm last as it never returns control to this script
 exec /usr/local/bin/dwm > /dev/null

If GDM is properly configured on your computer, you should see a new dwm entry in the session menu on the log-in screen.

More dwm tweaks, including setup for hibernate/shutdown are here.

Jeremy W

Posted 2012-06-03T09:42:06.643

Reputation: 3 529

I'm starting dwm from lightdm (default login manager in Ubuntu). When dwm is finished, all applications are killed. I don't see that gdm or lightdm provide any functionality for asking about am I really want these applications to be killed. – Riateche – 2012-06-10T05:40:15.103

@Riateche if you are starting this in lightdm already .. have you tried gnome-session-quit --logout-dialog? I'm not sure if it will be valid without gnome/unity desktop but it's worth trying. – Jeremy W – 2012-06-11T18:57:54.860

gnome-session-quit works only if gnome-session was started. dwm works not well with gnome-session. – Riateche – 2012-06-11T20:33:42.640

1@Riateche mod+Shift+Q should just kill dwm ... not X. Is this not the case for you? – Jeremy W – 2012-06-11T21:10:59.507

There are two options. First: session command is directly set to dwm. In this case mod+shift+q kills dwm, X and all gui applications. Second: session command is set to script that restarts dwm in infinite loop. In this case mod+shift+q restarts dwm without killing applications, and killall dwm kills dwm, X and all gui applications. I'm currently using the second type of setup. – Riateche – 2012-06-12T07:09:05.053