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

Set DesktopNames in sway.desktop to have XDG_CURRENT_DESKTOP #4876

Closed
wants to merge 1 commit into from

Conversation

morxa
Copy link
Contributor

@morxa morxa commented Jan 4, 2020

Setting DesktopNames in the desktop file sets the environment variable
XDG_CURRENT_DESKTOP, which can be used to find out the name of the
currently running session.

See also https://bugzilla.gnome.org/show_bug.cgi?id=727546 and https://bugzilla.redhat.com/show_bug.cgi?id=1787407.

We may want to allow additional names, e.g., Sway. I can update this PR if desired.

Setting DesktopNames in the desktop file sets the environment variable
`XDG_CURRENT_DESKTOP`, which can be used to find out the name of the
currently running session.
@ddevault
Copy link
Contributor

ddevault commented Jan 4, 2020

This isn't our responsibility, this is something the login manager should do. Arguably it shouldn't do it, because this isn't a spec, no one has written it down, and software which relies on it is wrong.

@ddevault ddevault closed this Jan 4, 2020
@morxa morxa deleted the set-xdg-current-desktop branch January 4, 2020 15:46
@thebitstick
Copy link

According to the XDG spec, the login manager sets the variable found in DesktopNames in the session file.
So this should be re-opened.

@morxa
Copy link
Contributor Author

morxa commented Feb 7, 2020

Thanks for finding it in the spec! I agree, but I'll leave this up to @ddevault.

@emersion
Copy link
Member

emersion commented Feb 8, 2020

XDG_CURRENT_DESKTOP otoh takes a list of compatible desktop identifiers, used for checking what to show of .desktop file entries.

People shouldn't use this to detect the current desktop.

@alebastr
Copy link
Contributor

alebastr commented May 9, 2020

I was trying to make xdg-desktop-portal-wlr package work out of the box and found another reason to reconsider this PR:

