FS#72297 - [sway] Set XDG_CURRENT_DESKTOP and import into systemd user environment

Attached to Project: Community Packages
Opened by Max Gautier (VannTen) - Thursday, 30 September 2021, 08:07 GMT
Last edited by Brett Cornwall (ainola) - Wednesday, 01 November 2023, 20:12 GMT
Task Type Feature Request
Category Packages
Status Closed
Assigned To Brett Cornwall (ainola)
Maxim Baz (maximbaz)
Architecture All
Severity Low
Priority Normal
Reported Version
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 4
Private No

Details

Description:

The sway package in archlinux ships with the following `/etc/sway/config.d/50-systemd-user.conf`
```
# sway does not set DISPLAY/WAYLAND_DISPLAY in the systemd user environment
# See  FS#63021 
# Adapted from xorg's 50-systemd-user.sh, which achieves a similar goal.

exec systemctl --user import-environment DISPLAY WAYLAND_DISPLAY SWAYSOCK
exec hash dbus-update-activation-environment 2>/dev/null && \
dbus-update-activation-environment --systemd DISPLAY WAYLAND_DISPLAY SWAYSOCK
```
In the pipewire article it is noted that to correctly use xdg-destktop-portal-wlr the XDG_CURRENT_DESKTOP has to be set to the name of the compositor (sway) in the environment of the systemd user instance.
https://wiki.archlinux.org/title/PipeWire#WebRTC_screen_sharing
Would it make sense to add that variable to 50-systemd-user.conf for a better out of the box experience ?

Additional info:
* package version(s)
sway 1:1.6.1-1
This task depends upon

Closed by  Brett Cornwall (ainola)
Wednesday, 01 November 2023, 20:12 GMT
Reason for closing:  Implemented
Additional comments about closing:  sway 1:1.8.1-3 fixes this!
Comment by Brett Cornwall (ainola) - Friday, 15 October 2021, 00:11 GMT
Thanks for the report. I don't see an issue with this. I went through sway's bug tracker to see if upstream had any opinions/downsides to doing this and I wasn't able to find anything. I'm in favor of adding this in for compatibility as other packages require it to function.
Comment by Maxim Baz (maximbaz) - Friday, 15 October 2021, 18:09 GMT
+1 from me, please go ahead if you have time to make the change.
Comment by Atomic (Atomic) - Sunday, 24 October 2021, 20:48 GMT
  • Field changed: Percent Complete (100% → 0%)
The change in sway-1:1.6.1-2 doesn't set XDG_CURRENT_DESKTOP to sway. You still have to set it manually prior to calling sway. In that case you might update systemd and dbus manually instead of the current change.

According to https://github.com/swaywm/sway/pull/6227#issuecomment-826288321 they do not want that variable in sway.desktop.

According to https://bugzilla.mozilla.org/show_bug.cgi?id=1640115#c10 last line, sway will not set XDG_CURRENT_DESKTOP itself. This is also absent in the manual page sway(1) near the bottom.

I don't think upstream would be in favor of this change if they explicitly don't want to set it themselves.


The Arch wiki page for sway currently does not mention XDG_CURRENT_DESKTOP. My suggestion is to add the information there.
Comment by Brett Cornwall (ainola) - Sunday, 24 October 2021, 21:02 GMT
This is not related to the ticket at hand but I felt it easier to merely accept the re-open request so that we may have an easier time to review this ticket in a historical context.

Upstream has confirmed their non-intention to set that variable as their belief is that users should set this up themselves (not out of gatekeeping but rather due to unfortunately poor specification by xdg-desktop-portal). This puts us in an awkward position: Do we pull a Debian and deviate or do we merely shrug and improve the docs?

There's a near-universal need for users to share their desktops, which guarantees that manual intervention would be involved if we don't do anything. We will likely continue to get bug reports and most users of Sway will require going through this irritation.

After conferring with maximbaz, we decided upon pragmatism and will go forward with setting/exporting XDG_CURRENT_DESKTOP=sway in the default configuration. There will be a separate /etc/sway/config.d/40-environment.conf file that will be sourced before the systemd/dbus environment import file. The intention here is that the default configuration will provide all of this nonsense for the majority that just want their desktop to function, whereas the edge cases can simply ignore importing the file.
Comment by Brett Cornwall (ainola) - Sunday, 24 October 2021, 21:41 GMT
Actually, maximbaz, are we sure we can do this? AFAICT there's no way to actually set env vars in a sway/i3 config. If that's true, then I don't believe there's anything sensible we can do...
Comment by Maxim Baz (maximbaz) - Sunday, 24 October 2021, 21:56 GMT
I think so, please check my findings below:

- `dbus-update-activation-environment` is always present (because it's provided by dbus, which is required by systemd, which in turn is part of base), so we don't need to check its existence with `hash`
- `dbus-update-activation-environment --systemd XXX` already imports to systemd user environment, so we can safely remove `systemctl --user import-environment XXX` as duplicate
- `dbus-update-activation-environment` allows usage as `dbus-update-activation-environment --systemd NAME=VALUE`

So we can reduce 50-systemd-user.conf to be simply:

dbus-update-activation-environment --systemd DISPLAY WAYLAND_DISPLAY SWAYSOCK

And create 40-environment.conf with this content:

dbus-update-activation-environment --systemd XDG_CURRENT_DESKTOP=sway

We can also consider renaming these files for clarity, e.g. 50-systemd-user.conf -> 50-display.conf and 40-environment.conf -> 60-xdg.conf, but I don't mind too much about the naming you choose, go with whatever makes sense to you.
Comment by Tadeas Uhlir (rahlir) - Monday, 09 October 2023, 12:25 GMT
I am a little confused about what happened with this. It seems that 50-systemd-user.conf was updated to also export XDG_CURRENT_DESKTOP into systemctl and dbus, but the XDG_CURRENT_DESKTOP was never set to sway. This is particularly problematic now that xdg-desktop-portal requires XDG_CURRENT_DESKTOP to be set to properly pick portal implementation. Without this you cannot even probe Settings interface.
Comment by Brett Cornwall (ainola) - Sunday, 29 October 2023, 00:56 GMT
So sorry for letting this slip through the cracks. I've pushed a fix to sway-1:1.8.1-2.
Comment by Tadeas Uhlir (rahlir) - Wednesday, 01 November 2023, 20:10 GMT
  • Field changed: Percent Complete (100% → 0%)
The pushed fix actually doesn't do anything. You have added XDG_CURRENT_DESKTOP to dbus-update-activation-environment, but that was already there (hence now the line reads DISPLAY ... XDG_CURRENT_DESKTOP XDG_CURRENT_DESKTOP). The missing part is that the XDG_CURRENT_DESKTOP is not set anywhere. This can be done by exec systemctl --user set-environment XDG_CURRENT_DESKTOP=sway and dbus-update-activation-environment --systemd ... XDG_CURRENT_DESKTOP=sway
Comment by Brett Cornwall (ainola) - Wednesday, 01 November 2023, 20:11 GMT
How embarrassing. That's what I get for doing this after a chaotic day. :(

Thanks for bringing this up again. It should really be fixed now.

Loading...