Skip to content

Scripting in KWin?

Wednesday, 19 March 2008  |  lubos lunak

I guess many people see KWin only as 'the window manager from KDE', but there are actually things that can make KWin beat many other WMs - features (some of them first introduced in KWin, such as the focus stealing prevention), compositing, tested codebase, handling of various broken apps, configurability, window-specific settings. I introduced window-specific settings to help with many special cases (broken Java apps, focus stealing prevention problems in corner cases [BTW, Metacity until recently didn't have any option to turn its focus stealing prevention off at all, and even now it's only all-or-nothing - I wonder if people learn to live with such problems, or how come], or simply I-have-this-very-special-case-when-I-want-this-window-do-this). But as you know, it's never enough, and there are some requests to make the somewhat large window-specific settings dialog even larger. I really have no idea how I should create a decent GUI for cases like 'when a window is maximized do ...'. Nor I am going to try anyway, for such really special cases. Contributions to KWin core are quite rare (except for people working on compositing, for which I'm really grateful) and I'm only a human.

However, the solution for this shouldn't be that difficult. Special cases can never be really handled by generic code, so the obvious way seems to be scripting. And after a while of starting at QtScript docs (I have only little clue about scripting) I created a quick KWin patch as a proof of concept. With it, a Javascript snippet makes all new XTerm windows appear on desktop 2. Of course, for this to make it into SVN it'd still need some work, most of which looks at the level of Junior Jobs or slightly higher: Make it preferably use Kross instead of QtScript, support for loading the scripts instead of having it hardcoded in the sources :), making sure it won't slow down KWin to a crawl, support for scripts getting access to more functionality and error checking (which is the reason why the patch creates a wrapper class for window instead of letting the scripts access KWin internals directly, right now e.g. KWin crashes if the script returns wrong desktop number, and I also really don't want to handle bugreports of a window manager that lets people mess with its internals).

So, people who don't want to do anything with KWin's code for unknown reasons but want new things from it, now you have a chance (of course, it involves temporarily doing that, but nothing is perfect, right ;) ?). I can handle writing KWin code quite fine, so I have little motivation for this getting finished, sorry.