title: Intercept WM_DELETE_WINDOW on X11?
body: <p>I'd like to intercept the <code>WM_DELETE_WINDOW</code> message that is posted to a certain selection of windows that an application I'm writing (<a href="http://alltray.trausch.us/" rel="noreferrer">AllTray</a>), so that I can act on it instead of the application receiving it.  I'm currently looking at trying this at the GDK level <a href="http://library.gnome.org/devel/gdk/unstable/GdkDisplay.html#gdk-display-add-client-message-filter" rel="noreferrer">via <code>gdk_display_add_client_message_filter</code></a> if possible, but I'd be happy with an Xlib solution if there is one as well; it <em>seems</em> to be possible, but I just don't seem to be understanding how I am to do it successfully.</p>
  
  <p>Currently, I have two programs (written in C) that I am trying to use to get this figured out, <a href="http://pastebin.com/f671ee287" rel="noreferrer">the first one</a> does nothing but create a window and register that it knows about <code>WM_DELETE_WINDOW</code>, and <a href="http://pastebin.com/f6b158f6" rel="noreferrer">the second one</a> attempts to catch that message, but seems to fail in doing so; it appears to do precisely nothing.  Am I understanding the documentation wrong on this, or is there something additional that I need to be doing (or do I need to avoid using GDK entirely for this)?</p>
  
  <p>The background is this:  Prior to my re-write of AllTray, the way it would do things appears to be to try to intercept a mouse-click on the X button itself.  For some window managers, this worked properly, for others it didn't work at all, and for others, the user had to configure it manually and instruct AllTray where the button for closing the window was.  What I am looking for is a solution that doesn't involve a <code>LD_LIBRARY_PRELOAD</code> and will work for any window manager/application combination that conforms to the current standards and sends a <code>WM_DELETE_WINDOW</code> ClientMessage when the window is closed.</p>
  
  <p><strong>UPDATE</strong>:  I'm still looking for an answer.  The route that I am taking at the moment is to try to reparent the window and manage it myself, but I just cannot make it work.  Upon reparenting, I don't seem to be able to get it back in any way.  I may be missing something very fundamental, but I can't figure out how to actually make it appear it my own window again, to bring it back on the screen.</p>
  
  <p><strong>UPDATE 2</strong>:  Alright, so I've hit another brick wall.  The X server documentation says to set the StructureNotifyMask on the window's event mask to receive both MapNotify and ReparentNotify events.  I'd be interested in receiving either.  My current thinking was to create a window that served just as an event receiver, and then when I get events for interesting things, act on them by creating and reparenting.  However, this simply doesn't seem to be working.  The only events I actually receive are PropertyNotify events.  So, this route doesn't seem to be doing very much good, either.</p>