Help KWin to revamp the configuration interfaces

The configuration interfaces of KWin in System Settings are really old. Some of them date back to KDE 1 times (copyright of 1997) when the window manager was KWM. This has some implications about the code: all the used widgets are configured through C++ which makes it very difficult to maintain and develop the configuration modules. The user interfaces do not yet use UI files which could be easily edited with Qt Designer. That’s the main reason why the interfaces still look like they used to be in KDE 1 and 2 times.

I think it’s about time to overcome the “uuuuhh, I don’t want to touch that code” state and start to move forward. For this it would require to transform the user interfaces into UI files. This is a very easy task which does not require any programming skills. And that’s why I blog about it. This would be a great task for anyone who always wanted to contribute to KDE, but has not dared because he is not a programmer.

All it needs is to go to System Settings -> Window Behavior -> Window Behavior and create for each tab a widget in Qt Designer which looks exactly like it used to be. If we have that it’s becoming easier for us developers to extend it, to try out better interfaces without touching the code. In case you have any questions feel free to send me a mail, contact me on IRC or leave a comment on this blog.

Build Instructions for KWin

On poular request I added a section on How to Build KWin to our Wiki. This aims to those who want to work on KWin but do not want to build all the dependencies and the other parts of the Plasma Workspaces.

I hope this can help some people to test and develop on KWin. In case you find any errors in the instructions, please let me know. I tested the instructions yesterday on my Pandaboard and it compiled KWin master against a dev environment of Ubuntu 12.04, so they seem to be correct 😉

Refactoring KWin’s Workspace

From time to time it happens that I talk with fellow developers who tried to work on KWin. One of the common feedback is that it is difficult to find your way inside KWin, though most is in fact described in the Hacking guide. But when considering our largest class Workspace, I kind of understand why people find it difficult to work on KWin.

The implementation of this class starts with an interesting discussion put into a comment:

Rikkus: This class is too complex. It needs splitting further. It’s a nightmare to understand, especially with so few comments 🙁

Matthias: Feel free to ask me questions about it. Feel free to add comments. I dissagree that further splittings makes it easier. 2500 lines are not too much. It’s the task that is complex, not the code.

I do not know when this comment was added (git blame only allows going back till 2007), but I fully agree with Rikkus on this one, because today it’s not the complex task which is dominating and it’s also not 2500 lines but a little bit more. Also most likely I could not ask Matthias (Ettrich) anything about KWin anymore.

And we actually did something about it. Last year we had a Google Summer of Code project to identify areas which should not belong into Workspace and splitted those out. For example the handling of Screen Edges had been moved into an own class.

But one of the larger tasks which did not get merged during the project was to split out the Compositor from the Workspace class. So far the Workspace had been responsible for both Window Management and Compositing. But on closer look we realize that these are two orthogonal tasks with only very small overlap.

Recently I took up this work and rebased it on current master and started to extend the work. The compositing related code part has always been responsible for creating the Scene (the actual renderer) and the Effect system. The effect system is only initialized if the Scene could be created and when compositing gets stopped both are destroyed. So we have a clear connection between the Compositor and the Effects system and the Scene. Nevertheless both are implemented as a static pointer available to everything in KWin. But nothing outside the Compositor needs the Scene. In fact it was only used as a check whether Compositing is active.

As a result the Scene is now owned by the new introduced Compositor class and I’m working on making the Effects system also completely owned by the Compositor, though for the Effects the static pointer probably has to be kept around. Nevertheless inside KWin there is actually no need to access this pointer outside the Compositor.

But even after moving the Compositor from Workspace into an own class quite a few methods remained in Workspace for the D-Bus interface. When looking through the interface I realized that most of these calls were actually delegating to either the effects system or the compositor. So I decided to also split up this interface and export the effects system and the compositor as own objects to D-Bus. This has also the advantage that we do not offer to e.g. load an effect if the compositor is suspended.

