tags:

views:

85

answers:

1

I have an x11 display with a windowmanager (sadly not a specific one, could be twm, dtwm, mwm, metacity …) , myApp and other applications with windows. I want to close the display if the other applications are closed and myApp is the only one with windows on the display. I do know the windows of myApp, but how do I distinguish between the windows of the windowmanger and of the other applications.

I’m currently polling with xwininfo -tree -root -children and comparing this to what I’m expecting, but this only works in a ‘well defined’ environment.

It seems that many of the above mentioned windowmanager don’t support EWMH.

+1  A: 

There isn't going to be a completely non-hacky way.

The ICCCM recommends identifying toplevel windows (as opposed in particular to WM frames) by looking for the WM_STATE property. So you could distinguish application windows with that. However, when the WM reparents the window into a frame it'll get tricky to find the app window inside the frame window. You'd have to implement a little program to do something like xwininfo -tree but only check for windows with WM_STATE set.

A relatively nice solution would be to use libwnck, or one of the tools based on it (wmctrl, devil's pie). However, this requires an EWMH window manager (which includes anything remotely modern or sane, but it sounds like you are dealing with some really old curmudgeonly stuff). The advantage of these tools is that they use EWMH to identify application windows and even the semantic type of those application windows (dialog, etc.).

Also, libwnck removes the need to poll, it can just watch for changes in the toplevel window list.

Havoc P
Thanks for the answer. I thought that it would be like that but hoped that there could be some magic/voodoo to help me. I ended up with having a editable list of allowed/default windows ("mwm,metacity..."). The xwininfo part will be replaced by a seperate custom c module (still polling) . Not nice, but working and adaptable.
ts