This week in KWin (2012, week 29)

This week has not seen much development given that we are very close to the 4.9 final tagging. I pushed a little bit of refactoring into master (coming with unit tests), but apart from that we only had bug and crash fixes for 4.9.0 and even one regression in current master (4.10) got spotted and fixed. Thanks to Michael Pyne for bisecting and identifying the commit shortly after the commit had been pushed.

I’m personally very unhappy to see bug reports being opened for new issues in 4.9 even after RC 2 as it means that the previous beta versions have not been tested properly. None of the reported issues is a regression compared to the previous beta and rc releases, so they should have been spotted before. At this I also want to remind to report “obvious” bugs which you think someone had to have noticed. E.g. the fade effect incorrectly faded in a minimized window which got closed resulting in a flash with the window visible again. It’s a very obvious bug but might not be spotted by developers (e.g. I never close minimized windows). Interestingly this bug had been present since a long time but had been shadowed by another bug which got fixed in 4.9.

There has been one for me very interesting crash report which I cannot reproduce, but looking at the code the crash had been obvious and took me something like two minutes to fix. But as I don’t like pushing changes I cannot verify I wrote the first unit test which highlights an issue and verifies that the problem is fixed. In this case it was possible to write a test as the affected code is in the window switching framework which is seprated from KWin core and allows to mock the required objects. Nevertheless I had to introduce around 500 lines of mocking code to write a five lines test for a three lines change. Nevertheless it’s worth the effort as the next spotted bug in this area can be easily verified by a test.

What I’m very happy concerning the bug reports is that none of the bugs reported this week are still open. All reports have changed the state to either resolved or needsinfo. For a relaese candidate phase that’s pretty good, but still we are looking for people wanting to help with triaging the bugs.

Summary

Crash Fixes

  • 303247: Crash after installed a new decoration
    This change will be available in version 4.9.0
    Git Commit
  • 303713: kwin crash when adding applets into the main amarok window
    This change will be available in version 4.9.0
    Git Commit
  • 303840: Kwin crash to do with hidden, empty or otherwise odd window titles
    This change will be available in version 4.9.0
    Git Commit

Bug Fixes

  • 303397: KDE desktop effects are laggy when i uncheck Vsync option in system settings
    This change will be available in version 4.9.0
    Git Commit
  • 303579: Rapid flickering in locked screen — makes it difficult to unlock
    This change will be available in version 4.10
    Git Commit
  • 303891: Fade effect is being executed for minimized windows
    This change will be available in version 4.9.0
    Git Commit
  • 303630: kde-workspace fails to compile, see kde-core-devel post in URL
    This change will be available in version 4.9.0
    Git Commit

