Rant: Desktop effects? Never more.
Disclaimer: this is a rant. I have been trying for the past few days to make desktop effects work and not use 90% of my CPU. I am frustrated, so this blog will step on people's toes. Maybe you shouldn't read it.
I remember when I was using KDE 3 and I enabled the desktop effects. The only objective of that was to have semi-transparent windows: I had just got a collection of nice wallpaper pictures, but what's the use if you never see the desktop? So I turned the feature on, and it worked -- more or less. There was a nice feature which you could set the transparency level differently for active and inactive windows, but once you clicked the Windows Operations menu (Alt+F3, the application icon in the top-left corner), the transparency level would become stuck for that window. To make matters worse, there was this one application that, if moved, would become 100% transparent. I had to be careful to change the level just after starting it, before doing anything in it.
But that wasn't too big a deal. After all, kwin in KDE 3 was never meant to have those effects. They were hackish.
Come KDE 4... I decided to continue using the desktop effects. After all, now kwin was meant to have those effects. The drawback was that kwin constantly used 40-90% CPU time, while doing absolutely nothing. I mean, the computer was idle, no windows had any activity, but it still would use CPU. Konsole takes 20 seconds to redraw if you try to resize the window. And to make matters worse, I can't use my wallpaper collection, because the slideshow mode always expands the pictures without considering the aspect ratio.
Someone in the office told me that XRender worked just as well, but without the CPU overhead. I have no idea why, but I just can't set that mode. Trying to change from OpenGL to XRender makes the entire desktop freeze: the helpful "you've changed configurations, do you want to keep them" dialog with a 15-second automatic cancellation doesn't even appear. But it does cancel, so it goes back to OpenGL. Trying to enable desktop effects with XRender gives me a message that it didn't work and the old configuration was restored.
I tried to debug kwin. Only to find out that you shouldn't do it from inside the X session. Everything freezes just after you press Enter on the "attach" line on gdb. So I switched to a virtual console, managed to attach to kwin, but the backtrace was useless due to glib appearing in the middle. Debugging the timers with glib is too difficult -- the Qt default event dispatcher is easier.
So I restart kwin without glib (QT_NO_GLIB=1 kwin --replace). Only to find out that that doesn't work. It took me a few tries doing that and doing killall kwin to get a new kwin running. And to my surprise, I couldn't find anything wrong with kwin under those conditions. Thinking I had done something wrong, I restarted KDE with glib turned off. And my suspicion was confirmed: turning glib off makes kwin use acceptable 1% CPU.
Performance was still bad, though. I mean, what's the point of having windows flying by when you switch desktops if all you get is two frames?
On Wednesday, Sebas blogged about NVidia releasing a new driver that fixed most of the performance issues. So I decided I would try, and I'd also try the many settings that presumably make performance better. So I downloaded version 177.67, built and installed; changed my xorg.conf to add the options that Sebas recommended; and restarted X. And for a while it appeared to be working correctly.
Until some Konsole windows started disappearing. No, wait, they weren't crashing or off-screen: they were just invisible. Yes, 100% transparent. I could even interact with them, but I couldn't see what was wrong. So... undo some of the modifications to xorg.conf and restart X.
Problem not gone. And to make it worse, some other windows started appearing black. Including the window decoration (borders, title bar, buttons). I assume it's the same problem affecting konsole, with the difference that konsole uses windows with alpha channels, thus making it go invisible instead of black. The interesting thing is that, when moving windows (I had an effect on to make them more transparent), the black window became slightly transparent! I managed to get most of the windows appearing when I minimise then restore the window. Not all, though (including one program I need for work).
So I try fiddle with my settings. I ran nvidia-settings to find out if I were using the correct driver. And to my surprise after starting that program, all windows stopped updating! Actually, they were updating, but I wasn't seeing them. If I clicked on another window, the window that had just become deactivated would update. So, yeah, I found a new interesting effect: freeze until focus lost.
Turning desktop effects off and back on helped. I had to do it twice because the second screen on my Twin View setup doesn't enable the effects on the first try.
Come today: I'm told that NVidia released a new version, 177.68, which fixes some bugs. So I go and upgrade the driver. And indeed things feel snappier. I can see the effects as they are meant to look like. However, the black windows don't go away.
I tried using nvidia-settings again. And a similar problem as yesterday started appearing. Only even worse than "redraw when focus lost". I could see the screen repainting from top to bottom, scan line by scan line. It took about 5 seconds (1680x1050). I don't think I've seen that happen since CGA was the norm!
Turning effects off and then back on (twice) fixed that problem.
But the black windows are still appearing. To almost all programs (konqueror, vmware-server-console, hooligan, etc.). Apparently Emacs isn't affected.
So my solution? Turn effects off. I need to work. I can't fight my system. After all, the whole point of the effects is to improve my user experience, not to make it worse. And I can't use wallpapers anyways...
And if that weren't enough, one or several kio_imap4 became runaway, printing a debug message from KIO::SlaveBase::waitForAnswer in an infinite loop. That exhausted my disk space in my /home filesystem, thereby making Kontact crash and lose all of its settings. I'm still synchronising my IMAP folders as I write this...
At least one good thing came out of this ordeal: I found out why kwin consumes so much CPU. If you're affected by this problem, turn glib support off in Qt. (export QT_NO_GLIB=1 before KDE is started, or compile Qt with the -no-glib option)
By the way, Konsole still lags in drawing, even with desktop effects turned off. That means it's not caused by the desktop effects.
Subscribe to our newsletter
Try Qt 5.15 LTS Now!
Download the latest release here: www.qt.io/download.
Qt 5.15 was developed with a strong focus on quality and is a long-term-supported (LTS) release that will be supported for 3 years.
Check out all our open positions here and follow us on Instagram to see what it's like to be #QtPeople.
Näytä tämä julkaisu Instagramissa.
Want to build something for tomorrow, join #QtPeople today! We have loads of cool jobs you don’t want to miss! http://qt.io/careers #builtwithQt #software #developers #coding #framework #tool #tooling #C++ #QML #engineers #sales #tech #technology #UI #UX #CX #Qt #Qtdev #global #openpositions #careers #job
Henkilön Qt (@theqtcompany) jakama julkaisu