Of course we cannot remove methods from our D-Bus interface as it is kind of our public API to the outside world and we don’t want to break 3rd party application or our own config modules. Given that the split is not sufficient to have less unrelated methods in Workspace. To solve this problem I introduced a very thin wrapper generated from the D-Bus Introspection XML. The implementation of this wrapper just delegates to either the Workspace, Compositor or Effects system. The result is that the Workspace is no longer directly exported to D-Bus and that the unrelated methods could be dropped – they were all unused inside the application. When leaving Qt 4 behind us we can then clean up the D-Bus interface and drop the unrelated methods and the wrapper.

The Compositor has not been the only area where I did some refactoring. Recently I added a new sub-menu to the Alt+F3 menu and was rather annoyed by the process. This menu is also part of Workspace and to implement an addition one has to add a private method, two private slot and two private members. Given the size of the class it’s lot of searching where to add the elements and the names are not the best. Basically one has to namespace the method and variable names to make them non confusing. To make the work even less pleasant the variable names vary in the naming: variable_name vs mVariableName. Personally I don’t mind the way how variables are written, just consistent please.

I was so annoyed working on this code that I decided to never again be annoyed about it and started to move it into an own class. Not only did Workspace get smaller by this change, but also the functionality of the menu is nicely coupled and I was able to rename the variables and methods to have sane and consistent names.

Overall the result of these three topics highlighted in this post are that the header file of Workspace dropped 120 lines of code which are about 10 % of the header’s size. And the two new introduced header both have more than twice the number of lines due to documentation being added to it. To be fair the menu already had documentation, but in Qt style on the implementation and not in the header. Most of our documentation is in the header so this also adds some more consistency.

This week in KWin (2012, week 34)

This week we have mostly seen work on 4.10 and not so much on 4.9.1. Two further bugs in Window Switching got fixed and a few more bug fixes are in the pipeline (I have a small review backlog).

But the work on 4.10 is rather impressive and really important. First of all I want to thank Jammy Zhou for adapting our OpenGL test application to determine whether the Catalyst driver supports direct rendering with compositing. Thanks to that change KWin will default to direct rendering and OpenGL 2 on the latest Catalyst drivers (in fact KWin defaults to direct rendering on all drivers now). If you are already using a recent Catalyst version you can also set the environment variable “KWIN_DIRECT_GL” to “1” to enforce direct rendering, no matter what the test app thinks. This works with all currently supported KWin versions.

My work concentrated on finishing the Plastik port to QML which I just merged into master. The classic decoration is still around, I want to make sure that the QML port is working correctly first. Please give it a try with e.g. Project Neon.

Furthermore I did quite some refactoring. Last week I mentioned the addition of Screens to the “User actions Menu” and that actually triggered some working on that code as I realized that this needs to be split out. This refactoring got just merged, too. And last but not least, I finally finished some unmerged work from last year GSoC. We again and again broke the patch set which made it difficult to merge. The user actions menu which I merged first, caused serveral merge conflicts again, so that was not a trivial thing. I intend to do a dedicated blog post to explain the refactoring especially as I have some more work already prepared. The numbers of these three merged branches today are quite impressive:

21 files changed, 650 insertions(+), 353 deletions(-)
7 files changed, 812 insertions(+), 555 deletions(-)
36 files changed, 2509 insertions(+), 160 deletions(-)

Summary

