emersion / xdg-desktop-portal-wlr

xdg-desktop-portal backend for wlroots
MIT License
580 stars 54 forks source link

Cannot Share Screen in Firefox Flatpak #261

Closed 3lpsy closed 1 year ago

3lpsy commented 1 year ago

I am running arch linux + sway with firefox under a flatpak. When navigating to the Mozilla gum test and trying to share my screen, I receive the following:

NotFoundError: The object can not be found here.

I have included the following environment variables via Flatseal:

XDG_CURRENT_DESKTOP=sway
XDG_SESSION_TYPE=wayland
GTK_THEME=Nordic
GTK_PATH=/app/lib/gtkmodules

I have included the following Talks for the session via Flatseal:

org.freedesktop.portal.OpenURI.OpenURI
org.freedesktop.portal.ScreenCast
org.freedesktop.portal.Settings
org.freedesktop.portal.Screenshot

These Talks for the session were included by default:

org.gnome.SessionManager
org.a11y.Bus
org.gtk.vfs.*
org.freedesktop.ScreenSaver
org.freedesktop.FileManager1
org.freedesktop.Notifications

I have gone through the checklist and get stuck at

< "/proc/$(pidof xdg-desktop-portal)/environ" tr '\0' '\n' | grep '^WAYLAND_DISPLAY='

This returns wayland-1 on the host but of course nothing within the flatpak application environment. The following wayland specific environment variables are set inside the flatpak app:

[📦 org.mozilla.firefox ~]$ env | grep -i wayland
XDG_SESSION_TYPE=wayland
WAYLAND_DISPLAY=wayland-1
QT_QPA_PLATFORM=wayland
ALACRITTY_SOCKET=/run/user/1000/Alacritty-wayland-1-6293.sock
SDL_VIDEODRIVER=wayland
MOZ_ENABLE_WAYLAND=1

[📦 org.mozilla.firefox ~]$ echo $XDG_CURRENT_DESKTOP
XDG_CURRENT_DESKTOP=sway

Is Firefox screensharing not expected to work via Flatpak? I also have xdg-desktop-portal-gtk running as well but from my understanding this should cause issues.

smlx commented 1 year ago

Firefox screensharing works out-of-the-box with Flatpak. There's no need to do any extra configuration.

Do you have this line in your sway config?

exec dbus-update-activation-environment --systemd WAYLAND_DISPLAY XDG_CURRENT_DESKTOP=sway
3lpsy commented 1 year ago

@smix Here's my setup in my sway/config:

...bindings, workspaces, menu, config stuff
exec --no-startup-id sway-dbus-portal-setup
include $sway/config.d/audio.conf
exec_always gtk-init-wayland-compat
exec systemctl --user start gammastep
include $sway/config.d/idle.conf
include $sway/config.d/bar.conf
exec_always swayinitapps
exec systemctl --user start graphical-session.target

And here is my flatpak overrides:

[Context]
sockets=!cups;!pcsc;!x11
devices=dri
filesystems=xdg-data/icons;xdg-data/themes;xdg-config/gtk-2.0;xdg-config/gtk-3.0

[Environment]
GTK_THEME=Nordic
XDG_SESSION_TYPE=wayland
XDG_CURRENT_DESKTOP=sway

[Session Bus Policy]
org.freedesktop.portal.Screenshot=talk
org.freedesktop.portal.Settings=talk
org.freedesktop.portal.ScreenCast=talk
org.freedesktop.portal.OpenURI.OpenURI=talk

Edit: I moved the systemctl calls to pipewire/xdg services to a script called sway-dbus-portal-setup (they had originally been there) to avoid parallel execution. The script looks like this:

#!/bin/bash
# Stop the things, even though the environments should already exist
systemctl --user stop pipewire pipewire.socket wireplumber xdg-desktop-portal xdg-desktop-portal-wlr xdg-desktop-portal-gtk

# Import enivonrmeet variables
/usr/bin/dbus-update-activation-environment --all
dbus-update-activation-environment --systemd WAYLAND_DISPLAY XDG_CURRENT_DESKTOP=sway
systemctl --user import-environment WAYLAND_DISPLAY SWAYSOCK