xdg-desktop-portal-wlr requires both XDG_CURRENT_DESKTOP=sway and a call to dbus-update-activation-environment --systemd WAYLAND_DISPLAY XDG_CURRENT_DESKTOP from sway config.
Sway config part could be shipped downstream (at least Arch already does that, although they don't copy XDG_CURRENT_DESKTOP), but initialization of the variable should be addressed here.

@Darkspirit
Copy link

Darkspirit commented May 22, 2020

Either you reopen this or Firefox can't detect you to enable features like hardware rendering etc.
As you can't be detected, your users must manually switch preferences to unbreak the file picker, for example: https://bugzilla.mozilla.org/show_bug.cgi?id=1639575#c3

@emersion
Copy link
Member

Either you reopen this or Firefox can't detect you.

This is actually a very good reason not to reopen this. Clients like Firefox should really not detect the current compositor.

@Darkspirit
Copy link

Darkspirit commented May 22, 2020

Firefox whitelists features for desktop environments that are proven bug free. It does not blacklist broken ones as it causes more trouble for users. WebRender (OpenGL rendering) rollout will happen incrementally by desktop environment. If you don't merge this, you might not get hardware rendering by default at some point. (?)

@Darkspirit
Copy link

Also, if your users report bugs and upload their about:support page, their desktop environment entry is empty. It's unlikely that every user is manually asked for it, so bugs might get mistriaged and not further debugged. All Sway bugs should ideally end up here: https://bugzilla.mozilla.org/show_bug.cgi?id=wayland-sway

@emersion
Copy link
Member

This is really broken behaviour and a Firefox bug. Reminds me of obnoxious websites whitelisting some browsers. (Not to mention that XDG_CURRENT_DESKTOP is unreliable and only set when users have a display manager enabled.)

@emersion
Copy link
Member

Reported https://bugzilla.mozilla.org/show_bug.cgi?id=1640115

@Darkspirit
Copy link

Darkspirit commented May 22, 2020

Yes, it might not be nice, but it's the common way. Then I guess systems without display manager are not officially supported, so it's up to the user to enable and disable certain preferences to achieve the correct feature set. (?)

@emersion
Copy link
Member

the common way

The common way? How is this common? Firefox is the very first Wayland client doing this.

I guess systems without display manager are not officially supported

How has a display manager anything to do with Firefox? Firefox doesn't interact at all with the display manager.

By the way, display managers are unsupported by Sway (which does interact directly with them). So I guess that makes it impossible for Firefox to officially support Sway.

This is getting quite ridiculous.

@Darkspirit
Copy link

Good to have brought this up, I almost wouldn't have reported this to you.
(I'm not a Firefox developer. Now I feel too anxious and probably won't help you further.)

ndhoule added a commit to ndhoule/dotfiles that referenced this pull request Oct 19, 2020
Unlike X11, under Wayland applications aren't permitted to access each
other's screen content; this is great for security, but breaks
screensharing. In order to enable screensharing, a program called
`xdg-desktop-portal` provides an API for accessing other applications'
screen content (and, optionally, entire screens' content).
`xdg-desktop-portal` launches a corresponding protocol-specific adapter
(e.g. `xdg-desktop-portal-gtk` for GNOME, `xdg-desktop-portal-wlr` for
`wlroots`-based DEs) depending on the value of `XDG_CURRENT_DESKTOP`.

Sway doesn't set this value and has rationale for not doing so
(swaywm/sway#4876). This is a pretty hacky fix
because it sets it no matter which DE launches, but there really aren't
any good options for setting this (the ideal is probably to set it in
`sway.desktop`, but that must be maintained systemwide and is updated
any time the `sway` package is updated).
@fwsmit
Copy link
Contributor

fwsmit commented May 16, 2022

Is there still a good reason to not set XDG_CURRENT_DESKTOP? From what I can tell the only reason for not setting it is the fear of landing on a whitelist or blacklist. But there is a legitimate use case for it in xdg-desktop-portal-wlr. Why make the configuration of this more difficult than it has to be?

I think we should reconsider this issue at least.

@kennylevinsen
Copy link
Member

People might have other preferences (e.g. setting it to KDE to have Qt rather than Gtk portals for file opening/printing, to have launchers show the proper applications, etc.). We only set environment variables that are needed to make clients able to talk to us (SWAYSOCK, WAYLAND_DISPLAY). That xdg-desktop-portal chose to rely on this is unfortunate.

Just set it to what you want before starting sway, or before starting the application in question. There are plenty of other environment variables that you might want to set (MOZ_ENABLE_WAYLAND, QT_QPA_PLATFORM , whatever else you fancy), no need for us to hardcode just one of them.

@jessesimpson36
Copy link

jessesimpson36 commented Nov 30, 2022

I had broken screensharing in firefox for years because of this issue, not even knowing that XDG_CURRENT_DESKTOP wasn't being set properly. How am I expected to know to set this environment variable when its not in the sway docs?

The reasoning's for not including this patch are philosophical at best. I'm a user with a real issue.

My suggestion is to include in a FAQ or README that as part of the installation, we should set this variable for compatibility with underlying applications. That way users who debug this issue don't have to search github's closed issues to fix their problem (as I did).

@smlx
Copy link
Contributor

smlx commented Nov 30, 2022

XDG_CURRENT_DESKTOP is documented in xdpw's FAQ and Troubleshooting guide.

@bl4ckb0ne
Copy link
Contributor

@jessesimpson36 you can edit the wiki to add that

@jessesimpson36
Copy link

I tried editing the wiki, but it seems I do not have permission. If you have feedback about the description, I'd be happy to change it to better reflect the findings of this discussion.
The diff I tried changing was in Home.md after line 490

XDG_CURRENT_DESKTOP environment variable is not being set

Some applications may rely on the XDG_CURRENT_DESKTOP environment variable to be set so that the application can accommodate for being ran under sway. One example of this is using Screensharing in Firefox. To set this variable, one option is to modify your shell's profile file to export this environment variable before manually running sway. If you use a login manager, the login manager will use the DesktopNames attribute inside the sway.desktop file. This file may be modified to add DesktopNames=sway.

It's not good practice for applications to make use of XDG_CURRENT_DESKTOP in this way, and Firefox has an issue open to try to fix it. Refer to (xpdw's FAQ)[https://github.com/emersion/xdg-desktop-portal-wlr/wiki/FAQ#how-do-i-run-xdpw] and (xdpw's Troubleshooting guide)[https://github.com/emersion/xdg-desktop-portal-wlr/wiki/%22It-doesn't-work%22-Troubleshooting-Checklist] if your issue is specifically related to screensharing.

@emersion
Copy link
Member

Ah, yes, the wiki was locked down because of recent abuse. I've unlocked it again.

@jessesimpson36
Copy link

Oh, I'm sorry to hear it.
I edited the wiki. Thanks for allowing me to make this change.

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

Successfully merging this pull request may close these issues.