In GNOME based environments, under X11, the average background color of the wallpaper can be obtained with
xprop -root | grep _GNOME_BACKGROUND_REPRESENTATIVE_COLORS
It gives an output like
_GNOME_BACKGROUND_REPRESENTATIVE_COLORS(STRING) = "rgb(65,70,61)"
This is the method Unity used to make the dash have the same color as the wallpaper.
However, xprop
does not work in Wayland, and _GNOME_BACKGROUND_REPRESENTATIVE_COLORS
would not work in KDE.
Is there any way to get the average color/accent color in KDE with Wayland as well as X11?
I want to use this color to make an app have ``chameleonic" background color.
Kirigami has this function, but I’m not aware of a command-line tool to get it easily.
However if you’re writing an app, you don’t want to use that anyway; you want to use the proper API to access the functionality! You can access it with Kirigami.ImageColors
. See the examples in examples/Image Colors · master · Frameworks / Kirigami · GitLab.
The only challenge here will be getting the wallpaper to use as the source. I’m not immediately sure how to do this.
I found another method that works in wayland as well as X11.
The command
gsettings get org.gnome.desktop.background picture-uri
gives me the location of the wallpaper image. Then, I can use imagemagick to get the color
convert "$(gsettings get org.gnome.desktop.background picture-uri | sed -e "s/'file:\/\/\(.*\)'/\1/")" -resize 1x1 txt:- | awk 'NR==2 {print $3}'
Similar methods would work for Cinnamon, MATE and XFCE as well.
Does KDE store the location of its wallpaper somewhere?
Then I can write a simple script in my code to extract the color for every desktop environment.
It’s not quite that simple, since the active wallpaper may not be an image; we support arbitrary wallpaper plugins.
But if it is an image, you’ll find it in ~/.config/plasma-org.kde.plasma.desktop-appletsrc
. Search for Image=
.
Keep in mind that each screen has its own wallpaper, so you might find several.
1 Like
You did say “an app” not “my apps” so I guess maybe you’re actually developing something new here, but if it’s the end result you’re after, there’s GitHub - luisbocanegra/kde-material-you-colors: Automatic color scheme generator from your wallpaper for KDE Plasma powered by Material You
1 Like
Just like Nate said, getting what is actually being displayed is not that simple for wallpaper plugins that aren’t a simple static image/color, the way I ended doing it for kde-material-you-colors was with a desktop screenshot fallback but even that isn’t perfect, see Getting wallpaper from Plasma is complicated and prone to errors · Issue #187 · luisbocanegra/kde-material-you-colors · GitHub
I think for this to work reliably Plasma would need to provide a method to query the current view of the desktop background as an image. There is also qdbus org.kde.plasmashell /PlasmaShell org.kde.PlasmaShell.color
but that one requires enabling accent color from wallpaper in the color scheme settings.
1 Like
Thank you. That should cover most use cases
Not quite. I recently rewrote this weather app (Typhoon), and I want to add a Chameleonic background feature.
Thank you all. I will get back if something goes wrong, and will post when the feature is ready.
1 Like
I wrote this function to extract the path to the wallpaper
and this lines of code turn the wallpaper into a color code using imagemagick
The app was recently featured in OMG Ubuntu Developer Revives Iconic Desktop Weather App for Linux - OMG! Ubuntu