Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kde: Apply theme without GUI session, ignore failures (#809) #848

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

lordkekz
Copy link
Contributor

@lordkekz lordkekz commented Feb 9, 2025

Fixes #809

Problem

Activation didn't work for users on Hyprland who still use stylix's KDE target for theming Qt apps.
The plasma-apply-* commands require some parts of the plasma session to be available:

  • plasma-apply-lookandfeel requires an available Qt Platform Abstraction, which is not a guaranteed with some autostart or automatic activation setups. This can be satisfied with non-Plasma GUI sessions such as Hyprland or Xvfb.
  • plasma-apply-wallpaperimage doesn't require a Qt Platform, but does require Plasma itself to be running, so this will still not work without the autostart script from Fix plasma activation #708.

Solution / Change Summary

  • Use xvfb-run to run the plasma-apply-* commands with a headless X11 server unless the $DISPLAY variable is set.
  • By default xvfb-run waits 3 seconds for the headless Xorg server to start. This delay only happens once because both plasma-apply-* commands run in a single script passed to xvfb-run.
  • Don't fail activation if either of the plasma-apply-* commands fail.
    I am strongly in favor of ignoring at least plasma-apply-wallpaperimage because it is expected to fail even when there is no misconfiguration: plasma-apply-wallpaperimage fails on some activation setups and on non-Plasma setups which still use stylix.wallpaper (e.g. Hyprland).

Potential alternatives

I initially tried to give Qt a platform to work with independently from the main Plasma/Hyprland session being fully started or not. There's some documentation for different Qt Platform Abstractions here but I couldn't get offscreen, vnc or minimal to work in my TTY.

plasma-apply-lookandfeel --apply stylix produces on my TTY:

qt.qpa.xcb: could not connect to display 
qt.qpa.plugin: From 6.5.0, xcb-cursor0 or libxcb-cursor0 is needed to load the Qt xcb platform plugin.
qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "" even though it was found.
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.

Available platform plugins are: wayland-egl, wayland, eglfs, linuxfb, minimal, minimalegl, offscreen, vkkhrdisplay, vnc, xcb.

Exit code -6

Backporting

My initial attempt is based on NixOS 24.11, see 1427b55. I can open another PR for 24.11 if you're okay with that.

Copy link
Collaborator

@trueNAHO trueNAHO left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you explain what is means to run the activation script from the TTY or a non-DISPLAY environment? Does it not need an environment to apply the theming on?

Either way, we should probably wait on @Alxandr's testing.

Cc: @rkuklik

@lordkekz
Copy link
Contributor Author

Could you explain what is means to run the activation script from the TTY or a non-DISPLAY environment? Does it not need an environment to apply the theming on?

My testing reveals that the two plasma-apply-* commands each have different requirements:

  • plasma-apply-lookandfeel seems to use some Qt classes which only work if there is a Qt Platform Abstraction available. It doesn't appear to require an actual Plasma session since it works on a plain TTY (If I just never start plasma and switch to a TTY instead) as well as Hyprland according to @Alxandr's testing in Allow plasma-apply-wallpaperimage to fail #809 (comment).
  • plasma-apply-wallpaperimage seems to not require a Qt Platform Abstraction (I just realized this and tested it), but it does actually require Plasma to be running via dbus. So this we can't fix with xvfb-run.

So, before this PR, you could run the activation in a running Plasma session and everything would work. Or, since #823, you could run the activation in a non-Plasma GUI session and the theme would work but the wallpaper not.
Depending on the user's setup, their activation may not be running in any GUI session at all, but rather a systemd unit (which could be started before the Compositor or with missing environment variables) or even a plain script run by the display manager (I do this).
To support such setups I am adding a wrapper which runs the plasma-apply-lookandfeel step via xvfb-run if there is no $DISPLAY set (this reduces the delay if activation is already running in a GUI session).

@rkuklik
Copy link
Contributor

rkuklik commented Feb 12, 2025

Could you explain what is means to run the activation script from the TTY or a non-DISPLAY environment? Does it not need an environment to apply the theming on?

When you run a QT app, it uses a platform plugin as an implementation for functionality like filesystems or windowing. If you look at plasma-apply-lookandfeel output, it finds a plugin, but fails to initialize it due to the environment the plugin expects to find itself (no windows in tty, for instance). Ideally, we would force the tools to use the minimal platform plugin (no drawing required), which should work in tty, but I am not a QT dev and have no idea how to do that.

@rkuklik
Copy link
Contributor

rkuklik commented Feb 12, 2025

Well I just found a forum post: https://forum.qt.io/topic/151317/qt-platform-plugin-xcb-could-not-load-qt6.

@lordkekz could you try to run plasma-apply-lookandfeel with QT_QPA_PLATFORM=minimal?

@lordkekz
Copy link
Contributor Author

I did but it didn't work on my system.
I didn't get any of the backends except x11 and wayland to work.

@rkuklik
Copy link
Contributor

rkuklik commented Feb 12, 2025

OK, thank you, but it's weird. I tried it on my system, outside Plasma, and it did work. Do you have the logs?

@lordkekz
Copy link
Contributor Author

I must correct myself; it produces errors but does seem to update the theme. So it seems that it would be possible to just do export QT_QPA_PLATFORM=minimal instead of wrapping it with xvfb-run.

Here's the log:

"applications.menu"  not found in  QList("/nix/store/apgm29h2lscbr4wcaqdx3bi9vxagzcz1-plasma-workspace-6.2.5/etc/xdg/menus", "/run/current-system/sw/etc/xdg/menus")
/nix/store/g3y7lj2i3b11vbs4q7m99fpi93iq06hd-xrdb-1.2.2/bin/xrdb: Can't open display ''
/nix/store/bkg6plcnllaw4q39iw1y2ylr23rk5wgv-xsetroot-1.1.3/bin/xsetroot:  unable to open display ''
kf.config.core: Couldn't write "/home/username/.config/kcminputrc" . Disk full?
/nix/store/g3y7lj2i3b11vbs4q7m99fpi93iq06hd-xrdb-1.2.2/bin/xrdb: Can't open display ''
/nix/store/bkg6plcnllaw4q39iw1y2ylr23rk5wgv-xsetroot-1.1.3/bin/xsetroot:  unable to open display ''

Do you get any output?

@rkuklik
Copy link
Contributor

rkuklik commented Feb 12, 2025

I must correct myself; it produces errors but does seem to update the theme. So it seems that it would be possible to just do export QT_QPA_PLATFORM=minimal instead of wrapping it with xvfb-run.

It should be. I would either add it to the original (pre PR) script, perhaps making use of writeShellApplication, which you began using.

Here's the log:

"applications.menu"  not found in  QList("/nix/store/apgm29h2lscbr4wcaqdx3bi9vxagzcz1-plasma-workspace-6.2.5/etc/xdg/menus", "/run/current-system/sw/etc/xdg/menus")
/nix/store/g3y7lj2i3b11vbs4q7m99fpi93iq06hd-xrdb-1.2.2/bin/xrdb: Can't open display ''
/nix/store/bkg6plcnllaw4q39iw1y2ylr23rk5wgv-xsetroot-1.1.3/bin/xsetroot:  unable to open display ''
kf.config.core: Couldn't write "/home/username/.config/kcminputrc" . Disk full?
/nix/store/g3y7lj2i3b11vbs4q7m99fpi93iq06hd-xrdb-1.2.2/bin/xrdb: Can't open display ''
/nix/store/bkg6plcnllaw4q39iw1y2ylr23rk5wgv-xsetroot-1.1.3/bin/xsetroot:  unable to open display ''

Do you get any output?

I got the same, apart from the disk full one. The program exited successfully, so I think it should be okay. I would try to use minimal plugin in activation and let @Alxandr test it.

@Alxandr
Copy link

Alxandr commented Feb 12, 2025

My filesystem is back up and running again, but due to #835 I`m a bit worried about testing branches. I've currently pinned stylix at b00c9f4 as my DE breaks otherwise.

@rkuklik
Copy link
Contributor

rkuklik commented Feb 18, 2025

I think this is the most correct thing we could do, @lordkekz will you go ahead?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow plasma-apply-wallpaperimage to fail
4 participants