New Features

    Tasks

    • 303314: Refactor Screen/Window PaintData
      This change will be available in version 4.10
      Git Commit
    • 303093: Don’t use OpenGL matrix stack in OpenGL 2 backend
      This change will be available in version 4.10
      Git Commit

    Looking for KWin Bug Triagers

    At the moment all incoming KWin bugs are managed by the developer community. This is actually not a really good solution as we have a high count of duplicate crash reports and also many bugs where we have to ask again and again for the same things (e.g. providing driver information or providing the list of loaded effects). Obviously if developers spend time on managing the bugs they cannot fix bugs in this time.

    KWin is in the very lucky situation to have a cleaned up bugtracker. This means we don’t have old junk in the tracker and our bugs are nicely categorized by being put into the right categories. So becoming a triager would not mean cleaning up the old stuff but only help us with incoming bug reports. And that are in fact not that many – we get about 20 new bug reports per week.

    For us developers it would be really helpful to only get the final and real bugreports. That is reports which have a way how to reproduce the issue and all needed information to properly investigate an issue.

    So your task as a bug triager for KWin would include:

    • Finding Duplicate crash reports (very easy as DrKonqui adds the number of possible duplicates)
    • Identifying clear driver crashes (relatively easy if you understand a little bit about reading backtraces)
    • Escalating if a driver crash is reported too often, so that we can consider adding a workaround
    • Adding meta-information to the report: version, component, flags
    • Verify that the bug is reproducable
    • Add the steps to reproduce a bug if it is missing
    • Identify actual user support issues and send the user to forum.kde.org
    • Discard all Wishlist reports and send user to brainstorm.forum.kde.org

    As we currently read all reports and are used to work with the bugtracker we can provide help and you can start by just watching our work in the bugtracker by following the shared bugzilla user. If you have questions about why we for example set a bug to duplicate I’m happy to explain that and for that I would prefer using #kde-bugs on freenode.net so that many bug triagers can get the information.

    We would be glad to welcome you as a KWin Bug Triager and your help to make KWin a better window manager will be highly appreciated.If you are interested please leave a note, send a mail to kwin@kde.org or just ping me in #kde-bugs.

    This week in KWin (2012, week 28)

    I decided to start a new blog category called “This week in KWin”. Based on the bug reports we resolved in a given week I am able to highlight important developments in KWin. This is not meant as a replacement or competition to the Commit Digest – I am very happy with the digest. But it is for overall KDE and does not give us any possibility to add further comments to it or highlight very technical things which might be noteworthy (yes, there is the digest tag for commits).

    The biggest difference to the commit digest is that this report is generated from the bug tracker while Commit Digest is generated from git log. I think the bug tracker is a better source to track the development of a project as quite often you have a commit series for a specific bug or feature.

    Important Changes in week 28

    This week we have seen the tagging and release of the last release candidate for 4.9. As you can see in the summary below we have fixed quite a few issues last minute on Monday. This includes two rather important fixes for the rendering of thumbnails and the logout effect is finally available again. These were changes mostly done on last day of Akademy and while flying home.

    We had received a very interesting crash report for 4.9 (4.8 is not affected) which got fixed (not available yet in RC2). When you use an Aurorae theme and close a glxgears window through the close button, KWin crashes. We had such issues with the old Aurorae implementation and had thought the port to QML had finally solved it. So we added the same and already known workaround from the old implementation to delay the closing by one event cycle.

    Last but not least there is one important change for the 4.10 release. KWin’s window tiling capabilities which were implemented by a Season of KDE project a few years ago had to be removed again as the feature is seeing some bit rot and is completely unmaintained. Thanks to scripting it should be possible to implement window tiling again and provide it in time for 4.10. And work is going on to make that happen. If you want to help, please leave a note 🙂

    This change does not affect the upcoming 4.9 release and does not affect the quick tiling on screenedges functionality.

    Summary

    Crash Fixes

    • 179077: drag-and-drop between windows by cover switch alt-tab causes apps to crash
      This change will be available in version 4.10
      Git Commit
    • 303450: kwin glxgears crash
      This change will be available in version 4.9.0
      Git Commit

    Bug Fixes

    • 296065: Lanczos Filter broken after screen size changes
      This change will be available in version 4.9 RC 2
      Git Commit
    • 297864: ThumbnailItem allows upscaling of Windows
      This change will be available in version 4.9 RC 2
      Git Commit
    • 302164: the efficiency of drawing in kwin 4.9 beta2 is lower than 4.8
    • 303096: Logout effect completely broken
      This change will be available in version 4.9 RC 2
      Git Commit
    • 303200: Incorrect signal connects for activities in WorkspaceWrapper
      This change will be available in version 4.9 RC 2
      Git Commit

    New Features

      Tasks

      • 303090: Remove Tiling Support From KWin
        This change will be available in version 4.10
        Git Commit

      Do not use BleachBit

      This week we received two crash reports after a user tried BleachBit. Reason enough to write a word of warning about this application.

      BleachBit invalidates shared memory included our shared data cashes. Any KDE application using will crash once the memory got invalidated. As to my knowledge Oxygen is a heavy user of the shared data cache any GUI application is affected.

      If you think that you need to use BleachBit I recommend to read the wonderful article on lwn about it: BleachBit: Does GNU/Linux need the equivalent of a Windows registry cleaner? If you don’t know what it is, just forget about it, but warn anyone who you will see using it.

      Akademy Impressions

      Now that I am back home I finally find some time to blog about my impressions of Akademy this year. Overall it was a really great Akademy at an awesome location and wonderfully organized by the local team. Thanks a lot for your work!

      For me it was the already the fifth Akademy – I hadn’t realize that before and was quite surprised, I still remember my first Akademy in Mechelen as it were yesterday. This year Akademy was a very special one as I had been a member of the jury for the Akademy Awards. I am very happy with the people and products we awarded this year. Camilla, Lydia, Kevin and Nicolás all do an awesome job in their area and all help shaping the future of KDE.

      From a conference point of view my personal highlights were the talks about Qt 5 and Frameworks 5 (thanks to Thiago, Kevin and David) as well as Mirko’s talk and the talk about defensive publications. I’ll probably start to document some of the “innovations” inside KWin soon (personally I do not consider anything inside KWin being an innovation, but I see that we should have it published before someone gets a patent on what we did years ago).

      My highlight of the days after the conference is the training on QtQuick 2 by our friends from KDAB. I was afraid that I would not learn anything new, but there was lots I did not know and I realized how I can improve my QML code quite a bit. Some of that (especially based on feedback from Nuno) already made it into the 4.9 release. But maybe most important is that I got an idea how QML based effects could look like which could contain shader elements as will be available in QtQuick 2.

      While nothing is implemented yet I thought about how our Fade effect could look like in QML:

      WindowEffect {
          id: myWindow
          opacity: 0.0
          onClosed: opacity = 0.0
          Component.onCompleted: myWindow.opacity = 1.0
          Behavior on opacity {
              NumberAnimation { duration: 150 }
          }
      }
      

      Well we will see how this idea will evolve.

      Another highlight of the days after the conference was a session where Jeroen van Meeuwen was present and explained his plans for our bugtracker. I am very glad that there is someone who cares and wants to help us getting bugs.kde.org in a usable shape again. I am really looking forward to this happening and I hope that our developers will support his efforts and start using the bugtracker. I am convinced that bugzilla is our most important and most neglected piece of architecture and a proper usage will help us producing better products (and with that I don’t mean that we fix bugs).

      Of course I hardly did any coding, but I mentored a BoF where I explained a little bit about the internals of KWin. I hope to see some patches and that is more important than me coding. But I fixed a few bugs I found by pure chance. And I must say this makes me rather unhappy. If a functionality is broken for almost a year and it’s me noticing then something is really broken. That I don’t use the functionality, that’s just fine. But that no user noticed that the logout effect has not been working at all in 4.8 is quite shocking.

      So please my dear users: if you see some “obvious” bug where you think it must have already been reported, please report it nevertheless. Not each obvious bug might be obvious to the developers (I only suspend my system and over the last year got only logged-out by a freezing BLOB). I rather have a duplicate too many than a broken feature.

      That reminds me: we currently have a release candidate out. Get it, test it!

      Workspace Sprint

      The last week I was allowed to spend in Pineda de Mar for the Workspace sprint. As others have already pointed out it was quite a different sprint with not much hacking going on and not so much technical discussions into the details. For this we will have a Tokamak sprint in Randa later this year.

      Our sprint was mostly focused on community building and getting everyone on the same knowledge level. The weeks leading to the sprint showed that this was needed and I myself – although being involved in Plasma for quite some time – had to catch up on many things I was not aware of. The sprint helped us to identify for example weak spots in our internal documentation and getting this fixed is now one of the highest priorities.

      The games Kevin played with us really helped us to identify where we want to go and what that means for our future development. This will also influence KWin’s development as we finally understand how Activities and Desktops go together and that helps us in KWin to properly focus development effort on it. Over the last cycles we did not really work on activities support in KWin as we were very unsure on how the window manager is involved in the process. This is now much clearer to me – I just need to document it and luckily AurĂ©lien already started that process.

      Luckily I was able to also get some hacking done. As Mr Gwenview was sitting next to me, I started to add some OpenGL magic to the image viewer. Sometimes I just need to work on a different piece of code and to get away from the daily work on KWin. The result is a much smoother zooming experience. At the moment the feature set is not yet identical to the existing implementation, but it’s on a very promising way. Very pleasing is also that at least on my system it works also well with llvmpipe, which could be a very nice solution for the case that a user does not have a decent OpenGL graphics card. For users who like to experiment, feel free to give a try to graesslin/opengl branch in the gwenview repository.

      Overall it was a very nice sprint, but also very exhausting. I’m glad that I have one day to relax before going back to work. And I am really glad to see everyone again at this years Akademy where I will give a talk about KWin scripting.

      Please thank the Frankfurt Airport for this blog post. Thanks to needing more than forty minutes to get my luggage from the plane to the belt I missed one train by two minutes (it went > 1h after landing) with the next train only after one hour instead of the normal half hourly service.

      Unit Testing a Window Manager

      KWin is one of the oldest KDE applications still in active development without having been rewritten from scratch. Development of KWin started in 1999 for KDE 2, but some parts of KWin even date back to KWM from KDE 1 times. The main software design of the Window Manager component hasn’t changed that much since the initial commit – there is a “Workspace” which manages “Clients”.

      Personally I find it very interesting to see such old parts of the code and software design. If we think about it we realize that the development started just a few years after the Gang of Four published their book about Design Patterns. Also development-methods like Test-Driven-Development and unit testing got described around that time for the first time.

      Given that it is not surprising that when development to KWin started unit tests were not added to the code base. At the time when QtTestLib got introduced KWin had already been in development for six years and not necessarily a code base which could easily be unit tested. Some classes inside KWin had turned into a size which makes it hardly possible to mock the required functionality.

      In order to use QtTestLib the port to Qt 4 had been required. At the same time compositing support got added to KWin – an area which mostly depends on visual representation and which is hardly unit testable at all. It is quite understandable that at that time nobody considered it worth the effort to add unit tests to the existing code base.

      Also it’s quite difficult to start with unit testing if you have been developing an application for a decade without unit tests. You might not see the need for the tests and in general we can say that adding the first test is the most difficult. For an application like KWin which highly requires interaction with an external application (X-Server) it is quite clear that one might consider it as impossible to unit test KWin at all.

      Personally I believe in the usefulness of unit tests especially during bug fixing. So I think that each bug fix should come with a unit test illustrating the problem. Unfortunately there is still a long way to go before establishing such a policy in KWin due to the difficulties in performing unit tests for a window manager.

      Nevertheless even KWin has parts which can be unit tested. And recently I added the very first test to KWin. In 4.8 the KConfig Update Script had a small bug which resulted in very rare cases in an incorrectly migrated configuration. When adding the KConfig Update Script for 4.9 I wanted to make sure that all possible upgrade paths are considered and therefore added the very first unit test for the KConfig Update Script.

      With that the most important first step is done: the KWin source tree contains a tests directory and now it becomes easier to add further QtTestLib based tests. So when I recently started to refactor some code which can be unit tested I decided to go for adding a unit test together with the new implementation. And I must say it turned very useful – some minor bugs I added, could be easily spotted without any code investigations. Just the way I like it.

      Unfortunately unit testing with QtTestLib allows only to test a very small portion of KWin. Anything interacting with the X-Server cannot be tested that way. Many parts require to be a window manager and as the situation is you can only have one window manager running. So a unit test would need to be a window manager and would interfere with the working system – nothing we want from a unit test.

      Given that we would have to basically start the full-blown KWin to perform tests which interact with the X-Server. Unit tests are out of scope and only integration tests seem feasible. But in fact running tests against a running KWin cannot work as it would interact with the running system. E.g. how to test that a window is set to keep above if there is a window rule that forces the same window to keep below.

      This is a difficult topic to solve. We basically need a dedicated testing framework which starts a (nested) X-Server, starts KWin, performs a test and shuts down both KWin and the X-Server. A framework which is decoupled from the running system.

      I’m currently supervising a Bachelor Thesis to evaluate the possibilities of such a framework and to implement a prototype tailored towards the needs of KWin. The current ideas look very promising and are based on KWin’s scripting capabilities by injecting KWin scripts to test certain functionality. I’m looking forward to this implementation as I hope that it will make our life easier – even if it will not be possible to run the tests on a Jenkins installation.

      Also I really like the idea of working together with students. We already do that during GSoC, but there are so much more possibilities for FLOSS to work together with academics. Being it Bachelor Thesis or just seminar papers: FLOSS source code is a great area to work together with real world software and not just a demo application as it is so often the case at Universities.

      BKO: Bug dependencies

      This is the sixth blog post in my series bugs.kde.org for developers.

      During software development it is quite normal that you have some dependencies between the bugs and features you want to implement. E.g. for feature foo you first have to implement feature bar. Bugzilla can help you track such dependencies in a nice way.

      In most KDE projects I have seen poor man solutions to manage these problems. The most obvious one is to just write in one of the comments that first the other bug report needs to be implemented. But that’s a very bad solution. It can only be processed by humans by reading the comments and from bug report bar the reference is missing completely.

      Another solution is to set bug foo to resolved later indicating that at some later state the bug will be fixed. But how likely is it that you remember to reopen that bug after you have implemented foo? I think it’s rather unlikely given the amount of bugs reported on bko that anyone is considering the resolved later bugs. I just checked that for KWin and of the 17 bugs resolved later many are fixed right now.

      Another solution I have seen is to create a meta bug and set all depending bugs as duplicates of this one. We then find comments like “note: please check duplicates”. This is also a very bad solution as it requires to read through all the bug reports and it’s not what duplicates are for. It’s not the same issue after all.

      All these solutions have one clear drawback: they cannot manage dependencies hierarchies. Consider the following hypothetical feature request: a user wants to be able to interact with a rotated window. This requires first generic support for rotated windows and support for input redirection. Input redirection makes only sense with Wayland. For this we need to add at least a build dependency in CMake, implement Wayland server and get rid of X. If we would want to we could split this up even further and we have a nice dependency tree like this one:
      Bug Dependency Graph

      This is a graph rendered by bugzilla. So how does it work? It’s quite simple. Each bug report has two fields to manipulate the bug dependency: “Depends On” and “Blocks”. A bug which depends on another one can only be set to fixed after the other one is fixed. The same way a bug which is blocked cannot be fixed as long as the bug which is blocking is not fixed. In fact these two are exactly the same: if you add a depends on, the other bugs blocks field will be updated. So you can always navigate the tree from both sides.

      Using the bug dependencies can really help you if you split up your work into multiple tasks. Combined with the searches you can get bugzilla telling you which bug you have to work on.

      Profiling of KWin

      In my last blog of KWin I described the improvements in the startup of KWin. Since then I did some further profiling and could improve a few effects to load resources only when needed. E.g. Present Windows effect created the texture for the window filter on startup. This is now delayed till the user starts to type which means not only about 20 msec faster startup but also less used resources in case the user does not use the filter at all. The effect (and other effects) had created this texture on creation since 4.3. Of course it’s not a long waiting time, but in multiple effects which need to be loaded at startup it sums up to a noticeable delay.

      My investigations have now reached a point where I think there is hardly anything left to do for 4.9. We still have some I/O when starting up the OpenGL compositor (150 msec) as we need to load the shaders from file but this will be quite difficult to improve without a major rewrite on how the compositor startup works, which is of course not possible for 4.9 any more and I want to change the compositor startup anyway for 4.10.

      Also remaining is currently the X communication in the startup. There are many round trips to the X Server and that can unfortunately be noticed. It’s something which will hopefully improve in 4.10 by making stronger use of xcb.

      Given that I was doing profiling I was also interested in our rendering and had another look at this to see why we sometimes are not able to render at 60 frames per second. My results are very promising. Some of the assumptions which we already had could be validated which means I have a general idea where I need to optimize. It will be interesting work as for that I won’t have to touch KWin source code. And I find it quite satisfying that we have reached a point in KWin development where we need to optimize non KWin code to improve the performance further.

      What remains is how I did the profiling. The obvious candidate would be callgrind, but it is not really useful to find delays in the startup. In case of KWin the compositor is dominating the results of callgrind so that the calls which are executed just once are hardly visible. Another problem with callgrind is that it does not show us when we are waiting for I/O or X.

      I needed to know how long the actual tasks take to perform. Therefore I needed to add profiling information which ended up in this small class:

      class Timing
      {
      public:
          Timing(const char *message)
              : m_message(message) {
                  m_timer.start();
              }
          ~Timing() {
              std::cout << m_message.latin1() << ": " <<
      m_timer.elapsed() << " msec" << std::endl;
          }
      private:
          QElapsedTimer m_timer;
          QLatin1String m_message;
      };
      

      With that I spiced up my KWin checkout to contain many Timing timing(“Load Cube Effect”); statements. And it allowed me to get very close to where the time is spent.

      Overall I take from this experience that the key to a faster startup is not a more parallel startup through things like system-d, but that actually you have to question everything you do. Of course it is useful to construct everything an object needs when the object is created, but it might not be what is actually required. This is quite the case for plugins and especially 3rd party plugins. I would be positively surprised if a third party author of a Plasmoid is aware that loading an image in the Plugin ctor will delay the startup of the complete KDE Plasma session.

      So if someone wants to work on getting the startup faster: there are many Plasmoids and I am sure for quite a lot we can put loading of data into threads and delay calls into the next event loop. Also it could be nice to create some krazy checks to test for common “mistakes” like loading an image not in a thread.

      Improving KWin Startup Performance

      I haven’t been blogging about KWin for quite some time, so it’s way time to write what I recently worked on for KWin.

      The big topic of the work of the last two weeks is improving the startup experience of KWin. It’s mostly a scratch your own itch as I do restart KWin quite often while working on it and having it start up faster is a nice thing in general.

      KWin consists of multiple parts which need to startup:

      • Window Manager
      • Compositor
      • Effects
      • Scripts

      The current version does everything in one go and starts with the compositor, but the first frame is rendered after everything has been set up. During this process the screen is frozen as the compositor has taken over the rendering from X and the screen has not yet been rendered by the compositor. This is not visible for users as KWin only starts up while the Splash Screen is shown and given the way how our Splash works this short freeze is hardly visible. If you know that it has to happen and if you know which of the shown icons belongs to the window manager you can see it.

      My idea to improve this is splitting up the startup into phases and try to get the first frame rendered faster. E.g. the Compositor is fully functional without Effects, the Window Manager does not need the scripts and so on. What we now already have in master is delaying the loading of Scripts into the first event cycle after the Window Manager has set up everything else.

      This does not shorten the startup time but reduced the frozen time. Even the overall frozen time is more or less the same, but we get a rendered frame in between.

      To get the actual startup time down a possible solution is to identify areas which take long and make them load in parallel. For that areas where KWin actually waits for something else need to be identified and moved into an async running thread.

      One of these areas is the loading of the configuration options. KWin re-parses the configuration file at startup. This is I/O and KWin needs to wait for it, but no longer in current master. The I/O operation is now performed in a background thread and only if the loading has not finished before KWin needs to access a configuration value for the first time it will have to wait. On my system loading the file takes only a few milliseconds and with an SSD it should be even faster, but nevertheless it’s a few milliseconds shorter startup time. And we have to consider that during startup there is a lot I/O going on and the file has probably not yet moved into the cache. But the longer it takes the more likely it is that KWin has to wait as we need config options very early in the startup process.

      Also the Compositor is currently waiting: it invokes an external program to figure out whether direct rendering is supported or not. After reworking the patches multiple times during review this is now strongly improved. KWin does no longer have to wait for the external program and as a side effect the code got cleaned up, so that no OpenGL call is created outside the compositor. To achieve the we “had to” remove OpenGL detection from the Desktop Effects configuration module. It now queries KWin directly which is of course much better.

      Executing the external program took around 100 msec on my system and the code which got removed were another 50 msec. That was about 5 % of the overall KWin startup time on my system.

      While doing the profiling I also figured out a few things which can easily improved when creating and destroying windows. So I discovered that the window decorations are actually created twice: once when the window is started for compositing and once when the window is fully managed by the window manager. This had been required to support both compositing and non-compositing and to allow easily turning on and off compositing at runtime (decoration needs to be recreated to e.g. remove shadows). My current patches will now ensure that the decoration is not created twice when a window is opened, though in the special case when kwin restarts it still has to create them twice. But that’s a problem I have to live with and which does not affect our users.

      Another interesting thing we discovered due to a crash I recently introduced: while ending the window manager completely we performed quite some heavy operations on the windows, which make sense during the normal operation but not when shutting down. This is now nicely optimized away resulting in a faster and more secure shutdown.

      This weekend I continued to move I/O operations into threads and loading KWin scripts from file does no longer block the window manager and compositor. It’s now more or less a pattern which I will try to use for other areas where files are loaded (e.g. some effects).