Window to Application
Try to determine the location of the
.desktop file associated with an X window.
from wintoapp import WinToApp # Initialise the object wta = WinToApp() # Get all the matching application paths matchingPaths = wta.from_id(windowId) # Grab the most likely match applicationPath = paths
On many Linux platforms, 'applications', in the way in which in casual user views them, are stored as '.desktop' files. These are ini-like flat files that contain the name, description and command (along with several other fields) associated with an application. The specifiation can be found here.
On the other hand, the actual windows of an application are clients of the X server. These windows have various properties (as enumerated by
xprop), which can be useful in various ways.
Unfortunately, there is no straight-forward and well-adopted way to associating '.desktop' files with their corresponding X server windows. The specifiation for '.desktop' files defines the
StartupWMClass field, which identifies the
WM_CLASS property of the window corresponding to an instance of the application defined in the '.desktop' file. However, this is far from widely adopted.
The solution (workaround), is to use several different methods of matching windows to '.desktop' files, and just hope one of them works. That is what this project aims to do. The matching algorithm is based off Docky's method, as detailed in my blog.
One thing for which this matching alogrithm is useful is in determining the correct icon associated with a window.
Check out the
examples directory for a sample scripts. There's a further README in there.
BadWindowIdError gets raised if a supplied window ID doesn't work. Also a
XServerError gets raised if there's a problem with the X Server (the original exception will be chained on).
Almost certainly doesn't work on Windows, though maybe it could be adapted. I don't know.
This code is licensed under the MIT license.
Have a wonderful day!