# restart the things
systemctl --user start pipewire pipewire.socket wireplumber
systemctl --user start xdg-desktop-portal
systemctl --user start xdg-desktop-portal-wlr
systemctl --user start xdg-desktop-portal-gtk
systemctl --user restart wireplumber

/usr/lib/polkit-gnome/polkit-gnome-authentication-agent-1
3lpsy commented 1 year ago

Sorry, screen sharing was working before i switched to flatpak but something changed and now it doesn't work when installed without flatpak. I'll debug the normal installation first.

3lpsy commented 1 year ago

I was able to get the non-flatpak Firefox installation to work with screen sharing by using the following incantation regarding xdp/pipewire services (sway-dbus-portal-setup script):

#!/bin/bash
# Stop the things, even though the environments should already exist
systemctl --user stop pipewire pipewire.socket wireplumber xdg-desktop-portal xdg-desktop-portal-wlr xdg-desktop-portal-gtk

# Import enivonrmeet variables
/usr/bin/dbus-update-activation-environment --all
dbus-update-activation-environment --systemd WAYLAND_DISPLAY XDG_CURRENT_DESKTOP=sway
systemctl --user import-environment WAYLAND_DISPLAY SWAYSOCK

# restart the things
systemctl --user restart pipewire pipewire.socket wireplumber
systemctl --user start xdg-desktop-portal
systemctl --user start xdg-desktop-portal-wlr
systemctl --user start xdg-desktop-portal-gtk
#systemctl --user restart pipewire wireplumber

/usr/lib/polkit-gnome/polkit-gnome-authentication-agent-1

However, I am still unable to get the flatpak installation to work with gum test returning NotFoundError: The object can not be found here.. For both the flatpak and native test I am using a vanilla profile with no extensions/pref changes. For reference, here are my overrides for flatpak:

[Context]
sockets=!cups;!pcsc;!x11
devices=dri
filesystems=xdg-data/icons;xdg-data/themes;xdg-config/gtk-2.0;xdg-config/gtk-3.0

[Environment]
GTK_THEME=Nordic
XDG_SESSION_TYPE=wayland
XDG_CURRENT_DESKTOP=sway

[Session Bus Policy]
org.freedesktop.portal.Screenshot=talk
org.freedesktop.portal.Settings=talk
org.freedesktop.portal.ScreenCast=talk
org.freedesktop.portal.OpenURI.OpenURI=talk

Any guidance on testing/debugging the ability to call the necessary portal from within the flatpak app would be helpful. When I attempt to share on gum test from within flatpak, no events/debug messages show up via journalctl --user -ef -u xdg-desktop-portal -u xdg-desktop-portal-wlr -u xdg-desktop-portal-gtk -u pipewire -u wireplumber

3lpsy commented 1 year ago

Okay, while I said I had it working on the non-flatpak version, I guess I somehow broke it or had got it into a working state accidentally and thought my setup script was working. But yeah, overall, it's broken across flatpak and native installs and I'm not sure why. Here's my setup script:

# ignore log and run functions, just wrappers for redirecting stdout
log "Running sway-dbus-portal-setup";
# Stop the things, even though the environments should already exist
run systemctl --user stop \
        pipewire \
        pipewire-pulse \
        pipewire-pulse.socket \
        pipewire.socket \
        wireplumber \
        xdg-desktop-portal \
        xdg-desktop-portal-wlr;

# Import enivonrmeet variables
run systemctl --user import-environment WAYLAND_DISPLAY SWAYSOCK XDG_SESSION_TYPE;
run dbus-update-activation-environment --systemd WAYLAND_DISPLAY XDG_SESSION_TYPE XDG_CURRENT_DESKTOP=sway;

log "Sytemctl import-environment";
log "WAYLAND_DISPLAY=$WAYLAND_DISPLAY";
log "SWAYSOCK=$SWAYSOCK";
log "XDG_CURRENT_DESKTOP=$XDG_CURRENT_DESKTOP";
log "XDG_SESSION_TYPE=$XDG_SESSION_TYPE"

# restart the things
run systemctl --user start \
    pipewire \
    pipewire-pulse \
    pipewire.socket \
    pipewire-pulse.socket;
