Quick KDE KWin hack: Ignore global shortcuts except alt-tab

From time to time a pet peeve can reach a critical level of annoyance at which it starts to irritate. You google it, hoping to find a solution or at least some allies, but if none turns up and you’re out of time, you simply give up and hope a solution will magically manifest itself one other day. But what if that day never comes? Luckily for us, open source enthousiasts, we can do something about it ourselves 🙂


I’m quite an avid shortcut user. Linux/KDE is an environment where this type of user feels right at home. Not only do most actions in a software have a shortcut, you can also define lots of system-wide or global shortcuts. Kwin, KDE’s window manager defines quite a few out of the box.


This is all fine and dandy until you want to use this cross-platform software which you got used to in a different environment (i.e. windows at work) and you want to start using it at home. When the application is not (KDE) shortcut friendly or you are so used to the windows keymap that it’s a pain to learn a new scheme, you start to feel frustrated. Learning a new shortcut scheme seems the best solution but this doesn’t work well when you have to maintain 2 shortcut schemes in your head, depending on your environment (home vs work, your computer at work versus a colleague’s computer).

A typical example here would be some IDE, for example Intellij IDEA. Although the IDE does provide a KDE keymap by now, I started using it ages ago when there simply was no alternative keymap (nor a community edition or even official linux version, I guess). Also, I used linux only occasionally back then. These shortcuts are hard-wired by now and it is already hard enough to keep in mind whether I’m using Intellij or Visual Studio.

Another possibility is that the application really needs that much shortcuts that it just can’t bother with the shortcuts which may or may not be defined by the environment or workspace. One example of such complex application is Blender. Try it out and you’ll see what I mean. 😉

KDE, being the configurable desktop environment, does offer some configuration settings. For each window, Kwin allows you to define rules which match certain windows / applications which creates a config. Using this config, you can configure special window attributes. One setting is to block all global shortcuts.

This allows you to use your favorite application with its favorite native shortcuts. Of course, most people use more than 1 application at the same time. However, since all global shortcuts are blocked, the alt+tab shortcut to switch windows is blocked too. Alt+tab is not a special shortcut to KDE, it simply is a shortcut that happens to be assigned globally to the “Walk through windows” action exposed by the KWin component to the System Settings. Lacking any window switching shortcut, you adapt and start using the mouse to switch applications. There are times you cope just fine. But there are other times it is just one thing too much that annoys you. 🙂


So how to fix this? Just like any other problem you have with an open source application: fetch the source, fix and build! 😉

Since I just wanted a quick fix (I thought, let’s check this out for 30 mins, which turned out to be a lot longer of course), I chose to patch the behavior of the “Ignore global shortcuts” setting to exclude the Alt+Tab shortcut (more precisely, the shortcut currently assigned to the “Walk through windows” action). I briefly investigated KWin’s scripting abilities but it turns out the required functionality is not exposed.

I will now document the process, which took place on opensuse leap 42.3. You may want to tune out now if you don’t care about the gritty tech details. 😉

Where is the source?

I thought it had to be kwin, right? So I checked out the source from github and started searching for “Ignore global shortcuts”. It turned out to just call something in kglobalaccel which is not part of kwin.

Getting my hands dirty, I first fired up a VM I had lying around in order not to f*ck up my currently running system. Next I installed Qt Creator to easily navigate the code. Also, never forget you have to checkout the tag for the version you are currently running! (can be a treasure hunt by itself)

Browsing the source, I finally find a possible tweaking point in the src/runtime/component.cpp -> deactivateShortcuts method. It disables all shortcuts when a window is entered which has a “Ignore global shortcuts” rule. So I simply added an exclusion for the “switch windows” action.

Building a patched rpm

Time to try it out! In order to build it, you will need to install its dependencies. On an rpm based system, the easiest way to go forward is to do a “sourceinstall” of the rpm in case. For that, we first have to know which rpm contains the affected shared object (.so file).

You can take different routes to pin point the rpm. I checked the CMakeLists.txt to see what the output targets were. When you build, you can also see the class pass by and check into which library it gets linked into. Using that .so file, you can find the rpm using “rpm -qf <.so>”

An alternative way would be to find a kde related rpm matching “global” and then checking its contents (using “rpm -q –filesbypkg <rpm>”) for the .so file.

Once you know the rpm, you can easily install all required build dependencies by issueing a zypper sourceinstall command: “zypper si <rpm>”

The hard part: logging

I wanted to add some debug output to see if I was looking at the right place in the source base and how frequently the code got called. Now things got messy. You’d think patching the code was the hard part, guess what.. 😉

