开发者

X11, how to detect I’m the last window/application on the display

I have an x11 display wi开发者_开发技巧th 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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