run systemctl --user status --no-pager \
    pipewire \
    pipewire-pulse \
    pipewire.socket \
    pipewire-pulse.socket;

run systemctl --user start \
    xdg-desktop-portal \
    xdg-desktop-portal-wlr;
run systemctl --user status --no-pager \
    xdg-desktop-portal \
    xdg-desktop-portal-wlr;

run systemctl --user start wireplumber;
run systemctl --user status --no-pager wireplumber;

Was able to go through the entirety of the checklist and the environment variables all check out. Some interesting messages from the the status calls:

# after pipewire / pipewire-pulse start
systemd[1269]: Started PipeWire Multimedia Service.
pipewire[1586]: mod.rt: Can't find org.freedesktop.portal.Desktop. Is xdg-desktop-portal running?
pipewire[1586]: mod.rt: found session bus but no portal

# after xdg-desktop-portal start
systemd[1269]: Starting Portal service...
xdg-desktop-por[1645]: No skeleton to export
systemd[1269]: Started Portal service.
# after wireplumber start
wireplumber[1589]: Can't find org.freedesktop.portal.Desktop. Is xdg-desktop-portal running?
wireplumber[1589]: found session bus but no portal
Feb 26 12:37:36 sanctuary.kongroo.io wireplumber[1589]: Failed to set scheduler settings: Operation not permitted

Definitely riding the struggle bus on this one. I had my setup working for more than a year and I have no idea how I broke it. I remember there being issues with the service start order and maybe having to throw a random restart at the end but don't have access to my original script unfortunately (though it was very similar to the one above).

smlx commented 1 year ago

You don't need to start/restart anything or override any firefox flatpak config. Just add the line I mentioned to ensure the env vars are set.

3lpsy commented 1 year ago

@smlx Unfortunately, I can't even get it working in the non-flatpak version. First, I enabled the services:

systemctl --user enable pipewire pipewire-pulse wireplumber xdg-desktop-portal xdg-desktop-portal-wlr

Here's my sway:

set $sway "~/.config/sway"
exec --no-startup-id sway-auth-agent
exec --no-startup-id sway-xrdb
exec --no-startup-id sway-dbus-portal-setup
exec_always sway-mako
exec_always sway-apparmor

# bindings, windows setup stuff

exec_always sway-gtk-compat
# idle, bar stuff

Here is sway-auth-agent:

# run is  a wrapper that logs
run /usr/bin/dbus-update-activation-environment --all;
run /usr/lib/polkit-gnome/polkit-gnome-authentication-agent-1;

Here is sway-dbus-portal-setup:

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

In my previous messages, I included some logs regarding wireguard / pipewire not being to see xdg-desktop-portal and xdg-desktop-portal reporting 'No skeleton'. Not sure if those are important. The wireplumber/pipewire issue related to not being able to find xdg-desktop-portal goes away if I restart wireplumber manually. Not really sure what I'm doing wrong.

I am also running linux-hardened, but I've always been running that so I assume that's not the issue.

3lpsy commented 1 year ago

Kind of crazy. I tried on my desktop, which uses the exact same config files my laptop and it worked fine for both flatpak and non-flatpak. I have no idea why as the configs are synced via git. Probably something to do with enabled/disabled systemd services.

Edit: went through and the services are basically the same in terms of what's enabled. The other main difference is my desktop has Xwayland installed but my laptop does not. However, both systems have firefox running under wayland anyways.

3lpsy commented 1 year ago

Okay, so my desktop, that works, has the following output for the xdg-desktop-portal-wlr service:

xdg-desktop-portal-wlr[1754]: 2023/02/28 11:26:17 [INFO] - xdpw: Using render node /dev/dri/renderD128

While my laptop, that doesn't work, has no such output. The only message is Started Portal Service (wlroots implementation). I'm starting to think that xdg-desktop-portal just can't find my laptop screen.

3lpsy commented 1 year ago

Okay, installed Xwayland on my laptop and it works (Xwayland was already on my desktop). I was 95% sure i had it working before without Xwayland and would like to be able to use it without it. Assuming there isn't a regression related to not having Xwayland, since I got it both working locally and in flatpak after installing Xwayland, this issue can be closed. Also thanks @smlx for providing feedback and keeping me from going down unnecessary rabbit holes :)