I had played with logging before in KDE, but of course things have changed with KDE 5. Nowadays, KDE uses Qt’s default logging mechanism. It meant figuring out the logging category used by kglobalaccel and finding a way to activate it. The logging category was nicely tucked away in logging_p.h: “kglobalaccel-runtime”. Activating it seemed to be trickier. According to the Qt documentation, you can alter the log level through an env var QT_LOGGING_RULES. Since I was adapting a core component, I needed to set the env var before logging in. On opensuse you can create a file /etc/profile.local which gets sourced by /etc/profile.

I added the env var and it seemed to work (=showed up), unfortunately still no logging. More precisely, nothing showed up in ~/.xsession-errors-:0. I started adding log statements all over the place, analysing the .so file to check whether my modified method was actually included in it (readelf -Ws libKF5GlobalAccelPrivate.so.5.32.0  | grep deactivate), etc.. Until I realised I didn’t check the journal (journalctl -b -0) yet, there it was. 🙂 Bonus points: the code change had its intended effect!

End result

So there I had it, a working patch WITH logging ⇒ pure SATISFACTION 🙂

Feel free to share this satisfaction by downloading the .so and installing it in /usr/lib64 (use at own risk). I’ve been using it for 2 months now without problems. It’s a good hack until a more fundamental solution is in place. First steps have been taken! 😉

Wiimote experiment

Okay, so I finally got to it. A few months ago I bought a wiimote to play a bit with the api’s floating on the net. It was until yesterday that I actually tried a driver, and since that seemed to work okay, I decided to give it a try myself. My simple goal, being an app plotting the raw inputs. However, it took me a 2 hours more than expected (1 =)) and also a lot more blood, sweat and tears. 😉 particularly because I made a lot of mistakes due to me being too tired 😉 So I will keep it short for now as I want to go to sleep.

I choose the wiiuse library as it seemed adequate for the job and still active (and even cross platform!). I started from the included example and tried to wrap it into a Qt app (hence I named it example-qt ;)). The obvious choice for drawing is using QGraphicsView. However, for once ;), I took the effort to see if there are no existing Qt graph plotting libraries. And this just happens to be the case. 🙂 Meet the excellent QWT lib. It couldn’t be more fit for the job. The site is (almost) nothing but the api docs, but that seemed sufficient. One second I thought this lib would not be qt4 ready, but it has been ported!

Quite a few seconds and segfaults later 😉 I got this:
wii experiment

Nothing fancy, but it does show the roll and pitch!! =)

Note: the wiimote survived the experiment 😉

Netbean probs

Some while ago, I start coding a feed reader in J2ME to run on mobile phones. After some searching, it seemed like Netbeans would be the way to go.. They provide a nice UI builder including modeling of the flow between the different screens, tailored towards cell phones. Also, it seems the Sony Ericsson SDK provides nice integration with Netbeans.

My favorite java IDE IntelliJ doesn’t seem to support mobile development at all. (for the record, I wouldn’t use IntelliJ if I had to pay for it myself ;)) The next best thing, Eclipse, seems to be less mature in this area, although they are progressing fast. So Netbeans it became.

To my surprise, I even found a tutorial on the netbeans site which already gave me a bootstrap to my task! 🙂

So, where’s the problem?

Well, I set up netbeans and created a project and all, so I could get to serious work on my 2h train trip. Unfortunately, I didn’t manage to write a single line of code! 🙂 As soon as I opened my laptop, the Netbeans IDE seemed to have become very unresponsive! Opening a menu could take 10 seconds, scrolling through the code is impossible. I couldn’t believe my eyes at first, so I rebooted because I thought my laptop was having trouble waking up after having the short nap. However, not improved. I had to give up.
At home, I searched the internet, and indeed, netbeans has problems with my ATI X600 ‘s PowerPlay function! Who would have imagined that. 😉 Especially since this is the only Java app I have trouble with… Anyhow, just disabling the PowerPlay function solves the problem! It’s probably related to my ATI drivers, but since I have a fricking Dell laptop, I’m not allowed to install drivers other than from Dell, so, as you can imagine, Dell never supplies updates to the driver! If anyone knows how to circumvent the checks going on in the driver installer from ATI, please let me know…


So, while I’m at it, why not add a first one. 😉 This is actually most recent. It is a very simple tool to inspect the ROT. The ROT (Running Object Table) is a system wide table in Windows, into which objects can register themselves, making them visible to and accessible by other applications. Inspect could be the wrong term: the tool just lists all objects in the ROT by their display name. There is a refresh button so that you don’t have to restart it all the time. 😉