About

The newest KDE plasma natively support blur, but it has many limitations, for example I can’t blur vim status line and firefox. This article tries to find a way to blur any window in plasma, like this:

demo


There is a much more elegant method to achieve this, see the comment for more information.


Preparation

To begin with, make sure you have already enabled blur effect via Kvantum and some themes that support blur, for example Sweet

desktop-demo

Script

I wrote a simple script that can launch application and blur the window automatically:

plasma-blur.sh:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/usr/bin/env sh

# Usage:
# ./plasma-blur.sh 'command' 'class' [transparency level]
# E.g.:
# $ ./plasma-blur.sh 'code' 'Code' 3

# Run in background
eval "$1 &"

# Blur
i=0
while [ "$i" -lt 18 ]; do
        if [[ "$i" -lt 6 ]]; then
                sleep 0.1s
        else
                sleep 0.2s
        fi
        xdotool search -classname "$2" | xargs -I{} xprop -f _KDE_NET_WM_BLUR_BEHIND_REGION 32c -set _KDE_NET_WM_BLUR_BEHIND_REGION 0 -id {}
        i=$((i + 1))
done

# Transparent
i=0
while [ "$i" -lt "$3" ]; do
        qdbus org.kde.kglobalaccel /component/kwin org.kde.kglobalaccel.Component.invokeShortcut "Decrease Opacity"
        i=$((i + 1))
done

The first argument is the command to launch the application, the second argument is the class of the application window, and the third argument is the transparency level. The higher the transparency level, the more blurred the window will be.

For example, you want to launch vscode with blurred effect enabled, the first argument should be 'code'. To get the second argument, open vscode window and execute xprop WM_CLASS in your terminal emulator, then you’ll get something like this:

1
2
$ xprop WM_CLASS
WM_CLASS(STRING) = "code", "Code"

The first string is the instance name and the second string is the class name, so the second argument should be 'Code'.

For the third argument, don’t set it too high, otherwise the window will look very bad. Also, I’d recommend to use this script with a high contrast color scheme.

Let’s say we set the transparency level to 3, then the complete command is as follows:

1
$ ./plasma-blur.sh 'code' 'Code' 3

Here is the final result:

vscode-demo

Application Launcher

Now let’s create a .desktop file to launch blurred vscode.

1
2
$ cp /usr/share/applications/visual-studio-code.desktop ~/.local/share/applications/vscode-blurred.desktop
$ chmod +x ~/.local/share/applications/vscode-blurred.desktop

Then modify the Name and Exec entry:

1
2
Name=Visual Studio Code (Blurred)
Exec=/path/to/plasma-blur.sh '/opt/visual-studio-code/code --no-sandbox --unity-launch %F' 'Code' 3

Open application launcher and launch this application, you’ll get a blurred vscode.

Limitations

Honestly this hack is very dirty, the first while loop will last for 3 seconds, then decrease the opacity of current window, which means this script won’t work if the startup time last more than 3 seconds or you switch to another window in this 3 seconds.

Glad if someone else can help me improve this script.