Plasma/How to create a Unity-like look and feel theme using Plasma’s Desktop Scripting API
In short, desktop scripting lets you control and interact with a Plasma user interface shell via javascript like API. As you may know, inside your L&F theme (contents/layout) there is a file called org.kde.plasma.desktop-layout.js which controls your Plasma setup. If you are using Look and Feel Explorer that file and its content is created automatically.
First you need to create a proper L&F package structure with all the files you need and save it in:
/home/[yourusername]/.local/share/plasma/look-and-feel/
You can use Look and Feel Explorer or modify an existing theme like United. Next open org.kde.plasma.desktop-layout.js in your favorite text editor. I am using Kate (Plasma’s default text editor). At the beginning of your file you need to add:
var plasma = getApiVersion(1)
Ok, now let’s create a new plasma panel located at the top of the screen:
panel = new plasma.Panel panel.location = "top"
Add the height property for the panel (gridUnit * 2 is a default value used in plasma)
panel.height = gridUnit * 2
Once you have a new shiny panel you can add some widgets.
To get a list of widgets installed locally (for example from the KDE Store), do this:
kpackagetool5 --list --type Plasma/Applet
To get a list of all installed widgets (system wide):
kpackagetool5 --list --type Plasma/Applet --global
Once you have a list of installed widgets, you can use the panel.addWidget method to add them to our top panel.
panel.addWidget("org.kde.plasma.appmenu") panel.addWidget("org.kde.plasma.panelspacer") panel.addWidget("org.kde.plasma.systemtray") panel.addWidget("org.kde.plasma.digitalclock")
And here is the result:
You need to add another spacer on the left side of the appmenu (otherwise the appmenu will overlap with the left panel). You also need a user switcher applet on the right side of a digital clock. Let’s start with the spacer:
var spacer = panel.addWidget("org.kde.plasma.panelspacer")
Now our global menu is located at center of the panel. This is because the default spacer takes up all available space in a panel. You need to change that by setting the expanding value to false. You use the currentConfigGroup property and writeConfig method to modify config file /home/.config/plasma-org.kde.plasma.desktop-appletsrc.
var spacer = panel.addWidget("org.kde.plasma.panelspacer") spacer.currentConfigGroup = ["Configuration", "General"] spacer.writeConfig("expanding", false)