This week in KWin (week 46 to 48)

Over the last weeks the beta phase for 4.10 has started which means we have more bugs being reported and more bug fixes. Overall given the large amount of changes which might have broken (switch to KConfigXT, refactoring work in the compositor, xcb), it looks rather good.

Summary

Crash Fixes

Critical Bug Fixes

    Bug Fixes

    • 264041: “Switch to Screen” shortcuts are broken when using three or more monitors.
      Git Commit
    • 310646: No animations in the CoverSwitch effect
      This change will be available in version 4.10 Beta 2
      Git Commit
    • 309510: Logout Desaturation Desktop Effect no longer works correctly
    • 309170: If a windows is fullscreen the quick (un)maximizing is triggered when Alt+click moving it
      Git Commit
    • 276391: Desktop zoom shows wrong mousecursor while resizing window
      Git Commit
    • 309960: HTML in window titles not escaped in tabbox
      This change will be available in version 4.9.4
      Git Commit
    • 310613: Rendering of window decoration preview is broken/rendered white/partial
      This change will be available in version 4.10 Beta 2
      Git Commit
    • 309647: KWin uses incorrect function prototype for glXSwapInterval
      Git Commit
    • 309765: Closing a tabbed window gives focus to an other, but doesn’t raise that
      Git Commit
    • 310363: problem with extendedWindowBorders and dragAndDrop

    New Features

    • 307721: Make use of KDecorationDefines::ExtendedBorderRegion in shipped decorations
      Git Commit
    • 308994: Move ExtendedBorderRegion to stable API
      This change will be available in version 4.10
      Git Commit

    Tasks

      Fallback mode in KDE Plasma Workspaces

      Recently there has been a lot of buzz about non-composited fallback modes in various Desktop Shells and of course I have been asked several times about the fallback modes in KDE Plasma workspaces and whether they would be removed, too. Now instead of answering the same question again and again I decided to write a blog post to discuss the situation in more detail.

      The first thing to notice is that KDE Plasma workspaces do not have a non-composited fallback mode in the way GNOME Shell or Unity used to have. The main difference is that our window manager (KWin) is able to act as a non-composited, XRender based compositor and OpenGL (ES) based compositor. This means that we do not have to maintain two window managers in order to provide non-composited setups.

      The second major difference is that the Desktop Shell (either KDE Plasma Desktop, KDE Plasma Netbook or KDE Plasma Active) is not a plugin to the compositor but a separate application running in an own process. This allows to use a completely different window manager together with the Desktop Shell. Some years ago it was not that uncommon to use Compiz together with Plasma, though we see less and less such usage patterns (mostly caused by Compiz no longer being available in most major distributions except Ubuntu). This is a design decision which served us well and we do not plan to change it. Some time ago I brought up the topic, but more experienced developers (mainly Aaron) illustrated nicely the advantages of our design choices.

      Of course we need some code to be able to adapt to non-composited mode inside the Plasma workspaces. But this code would be needed anyway. Why? To answer this question we have to go back in time to when the development of Plasma had started – that is around 2006/2007. Back then OpenGL based compositing had been a rather new topic (I think I first heard about Compiz in 2004 or 2005) and it had only been possible with the binary blobs and hacks such as Xgl. The Intel hardware back then was not powerful enough and drivers were lacking, too. With other words: going an OpenGL-based only path seemed not feasible at that time and consider that the fallback modes in Unity and GNOME Shell got only removed in late 2012/early 2013. This is more than half a decade later – an eternity in IT. Also KWin did not enable compositing support by default till 4.2, so the first releases of KDE Plasma were non-composited by default.

      The solution inside Plasma was to make our themes aware of compositing. That is each theme contains an opaque element set which will be used when in non-composited mode. The fact whether compositing is used, is globally available through a standardized X11 manager selection. So whenever the compositing state is changed Plasma is notified and switches the used elements. Simple and elegant. This functionality served us quite well when we introduced the blur effect. Translucency is actually a very difficult topic. If you choose a too strong translucency level the text is no longer readable, if you choose a translucency fitted for text readability the translucency is hardly visible. The solution to this problem is the blur effect. It provides easily readable text even with strong translucency levels. But even today we do not enable the blur effect by default on all hardware as it is an expensive effect and we would not dare to enable it on embedded devices (personally I doubt that Windows 8 removed the blur because the designers disliked it). So we see we need themes with different levels of translucency depending on whether blur is available or not. The design decisions for the Plasma themes provided us the solution directly. As well it means that even if we would drop the non-composited mode we would have to keep our design to support the blur selection.

      For most of the applications it hardly matters whether the desktop is composited or not. Only very few applications use the alpha channel in the first place and if they want to use it, everything’s nicely abstracted inside Qt.

      Inside the window manager it also doesn’t really matter. Of course our window decorations are aware of whether compositing is used or not and especially Oxygen makes use of it by providing an adjusted look for the non-composited case, so there we have some overhead, but except that there are hardly any adjustments.

      This also means that we would not gain anything from requiring compositing. The compositor is a separate module inside the window manager which just gets started by the window manager on start-up. It lives more or less for itself and is just notified when a new window is added to the window manager and so on. Nothing inside the window manager really depends on the compositor. That means it would be more work to get KWin requiring compositing than to keep supporting the non-composited mode. And having the non-composited mode around allows us to do things like turning compositing off when running games or heavy OpenGL based applications such as Blender. So if you want to get some of the now finally available games for Linux, KDE Plasma should be your primary choice to enjoy the game. I have also heard of users switching to KDE Plasma because we still provide non OpenGL based setups.

      What remains is the question of what will change with Qt 5? Obviously not much. Plasma will continue to provide a non-composited and a composited theme, but Plasma itself will require OpenGL due to being based on QtQuick 2. I do hope that llvmpipe will be sufficient for Plasma in case of non available drivers. The same is true for KWin: our QtQuick based elements will require OpenGL 2, but that does not mean that we will require OpenGL based compositing. We will still provide non-composited mode and if the XRender based compositor get’s ported to XCB (we have lots of work there to get involved 😉 will continue to provide XRender based compositing as well as OpenGL 1 and OpenGL 2 based. Since the refactoring of the OpenGL based compositor I do not see much difficulties with keeping the OpenGL 1 based compositor around, though if it turns out to not be used anymore, it might be removed.

      The last remaining question is what will change with Wayland? Obviously Wayland requires to have a compositor, but it does not require us to stop supporting X11. KWin will continue to be an X11 based window manager allowing you to not use Wayland at all. And even if you choose to use a Wayland based KWin nothing says that it needs to be a compositor on top of OpenGL. Whether we will provide non-OpenGL based compositors for Wayland is a question for the future, though.

      A final remark: this blog post describes the situation inside the KDE Plasma workspaces and the design decisions we have done. This is not a critic at the design decisions other projects have done and I am not able to judge whether their decision is right or wrong and it is completely irrelevant what my opinion is on their decisions.

      What is a Desktop?

      A few days ago I started to work on a part of KWin which made me wonder what do we mean with the word “desktop” in the context of a window manager such as KWin. Of course in the sense of a window manager one means “Virtual Desktops” when speaking of “desktop”. Wikipedia says about virtual desktops:

      In computing, a virtual desktop is a term used with respect to user interfaces, usually within the WIMP paradigm, to describe ways in which the virtual space of a computer’s desktop environment is expanded beyond the physical limits of the screen’s real estate through the use of software.

      Inside KWin we identify the virtual desktop through mostly two properties in our Workspace class: currentDesktop and numberOfDesktops. In the X11 world the usage of virtual desktops is furthermore specified through the Extended Window Manager Hints (EWMH) which defines the root window property _NET_NUMBER_OF_DESKTOPS as:

      This property SHOULD be set and updated by the Window Manager to indicate the number of virtual desktops.

      And the root window property _NET_CURRENT_DESKTOP as:

      The index of the current desktop. This is always an integer between 0 and _NET_NUMBER_OF_DESKTOPS – 1. This MUST be set and updated by the Window Manager.

      As we can see the naming inside KWin is influenced by the specification which is implemented.

      Normally an X11 window manager implements the “virtual space” by putting windows on a virtual desktop. This is controlled in KWin inside the Toplevel class by having a property called desktop which directly reflects to the EWMH specification’s property _NET_WM_DESKTOP:

      Cardinal to determine the desktop the window is in (or wants to be) starting with 0 for the first desktop. A Client MAY choose not to set this property, in which case the Window Manager SHOULD place it as it wishes. 0xFFFFFFFF indicates that the window SHOULD appear on all desktops.

      The last aspect of the specification tells us that the desktop number “-1” is used to say that a window is on all desktops. Inside KWin we map that to a boolean property onAllDesktops.

      When looking at the source code of Toplevel related to desktops it is very easy to get confused due to the two following methods:

      bool isDesktop() const;
      int desktop() const;
      

      So there is both a boolean and an integer property called “desktop”. That does not make any sense. How can a desktop be a boolean value? Looking at the Q_PROPERTY value helps us to resolve the confusion: the boolean property is there called “desktopWindow” which refers to a window type as provided by the EWMH specification:

      _NET_WM_WINDOW_TYPE_DESKTOP indicates a desktop feature. This can include a single window containing desktop icons with the same dimensions as the screen, allowing the desktop environment to have full control of the desktop, without the need for proxying root window clicks.

      In the KDE world that is our plasma-desktop application. A more modern name would be “shell” as we nowadays speak of Desktop Shells. Funnily enough a desktop window is normally not on any desktop.

      In order to get access to the desktop shell there should not be any windows in front of the desktop. To provide easy access there is the concept of “showing the desktop”. All windows are temporarily removed when entering that mode and restored afterward. Inside KWin this is controlled by the boolean property showingDesktop of the Workspace class which is again influenced by the EWMH property _NET_SHOWING_DESKTOP:

      Some Window Managers have a “showing the desktop” mode in which windows are hidden, and the desktop background is displayed and focused. If a Window Manager supports the _NET_SHOWING_DESKTOP hint, it MUST set it to a value of 1 when the Window Manager is in “showing the desktop” mode, and a value of zero if the Window Manager is not in this mode.

      Overall we see that inside KWin we have three completely different concepts denoted by the word “desktop”:

      1. Virtual Desktops
      2. A window which is the Desktop Shell
      3. Showing Desktop Shell Mode

      I can imagine that for developers having a look at the code for the first time this can be quite confusing. We see here a general problem in programming when one does not clearly define the concept in the naming. In this case the naming is fuzzy and can only be understood by someone with domain knowledge.

      Now how come I wrote this blog post? I started to further refactor Workspace and split out the handling of virtual desktops into a VirtualDesktopManager. This manager is supposed to take care of all aspects of virtual desktops like telling us how many there are and which is the current. While looking through the code I noticed how many methods there are with “desktop” in it which have nothing to do with virtual desktops. That made me wonder what else a desktop can be except a virtual desktop.

      It’s still quite some work till that code will be ready especially as I want to add unit tests to the new Manager but the improvements to the overall code base are already visible. The name makes clear that it is about Virtual Desktops and not about the Desktop Shell or the Showing Desktop mode and due to the class being just about Virtual Desktops the smurf-naming of all methods and properties could be removed. Much cleaner and easier to read. And of course the Workspace class is again losing a few hundred lines of code which is always a positive thing.

      This week in KWin (2012 week 44, 45)

      The last two weeks have been very important in the KWin development area. First there was the release of 4.9.3 which includes a very important performance bug fix for Mesa 9.0 Intel users. If you had problems please consider an upgrade.

      On Thursday we had the hard feature freeze and many features got merged in during that period. Bellegarde Cédric merged in the appmenu support, allowing to have the window’s menu inside the window decoration. I love it as it’s very clean and I hardly use the menu in any application.

      Fredrik merged in the initial port from XLib to XCB. This is an important step on the road towards Qt 5 support inside KWin and will probably require still quite some work during the 4.11 cycle.

      Casian Andrei’s Google Summer of Code project on color correction got merged in as well. Unfortunately the merge did not go well, so there is still some work to do before the beta release. I hope that I can point to some documentation how to setup a color corrected system very soon.

      We have received a nice performance improvement for moving windows when using compositing. This should help alleviating some choppiness when using vsync.

      I merged in an improvement to window decorations, so that they can inform the compositor when they are not translucent. This improves the situation for rendering e.g. a maximized window with Oxygen but is most important for the new Plastik QML decoration which is not using translucency at all.

      Due to so much going on during these two weeks I’m sure that I have forgotten to mention something important. This could be summarized as “I don’t like feature freezes” – it’s so un-git.

      Summary

      Bug Fixes

      • 308633: Window tab group separated in shaded windows
        Git Commit
      • 308759: Forgotten “${…}” witihin CMakeLists.txt
        This change will be available in version 4.10
        Git Commit

      New Features

      • 102607: Display application menu and title bar side by side for maximized windows
        This change will be available in version 4.10
        Git Commit
      • 296773: GHNS support for Scripted Effects
        This change will be available in version 4.10
        Git Commit
      • 308995: Support shortened titles like in bespin in all decorations
        This change will be available in version 4.10
        Git Commit
      • 308990: Animate Window Maximize/Restore
        This change will be available in version 4.10
        Git Commit
      • 266596: Add support for appmenu-qt
        This change will be available in version 4.10
        Git Commit

      Notice for users of KWin master

      With KWin master as of today the configuration of the Translucency Effect changed. It used to have translucency values in the area [0.0, 1.0] which got changed to [0, 100]. If you rebuild and just restart KWin it might be that you do not see any windows at all, because the windows are completely translucent.

      To circumvent this problem run the KConfig Update application in $KDEDIR/lib/kconf_update_bin/kwin_update_settings_410 or just log out and log in again.

      Users not running master are of course not affected by the change, the KConfig Update handles it correctly on first login after update.

      This Week in KWin (2012, week 40-43)

      First of all I want to say sorry for not providing an update for the last few weeks, which makes this post more a “This month in KWin” than a “This week in KWin”. There are many reasons why I haven’t provided an update, one of them is that not that much has happened, as new features were merged in just this week and given that 4.9 has been out for quite some time not so many new bugs are reported.

      Since Thursday we are in soft feature freeze, which means that only features listed in the Planned Feature Document are allowed to enter master. And there are quite a few nice additions which went into master lately. We have two new effects: one to animate when a mouse click has been performed. It’s a really nice effect especially for screen casts. The other one is a small JavaScript effect which animates the maximize window state change. If you don’t want to wait till 4.10 for this effect: it’s compatible with 4.9 and can be downloaded.

      This brings me to the next topic: finally the categories on kde-look.org for our new scripted elements have been created which means we get GHNS integration. Luckily I prepared the code for Scripts and Window Switcher Layouts for 4.9 and the download button was just visually hidden. Now that the integration works, I pushed a change for 4.9.3 to show the button. For scripted effects this had not been prepared, but GHNS integration will be available in 4.10.

      Given that GHNS for effects works and I really want to see many effects being developed, I was finally forced to create the API documentation. Tutorials will be added sometime soon, also including how to write C++ effects, my old tutorial is no longer up to date at all.

      Summary

      Bug Fixes

      • 307609: Zoom effect broken in master
        This change will be available in version 4.10
        Git Commit
      • 307866: kwin fails to build when the GLES support is disabled
        This change will be available in version 4.10
        Git Commit
      • 308248: Incorrect offset for decoration-maximized elements
        This change will be available in version 4.9.3
        Git Commit
      • 308283: [JJ]: DimInactive effect does not update on config changes
        This change will be available in version 4.9.3
        Git Commit

      New Features

      • 183996: Add a rule to select the screen
        This change will be available in version 4.10
        Git Commit
      • 296773: GHNS support for Scripted Effects
        This change will be available in version 4.10
        Git Commit
      • 296774: GHNS support for KWin Scripts
        This change will be available in version 4.9.3
        Git Commit
      • 297636: GHNS support for Window Switching Layouts
        This change will be available in version 4.9.3
        Git Commit
      • 306436: GLPlatform should recommend either OpenGL1 or OpenGL2 compositing
        This change will be available in version 4.10
        Git Commit
      • 308990: Animate Window Maximize/Restore
        This change will be available in version 4.10
        Git Commit
      • 309006: Mouse Click effect
        This change will be available in version 4.10
        Git Commit

      Tasks

      • 297634: Request category for scripted KWin Effects on kde-(look|app).org
        This change will be available in version 4.10
      • 297635: Request category for KWin Scripts on kde-(look|app).org
        This change will be available in version 4.10
      • 297637: Request category for Window Switcher Layouts on kde-(look|app).org
        This change will be available in version 4.10

      [Help KWin] Fix Warnings

      Today I once more present some easy tasks to help the KWin development. This time it is a small coding task, though it’s not a very difficult task, but a very important one.

      As you might know there is a new C++ standard available, which is called C++11. This standard provides quite some nice and useful additions to the language which we would like to use.

      Unfortunately the new standard is not completely backwards compatible and there are some usages inside KWin which would no longer compile if we would enable C++11. This used to be totally valid code which did not even raise a warning. With gcc 4.7 we nowadays get a warning for all these code fragments which would not compile with C++11.

      We need to fix those warnings, because we want to use C++11 in future and because they make it more difficult to spot the “real” warnings.

      Therefore I set up a wiki page which contains all the warnings the compilation of KWin is currently causing and I would like to fix them all and that’s an easy way to help.

      All you need is a current checkout of KWin and you need to be able to compile it with (at least) gcc 4.7. Please follow the instructions about building KWin. When you work on a warning just set the row in the table on the wiki page to InProgress and add yourself to the contact information. Please do this step as it prevents that multiple people start to work on it. Once you have a warning (or multiple) fixed, just open a review request on Review Board for group KWin.

      If you work on it, please concentrate on warnings mentioning C++11.

      Themen fuer Einfuehrung in Kubuntu auf der Ubucon gesucht

      Ich bin gerade dabei mein Demo-System fuer meine Einfuehrung in die KDE Plasma Workspaces auf der Ubucon am Samstag vorzubereiten und wollte dabei noch einmal kurz daran erinnern, dass ich immer noch gerne Themenvorschlaege annehme zu was ich denn im Vortrag alles beruecksichtigen soll.

      Also falls jemand einen Wunsch hat, einfach in den Kommentaren hinterlassen, dann kann ich was vorbereiten. Ansonsten einfach zu meinem Vortrag kommen und die Frage/Antwort Session nutzen 😉

      A journey through virtualization

      This weekend I had a look on enabling the OpenGL compositor when running in a virtual machine. My assumption was that given that the next version of Ubuntu is going to require OpenGL, there should be no problem with getting OpenGL running in a virtual machine.

      I normally use KVM when I have need for a virtual machine running a Linux guest. As far as I know you cannot get OpenGL with this technology, so I hadn’t looked into it for quite some time.

      My first attempt was to just use the project neon weekly build. Unfortunately I failed to convert it to a VirtualBox image, nevertheless I decided to run it and verify that KVM does not support OpenGL. Well I was rather surprised once the machine was up to see that OpenGL was functional, but well it was slow. Restarting KWin showed me that there is a missing slot (which I am aware of and is already fixed in one of the pending reviews) in master which makes the fallback to XRender not work, but KWin just uses llvmpipe. OK, result incorrect, but at least validated that KVM is not working.

      I then decided to try VirtualBox with an install of Kubuntu Natty. Install went well but no OpenGL available. The Xorg log file told me that VirtualBox does not know the XServer version. Installed the latest version of VirtualBox, installed the latest version of guest additions in the Kubuntu guest, but no success: driver does not work.

      So I decided to test with an outdated system, aka Debian Testing as I’m also running this on my workstation. Here I was more successful. After installing the system in the virtual machine OpenGL worked out-of-the-box. And what surprised me even more was that OpenGL in KWin worked when using KWIN_DIRECT_GL=1 and KWIN_COMPOSE=O. This means OpenGL works in general and it’s only blocked by KWin not knowing the driver.

      KWin with OpenGL in VirtualBox

      The main reason is that KWin does not use direct rendering if it finds an unknown driver and VirtualBox only provides OpenGL in direct rendering mode. If LIBGL_ALWAYS_INDIRECT is set, it falls back to Mesa’s software rasterization and KWin sets this environment variable if it doesn’t know the driver.

      This meant I had to perform some coding to recognize the driver and had to test it in the virtual machine. Thanks to host and guest running the same version of Debian I was able to setup a NFS share and just use my normal development version of KWin.

      After a little bit of hacking and fighting with NFS I got the driver reported correctly and KWin running with OpenGL without using environment variable hacks. But VirtualBox’s driver is not complete. Some methods we (optionally) use from GLX 1.3 are not implemented and trying to use it resulted in warnings. That unfortunately needed a hack inside KWin (it’s small and well contained, so it’s not much of an issue).

      With VirtualBox working I decided to also look into VMware and have installed VMware Player for the first time in years. Converted my Debian image into a VMware compatible format, enabled 3D acceleration and started the system, just to be presented with warnings that 3D is not working.

      The Internet told me to add

      mks.gl.allowBlacklistedDrivers = TRUE
      

      to the vmx file. But that did not resolve the issue. The two warnings went down to one, but still a warning. Apparently one has to install libtxc-dxtn-s2tc0 in order to get 3D support.

      Installed and no warnings: yeah. Started the system, but no OpenGL. Installed the guest additions, but it told me that the system already has X11 integration. Looked into the Xorg log and yes it complained that something is wrong with the module. So no OpenGL inside Debian guest.

      KWin with OpenGL in VMWare player

      Resolved to my previous plan of trying Kubuntu 12.10. Started it in a live session and KWin is not composited. But glxinfo reported a driver, so I restarted KWin with KWIN_COMPOSE=O and there it was: OpenGL running also in VMware.

      Looking at KWin’s output I was quite happy to see that it is a Gallium3D driver, which means we don’t need any adjustments at all. KWin uses OpenGL out-of-the-box, it was only not running, because of the live session of Kubuntu. So all that was needed was adding some detection code, that KWin doesn’t print out “unknown” in the debug output. Unfortunately using my KWin from Debian did not work, so I could not yet verify the output, but that can be done once it hit project neon.

      Once the patches are merged into master KWin will use OpenGL in virtual machines – if supported. But given the experience it looks like at least on Linux hosts OpenGL is basically not supported in default setups. I would like to also support Parallels and Windows Virtual PC, but am of course lacking both required host operating system and licenses.