Crash Fixes

    Bug Fixes

    • 305449: Empty TabBox in case of no active Client
      This change will be available in version 4.9.1
      Git Commit
    • 304950: alt+tab works wrong with “one window per application”
      This change will be available in version 4.9.1
      Git Commit

    New Features

    • 301327: Option to disable close on double click in Aurorae
      This change will be available in version 4.10
      Git Commit
    • 301103: Allow direct rendering with fglrx
      This change will be available in version 4.10
      Git Commit
    • 303810: Generic QML support for Aurorae Themes
      This change will be available in version 4.10
      Git Commit

    Tasks

    • 299277: Move Workspace’s compositing functionality to own class Compositor
      This change will be available in version 4.10
      Git Commit
    • 305832: Split out Useractions Menu from Workspace
      This change will be available in version 4.10
      Git Commit

    This week in KWin (2012, week 33)

    This week we have seen many bugfixes for the next 4.9 release and more are in the pipeline. Overall nothing special happened, the distribution I wrote about last week fixed the downstream issue so we are no longer flooded by duplicate crash reports. Since the 4.9.0 release 39 bugs have been created against KWin and we already fixed ten of those. Most of the other bugs are of course duplicates and other incorrect states.

    Next to bug fixing also some new features entered master aka 4.10. A patch to use mouse wheel in Cover and Flip Switch effect which had been blocked for some time by the feature freeze got merged and for the users of multi-screens we have a new nice feature: the window decoration context menu (alternative shortcut Alt+F3) gained a “Move To Screen” sub menu. When I worked on that code fragment I realized it needed to be refactored – that will most likely end up in the next report.

    Summary

    Crash Fixes

    • 304620: KWin crashes when alt-tabbing after plasma crash
      This change will be available in version 4.9.1
      Git Commit

    Bug Fixes

    • 304791: Aurorae ignores ‘Window title’ font setting
      This change will be available in version 4.9.1
      Git Commit
    • 304822: TitleHeight should never be smaller than ButtonHeight
      This change will be available in version 4.9.1
      Git Commit
    • 304404: Track mouse effect does not explicitly set the opacity
      This change will be available in version 4.9.1
      Git Commit
    • 304847: Big Icons TabBox does not elide caption
      This change will be available in version 4.9.1
      Git Commit
    • 305338: Effect Information not included in Support Information
      This change will be available in version 4.9.1
      Git Commit

    New Features

    • 269207: Add screen management actions to window context menus
      This change will be available in version 4.10
      Git Commit
    • 244439: JJ: Need Mouse navigation in flip switch mode
      This change will be available in version 4.10
      Git Commit

    Tasks

      After 4.9 there will be 4.10

      After the release of the KDE Plasma Workspaces 4.9 I have read quite often in the Internet that users and also Media assume that the next release will be 5.0. This is not the case, the next release of the KDE Plasma Workspaces, Applications and Plattform will be 4.10 to be expected at the beginning of 2013 (release schedule has not yet been finalized by the release team).

      I do not know why people assume that there would be a 5.0 release but I guess it is related to the work on Qt 5 and KDE Frameworks 5. Also some people seem to assume that after 4.9 the 5.0 has to follow due to second number being single digit, but a simple look at e.g. GNOME would show that numbers can increase as long as one likes.

      At the current time there are no plans yet for a 5.0 release of the KDE Plasma Workspaces and at least I do not see any reason to increment the first number even after the release of Framworks 5. I expect that there will at least also be a 4.11 release before we start to think about version numbering for software based on Frameworks 5.

      This week in KWin (2012, week 31 and 32)

      This week I present a summary for two weeks as I had unfortunatelly no possibility to write the summary last week. Of course the main event in this two weeks has been the release of 4.9.0 and as always this triggered quite a flow of new bug reports. Since the release on August 1st 38 bugs have been reported against KWin and an additional nine KWin related duplicate crash reports ended in systemsettings. What is really sad is that we have a duplicate rate of 47 % since the release. Many of the often reported bugs are easy to find and easy to trigger regressions compared to 4.8. This makes me really sad, not because we released with regression, but because such issues could have been spotted and fixed during the beta testing phase. My wish for 4.10 is that more users test the beta releases and report issues.

      The most often reported bug since the release is unfortunately a crash in the window decorations configuration module. This is a very nasty bug and interestingly the reason for this crash is in my opinion just lack of communication. In 4.9 we changed the API of KDecorationUnstable, as the name says that is an Unstable API. We ensured that an incompatible decoration would not be loaded and does neither crash KWin nor the decoration module. Unfortunately we did not inform the distributions about the change. One distribution recognized that there is an ABI incompatible change and seems to have done what they use to do in such cases: change the ABI version of the package. The result was that also for the stable decorations the ABI changed. We were not prepared for such a case and did not expect incompatibilities in the stable API. The result is that the configuration module crashes in case a user has a 3rd party decoration installed which has not been compiled again with the new ABI. Overall the problem could have been easily prevented before by better communication. We should have informed the distributions and the distribution should have contacted us to clarify what to do.

      Summary

      Crash Fixes

      • 304340: segfault on exiting cube effect
        This change will be available in version 4.9.1
        Git Commit
      • 304870: kwin crash when maximizing window when using Aurorae and BorderlessMaximizedWindows
        This change will be available in version 4.9.1
        Git Commit

      Bug Fixes

      • 304248: Wheel operations on title bar not functional
        This change will be available in version 4.9.1
        Git Commit
      • 302783: In kde 4.9 rc1 some opengl fullscreen games dont work correctly, by not going fullscreen
        This change will be available in version 4.9.1
        Git Commit
      • 304253: The «bounce» cursor effect when starting a program is not bouncing anymore
        This change will be available in version 4.9.1
        Git Commit
      • 304520: flip switch incorrectly aligns window height on multiple monitors
        This change will be available in version 4.9.1
        Git Commit
      • 304564: blur effect does not work when the dashboard is first invoked
        This change will be available in version 4.9.1
        Git Commit
      • 304249: Long delay when moving window through title bar
        This change will be available in version 4.9.1
        Git Commit
      • 304799: kwindecoration kcm is broken when using a touchpad
        This change will be available in version 4.9.1
        Git Commit

      New Features

        Tasks

          Fixing Slow Window Movment in 4.9

          Unfortunately a small bug entered 4.9: when using an Aurorae theme moving the window through the titlebar is delayed. It’s a bug we discovered a few days after the final tagging through the work on porting Plastik to QML.

          Since the release we had quite a lot of bug reports for this issue and I have seen some forum threads about this issue. It is already fixed for 4.9.1 but this might be a little bit too late.

          As the bug is just in the QML component, everybody is able to fix it localy. In order to do so follow these steps:

          cd /tmp
          wget https://projects.kde.org/projects/kde/kde-workspace/repository/revisions/9ee6a775d592ec3f105892c32c7576d6cdd7c210/diff/kwin/clients/aurorae/src/qml/aurorae.qml?format=diff
          cd /usr/share/kde4/apps/kwin/aurorae/
          sudo patch -p6 -i /tmp/aurorae.qml\?format\=diff
          

          And now restart kwin. Just use KRunner and type
          kwin --replace

          Please be aware that any distribution update for kwin will overwrite the local change and please note that depending on your distribution the path might be different (the path is taken from the Ubuntu package).

          If you don’t want to experience such regressions in 4.10 I recommend to test the beta releases. The issue had been introduced in January or February and nobody had noticed (I use Aurorae but don’t move windows through the titlebar). I’m really surprised to see this issue being reported so often after the release that I have to write a blog post.

          A small service announcment: as you might have noticed I did not write a this week in KWin post. I currently have a reduced connectivity which means the system having the xslt does not have Internet. So next week I will cover both weeks.

          This Week in KWin (2012, week 30)

          The major event of this week was of course the tagging of 4.9.0. We have two important fixes which made it into 4.9 and apart from that not much happened. My current work on Aurorae is not yet finished and has not been pushed yet. The work on it also discovered two small regressions in Aurorae 3 and I’m quite unhappy that we will ship 4.9 now with two known regressions. But they will of course be fixed for 4.9.1.

          I want to use this rather quiet week to remember everybody about the importance of reporting issues early. We got today a bug report where the user mentions that he noticed this issue already with 4.7 and 4.8. Well by know it was already fixed in 4.9 and the user is unhappy that he does not benefit from the fix as he uses Debian Testing (which won’t go to 4.9 any time soon). If an issue gets reported when it got introduced more users will benefit from the fix and it’s much easier to fix the bug as it is more likely that we remember what we worked on.

          Please report bugs only in English language. This week 2 of the 18 reported bugs were not in English. This makes it much more difficult to handle the bugs as there is a language barrier. For me even a bug report in German is completely useless. I use my software only in English and have problems with back translating the German translation to English.

          Summary

          Crash Fixes

          • 304026: KCM crashes on updating a deco’s settings because the lib is conditionally unloaded in new ::canLoad()
            This change will be available in version 4.9.0
            Git Commit

          Bug Fixes

          • 303937: Quick tiling (snap) uses wrong geometry on alternate attempts.
            This change will be available in version 4.9.0
            Git Commit

          New Features

            Tasks

              QML Support for Window Decorations

              Implementing a new window decoration for KWin is not the easiest thing to do. While the API has hardly changed since early 3.x releases it is not very Qt like and requires a strong understanding of how the window decoration in KWin works. To design a window decoration you basically have three options which come with KWin:

              • Subclass KDecoration
              • Subclass KCommonDecoration
              • Design an Aurorae theme

              KDecoration gives a developer the most powerful options. The developer can design the decoration in whatever way he likes. But it also means that the developer has to take care about everything himself. E.g. properly laying out the buttons, handling mouse events on the decoration, ensuring the right resize handles are shown, etc. etc.

              An easier way is to implement KCommonDecoration which already implements the common aspects of a decoration. For example a normal decoration has some buttons on the left and some buttons on the right side. The main task of a developer is to define how large various parts of the decoration should be, e.g. the margin between the left buttons and the caption. This of course limits the possibilities with the decoration.

              The third option is to design an Aurorae theme which means just creating a few SVG elements. This is of course for designers the best option, but again very limiting. If a feature is not provided by the theme engine it cannot be represented. In the same way there are third party deKorator themes available.

              The C++ based decoration APIs seem to be too difficult to be used. If we look at kde-look we see that there are just 14 native decorations available and some of them are forks or old versions of decorations available in KWin directly. But there are already 79 Aurorae themes available and more than 150 deKorator themes.

              What seems to be a real issue concerning 3rd party usage can be validated if we just look into the KWin source base. In 4.9 we ship four window decorations: the Aurorae theme engine, Oxygen, Plastik, b2 and Laptop. Together they are 10 kSLOC of C++ code and 1 kSLOC QML code (Aurorae). Before Aurorae got ported to QML the size of the decorations was 13 kSLOC. Overall that is about 10 per cent of the KWin source base, which is rather large.

              When I ported Aurorae to QML one of the nice results was that I had to add a QProperty based API to communicate with QML in the first place. If this were the actual API writing a window decoration would be probably much easier. As a first step in that direction I started adding generic QML support to Aurorae.

              Following the general direction of all scriptable elements in KWin I decided to go for the well known Plasma Package structure, and added support to Aurorae to use a QML file from a package instead of the own QML file. The patch for this had been in my workspace for quite some time but I did not have any code to actually test whether it works.

              So yesterday I started to re-implement one of our C++ based decorations in QML. I decided for Plastik as the decoration is in fact broken and had been scheduled for removal. We have not yet removed it as we acknowledge the user’s wish to have the KDE 3 look still around. But we are unhappy with having a decoration which is broken and unmaintained. So having a QML replacement would be something rather nice.

              After one and a half days of work I’m proud to say that writing decorations in QML is possible. The changes to the configuration module and Aurorae itself are already under code review, the new Plastik still needs some love. But the decoration is already completely useable as can be seen in this screen shot:

              In the current state the decoration consists of 370 lines of QML code and I expect to need an additional 100 lines to finish the buttons (they are already functional, that is the close button closes the window) and add some of the configuration options. The same API in C++ consists of 1500 lines of code. So we do not only get fewer lines of code but also a more readable and easier to maintain codebase. For something like a window decoration a declarative approach is much better suited than the imperative C++ way of painting elements.

              Overall the new QML API will provide the same powerful features as the KDecoration API, but also provides convenience functionality as KCommonDecoration, e.g. a button group taking care of laying out the decoration buttons. To make development of QML based decorations quite simple support is currently being added to Plasmate as part of the Google Summer of Code project. So you will be able to design and also test the decoration directly from inside Plasmate. This is also quite some improvement as with C++ the only way to test a decoration is to use it in KWin, which can be quite nasty during development.

              The API will need some more love till I’m quite confident to provide it’s usage but there is enough time till 4.10 🙂 So I hope that we can provide a better decoration experience in 4.10. I have a few ideas concerning the usage of QML based decorations in KWin and are looking forward to experiment with them.