This forum has been archived. All content is frozen. Please use KDE Discuss instead.

How does Plasma change theme under the hood?

Tags: None
(comma "," separated)
erayerdin
Registered Member
Posts
1
Karma
0
I wonder how Plasma changes theme under the hood.

I see lookandfeeltool which changes theme "lookandfeeltool -a <themename>" yet I do not know how it does that. Oddly, I cannot seem to find the source code for it. It is probably inside somewhere of "plasma-desktop" repo.

One thing came to my mind was to check if it uses DBus. I did:

Code: Select all
strings "$(which lookandfeeltool)" | grep "org.kde"


which printed

Code: Select all
org.kde.lookandfeeltool
org.kde.kdecoration2
org.kde.KLauncher


org.kde.lookandfeeltool and org.kde.kdecorations2 are not in session bus. org.kde.KLauncher is there but it does not have a method to change the theme.

So, I have multiple questions:

  • How can I change Plasma color schema, widget style etc. programmatically?
  • How can I get a list of color schemas, widgets programmatically? Where are these stored in the filesystem?

KDE is great and all but when it comes to program it yourself, it seriously lacks documentation.

Thanks in advance.
User avatar
Mamarok
Manager
Posts
6071
Karma
16
OS
viewtopic.php?f=305&t=165711 might also be of help


Running Kubuntu 22.10 with Plasma 5.26.3, Frameworks 5.100.0, Qt 5.15.6, kernel 5.19.0-23 on Ryzen 5 4600H, AMD Renoir, X11
FWIW: it's always useful to state the exact Plasma version (+ distribution) when asking questions, makes it easier to help ...
kde-cfeck
Registered Member
Posts
93
Karma
0
First, theming of Plasma isn't unified; it is splitted over several different theming elements, which are all handled differently. For an overview of theming elements, see my comment at https://www.reddit.com/r/kde/comments/b ... beginners/

If you are writing a KDE or Qt application, changes in theming (fonts, color scheme, widget style) are usually handled automatically via global Qt events (QEvent::ApplicationFontChange, QEvent::ApplicationPaletteChanged, QEvent::StyleChanged), so there is no pressure to document the process further.

Internally, these events are sent by Qt when Plasma's Qt platform integration plugin changes settings in each application. This plugin listens to D-Bus signals sent by the KCMs. The source is the documentation in this case; see https://cgit.kde.org/plasma-integration ... ttings.cpp and https://cgit.kde.org/plasma-integration ... gsdata.cpp

List of available fonts is handled by fontconfig library; available color schemes are in (/usr|~/.local)/share/color-schemes; available widget styles are handled internally by Qt reading the plugin folders, see https://www.reddit.com/r/kde/comments/g ... _location/
See also QStyleFactory::keys() documentation.

For theming elements that don't affect applications, but are private to Plasma (e.g. window decorations are handled by kwin, Desktop themes are handled by plasmashell) you would need to find the internals in the source of the relevant KCM pages.

For example, the desktoptheme KCM finds the list of available plasma themes in (/usr|~/.local)/share/plasma/desktoptheme, and notifies plasmashell via changes to its plasmarc config file, see https://cgit.kde.org/plasma-desktop.git ... smodel.cpp

If your application cannot use KConfig, because it doesn't use KDE's frameworks, you can use the kwriteconfig5 command, e.g.
Code: Select all
kwriteconfig5 --file plasmarc --group Theme --key name breeze-dark


Bookmarks



Who is online

Registered users: Bing [Bot], Evergrowing, Google [Bot], rblackwell