I am trying to find a way to detect the event of a window (any window) being opened in Ubuntu 16.04
I would like to be able to detect the "window open" event and check if the opened window was my sought window and thereafter run a bash script or a C/C++ function.
So far I've found that I can use wmctrl -l
to find which windows are already opened. I could use this command and perhaps grep
to find if my sought window is opened and then act on this information.
I'd prefer not to poll, as I'd not want the application to stand idle when the window opens. The action should be as "instantaneous" as possible.
Is there an event or signal I could listen for to achieve this? From the kernel, window manager (Compiz) or maybe some log file that changes?
EDIT: To clarify, I have an application (not under my control) which might show a window at any time, this window does not have a title but it does have the WM_CLASS set (the WM_CLASS is the same for all windows of the application). I want to act upon the event that this window is shown (or created, whichever is best/easier).
It doesn't seem like the window is opened "within" the main applications window. Using xwininfo -children -id <window-id>
shows that the main application and the sought window are on different branches, connected to "the root window".
The branches looks like this, where R is "the root node"; A is a root node of the main application's branch and Y is the root of the branch with sought window W:
R
/ \
A Y
/\ \
B C X
\ \
Q W
So I'm hoping that I can find the unique structure of Y-X-W
I'm not sure I have to listen to all windows, but it is my assumption that I'll have to check what happens within "the root window" and try to find the sought window.