fix: don't block startup on the desktop portal - #5270
Open
shivankgarg98 wants to merge 1 commit into
Open
Conversation
Waybar reads org.freedesktop.appearance color-scheme through
org.freedesktop.portal.Settings to pick a light or dark stylesheet. Both
halves of that read are synchronous and sit ahead of setupCss(), so the
bar cannot draw until the portal answers:
- the Gio::DBus::Proxy is constructed with default flags, so it asks
the bus to *spawn* the portal and waits for the activation, and
- the Read itself uses call_sync() with the default 25 s timeout.
A portal that is slow to activate therefore delays the whole bar. This
is a long-standing complaint (Alexays#1266, Alexays#2675, Alexays#3140, Alexays#3714); every answer
in those threads is a workaround such as masking a portal backend or
rewriting the activation environment, because Waybar itself has no way
to opt out.
Pass DO_NOT_AUTO_START so Waybar stops being the thing that launches the
portal, skip the call when the name has no owner, and issue the Read
asynchronously. The result is delivered through the existing
signal_appearance_changed() path that Client already connects to
setupCss(), so a late answer still restyles the bar. Watching
g-name-owner covers a portal that only appears after Waybar starts.
Reproduced with a user drop-in that makes activation slow:
mkdir -p ~/.config/systemd/user/xdg-desktop-portal.service.d
printf '[Service]\nExecStartPre=/bin/sleep 30\n' > \
~/.config/systemd/user/xdg-desktop-portal.service.d/slow.conf
systemctl --user daemon-reload
systemctl --user stop xdg-desktop-portal.service
waybar -c min.jsonc -s min.css
Time between the "Using configuration file" and "Using CSS file" log
lines, which is the window where no bar is on screen:
before 25.001 s
after 0.001 s
Also verified on the session bus that no Settings.Read is issued while
the portal has no owner, that exactly one is issued once it appears, and
that Waybar no longer triggers the portal's D-Bus activation.
Trade-off worth naming: getStyle() now runs before the reply arrives, so a
user with style-light.css/style-dark.css gets style.css first and the
appearance-specific sheet a moment later, through the existing
signal_appearance_changed() -> setupCss() path. Measured here that second
pass lands 11 ms after the first, i.e. inside one frame. Changing the
system appearance while Waybar runs is unaffected and produces the same
log sequence as before the patch.
Contributor
Author
|
test: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Waybar reads org.freedesktop.appearance color-scheme through org.freedesktop.portal.Settings to pick a light or dark stylesheet. Both halves of that read are synchronous and sit ahead of setupCss(), so the bar cannot draw until the portal answers:
A portal that is slow to activate therefore delays the whole bar. This is a long-standing complaint (#1266, #2675, #3140, #3714); every answer in those threads is a workaround such as masking a portal backend or rewriting the activation environment, because Waybar itself has no way to opt out.
Pass DO_NOT_AUTO_START so Waybar stops being the thing that launches the portal, skip the call when the name has no owner, and issue the Read asynchronously. The result is delivered through the existing signal_appearance_changed() path that Client already connects to setupCss(), so a late answer still restyles the bar. Watching g-name-owner covers a portal that only appears after Waybar starts.
Reproduced with a user drop-in that makes activation slow:
mkdir -p ~/.config/systemd/user/xdg-desktop-portal.service.d
printf '[Service]\nExecStartPre=/bin/sleep 30\n' >
~/.config/systemd/user/xdg-desktop-portal.service.d/slow.conf
systemctl --user daemon-reload
systemctl --user stop xdg-desktop-portal.service
waybar -c min.jsonc -s min.css
Time between the "Using configuration file" and "Using CSS file" log lines, which is the window where no bar is on screen:
before 25.001 s
after 0.001 s
Also verified on the session bus that no Settings.Read is issued while the portal has no owner, that exactly one is issued once it appears, and that Waybar no longer triggers the portal's D-Bus activation.
Trade-off worth naming: getStyle() now runs before the reply arrives, so a user with style-light.css/style-dark.css gets style.css first and the appearance-specific sheet a moment later, through the existing signal_appearance_changed() -> setupCss() path. Measured here that second pass lands 11 ms after the first, i.e. inside one frame. Changing the system appearance while Waybar runs is unaffected and produces the same log sequence as before the patch.
Related issues
Closes #1266, #2675, #3140, #3714
Checklist
clang-formatninja -C build)man/)