kde-material-you-colors icon indicating copy to clipboard operation
kde-material-you-colors copied to clipboard

Getting wallpaper from Plasma is complicated and prone to errors

Open luisbocanegra opened this issue 4 months ago • 5 comments

Currently there are two methods to get the current wallpaper, Plasma scripting API and KWin scripting API with the compiled helper.

Plasma scripting method requires wallpaper plugins to actually store the current wallpaper source in the configuration, some do, but most do not (because they don't need to). Also some may require special handling like Picture of the day or store wrong/outdated data, causing us to get the wrong colors.

The fallback screenshot method is more reliable, but also more resource expensive as it requires continuous snapshots and checking whether the image hash changed each time. It's also more complex, requires maintaining both KWin Script + compiled plugin that access the KWin's screenshot plugin. An example of this is the upcoming Plasma 6 KWin changes mentioned in https://github.com/luisbocanegra/kde-material-you-colors/issues/161

For all the problems above I have even considered dropping automatic detection from plasma and have the screenshot method executed manually by spectacle in combination of the show desktop shortcut with just a click on a button. That would be a downgrade but maybe an acceptable one?

Possible alternative (but still complicated)

Just recently found out about Plasmoid.containment.wallpaperGraphicsObject which is attached to widgets that are placed on the desktop, using grabToImage method is possible to store and save an image of what's currently shown as wallpaper.

Additionally to grabbing the image, wallpaperGraphicsObject could be recursively scanned for properties like imagePath, modelImage, color for some wallpapers where it returns an appropriate source.

The proposed solution is to create an invisible plasmoid to be placed on the desktop, process of adding it to every screen/(activity?) could probably be handled by the backend (Plasma scripting API) or done manually.

Then plasmoids would store the desktop preview to a temporary location (probably scaled down to save resources) and then the backend will make use of them.

It would be necessary to store from which screen/(activity?) the wallpaper is coming from for the backend to know that the current one is.

Additional context, should this be provided by Plasma?

Since there are already multiple utilities to set/set wallpaper/icons/colors in plasma, I believe a method to get the actual wallpaper source or even a image snapshot should exist too (currently it only returns their configuration as seen in qdbus org.kde.plasmashell /PlasmaShell org.kde.PlasmaShell.wallpaper 0), my plan to raise this idea to KDE developers to see that they think of that (maybe too niche?) feature in Plasma.

TL;DR Looking for a more reliable way to get the wallpaper source or considering dropping automatic detection in favor of a button to do it.

luisbocanegra avatar Feb 24 '24 00:02 luisbocanegra

I came here to open an issue about the wallpaper detection not working with wallhaven.cc wallpaper plugin, sometimes it would take a sceenshot which works but most of the time it is using that journalctl command.

after reading this, I can see the issue, the screenshot method is the most reliable currently and decouples wallpaper detection from the plugin, I think an option to only use screenshot method for detecting wallpaper would help with usability for people like me who don't use any of the supported wallpaper plugins until there is a stable API to obtain the current wallpaper.

on another note, plasma also has material-you but it only updates the color scheme colors, it can tint all colors with the extracted colors from wallpaper, perhaps letting plasma handle color extraction and simply taking the values from there would be easier than manual extraction, eliminating the issue of getting wallpaper.

color scheme options

image

example color scheme generated from wallpaper

the colors are also applied to the icon pack if supported (breeze does support it, icons shown below are from tela)

Screenshot_20240227_131510

Blacksuan19 avatar Feb 27 '24 19:02 Blacksuan19

I came here to open an issue about the wallpaper detection not working with wallhaven.cc wallpaper plugin, sometimes it would take a sceenshot which works but most of the time it is using that journalctl command

It's good to hear it works.

after reading this, I can see the issue, the screenshot method is the most reliable currently and decouples wallpaper detection from the plugin, I think an option to only use screenshot method for detecting wallpaper would help with usability for people like me who don't use any of the supported wallpaper plugins until there is a stable API to obtain the current wallpaper.

Sounds like a good idea. The only downside is requiring people who don't use Arch + AUR having to compile the helper but there's no way around that one.

on another note, plasma also has material-you but it only updates the color scheme colors, it can tint all colors with the extracted colors from wallpaper, perhaps letting plasma handle color extraction and simply taking the values from there would be easier than manual extraction, eliminating the issue of getting wallpaper.

color scheme options

Image

image

example color scheme generated from wallpaper

the colors are also applied to the icon pack if supported (breeze does support it, icons shown below are from tela)

Image

Screenshot_20240227_131510

I also thought of adding that as an option, didn't like going from a variable amount of colors returned from the wallpaper to just a single color returned from Plasma API but maybe it's fine for people who don't enable text colors from wallpaper? Shouldn't be too hard to implement.

luisbocanegra avatar Feb 27 '24 20:02 luisbocanegra

offtopic but what plasma style and application style are you using? @Blacksuan19

kun-codes avatar Feb 29 '24 11:02 kun-codes

Sounds like a good idea. The only downside is requiring people who don't use Arch + AUR having to compile the helper but there's no way around that one.

you can use github actions to build the helper and upload it as an artifact for popular options like deb or rpm.

I also thought of adding that as an option, didn't like going from a variable amount of colors returned from the wallpaper to just a single color returned from Plasma API but maybe it's fine for people who don't enable text colors from wallpaper? Shouldn't be too hard to implement.

it's definitely way less colors but its decent enough for themeing purposes.

offtopic but what plasma style and application style are you using? @Blacksuan19

plasma style is my own version of colloid-light that follows system colorscheme application style is lightly

Blacksuan19 avatar Mar 03 '24 16:03 Blacksuan19

Sounds like a good idea. The only downside is requiring people who don't use Arch + AUR having to compile the helper but there's no way around that one.

you can use github actions to build the helper and upload it as an artifact for popular options like deb or rpm.

Maybe, previously there were rpm packages built on OBS by a user but they couldn't maintain it anymore and nobody took over.

I also thought of adding that as an option, didn't like going from a variable amount of colors returned from the wallpaper to just a single color returned from Plasma API but maybe it's fine for people who don't enable text colors from wallpaper? Shouldn't be too hard to implement.

it's definitely way less colors but its decent enough for themeing purposes.

True, will add it as an option in a future version

luisbocanegra avatar Mar 04 '24 01:03 luisbocanegra