Plasma/How to create a Unity-like look and feel theme using Plasma’s Desktop Scripting API

From KDE UserBase Wiki
Revision as of 21:57, 9 April 2018 by Łukasz Sawicki (lucas) (talk | contribs) (Created page with "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)...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

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)