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

🔨 Wayland support for electron apps #23

Merged
merged 6 commits into from
Jun 8, 2024
Merged

🔨 Wayland support for electron apps #23

merged 6 commits into from
Jun 8, 2024

Conversation

noonsleeper
Copy link
Contributor

@noonsleeper noonsleeper commented Feb 22, 2024

if socket=wayland is active the parameters to handle wayland decorations is set also ozone-platform-hint=auto is set

if you override with nosocket=wayland force ozone-platform=x11

@daiyam
Copy link

daiyam commented May 8, 2024

Hello @gasinvein, can you give us a timeline for this PR? Thx

@gasinvein
Copy link
Collaborator

Hello, sorry for the delay and thanks for the contribution. Sadly, I cannot test this myself atm. Did you try to build VSCod[ium] flatpak with this wrapper version and verify that it works as intended?

editor.sh Show resolved Hide resolved
editor.sh Outdated
# See https://github.com/flathub/im.riot.Riot/blob/3fdd41c84f40fa1e8e186bade5d832d79045600c/element.sh
# See also https://gaultier.github.io/blog/wayland_from_scratch.html
# and https://github.com/flathub/com.vscodium.codium/issues/321
if [[ ${WAYLAND_DISPLAY} == "/run/flatpak/wayland-"* ]] || [[ -e "${XDG_RUNTIME_DIR}/${WAYLAND_DISPLAY}" ]] && [[ "wayland" == "${XDG_SESSION_TYPE}" ]]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Isn't checking if XDG_SESSION_TYPE is set to wayland is enough?

Suggested change
if [[ ${WAYLAND_DISPLAY} == "/run/flatpak/wayland-"* ]] || [[ -e "${XDG_RUNTIME_DIR}/${WAYLAND_DISPLAY}" ]] && [[ "wayland" == "${XDG_SESSION_TYPE}" ]]
if [[ "wayland" == "${XDG_SESSION_TYPE}" ]]

Copy link

Choose a reason for hiding this comment

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

Isn't checking if XDG_SESSION_TYPE is set to wayland is enough?

No, under KDE, $XDG_RUNTIME_DIR/$WAYLAND_DISPLAY will give /run/user/1000//run/flatpak/wayland-0 which is incorrect. That's why @noonsleeper is testing for the prefix /run/flatpak/wayland-.

Copy link

@bbhtt bbhtt May 8, 2024

Choose a reason for hiding this comment

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

Isn't checking if XDG_SESSION_TYPE is set to wayland is enough?

Checking for the socket is correct, $XDG_SESSION_TYPE can stay on wayland even if the finish arg is removed (ie. with --nosocket) as it is inherited from the environment and has no connection with the active finish args.

/run/user/1000//run/flatpak/wayland-0

Those two should not overlap like that, it should always be /run/flatpak/wayland-{0, 1,...}

You should check for only one of them - preferably for the one /run/flatpak/ only.

Copy link

@bbhtt bbhtt May 8, 2024

Choose a reason for hiding this comment

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

If you want to make it more sound you can check if stat -c %F /run/flatpak/wayland-0 reports socket or if it fails (ie. when nosocket=wayland or not on wayland session).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hi @bbhtt, to sum up, I only need to check if $WAYLAND_DISPLAY contains wayland- and also $XDG_SESSION_TYPE == wayland, because flatpak already check if wayland-* is a socket, is that so?

Copy link

@bbhtt bbhtt May 8, 2024

Choose a reason for hiding this comment

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

You can do if [[ -e "$(echo "/run/flatpak/wayland-"*)" ]]; then echo "yes"; else echo "no"; fi but it might match multiple files wayland-0, wayland-0.lock too (fortunately there is only one wayland-0 in /run/flatpak/)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@bbhtt, @gasinvein

I'm still on Silverblue F39 and WAYLAND_DISPLAY is reporting only wayland-0 not the full path, I don't check if F40 change that behaviour within gnome 46, but I think other distros like Debian or Ubuntu maybe has the same behaviour for Gnome 45.
Then, if we need to check both at the same time, I come with this:

Screenshot from 2024-05-08 20-44-30

It is not perfect like you can see, but it comes handy because I don't use or pass that variable to anything, also this check that at least the variable is filled with something that resembles what we are looking for,

Also, I can go with a more accurate regex that only *wayland-? (to me this will add more complexity to something that doesn't require that, but maybe I'm wrong, I'm open to any advice), what do you think?

Btw, sorry for this wall of text

Choose a reason for hiding this comment

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

I think it would be easier to check if WAYLAND_DISPLAY is an absolute path. If not, then construct the path to the socket using the implicit path. Like:

local display_type=x11
local display_server_args
local wayland_socket

if [ "$XDG_DISPLAY_TYPE" = wayland ] && [ -n "$WAYLAND_DISPLAY" ]; then
    if [[ $WAYLAND_DISPLAY =~ ^/ ]]; then
        wayland_socket=$WAYLAND_DISPLAY
    else
        wayland_socket="${XDG_RUNTIME_DIR:-/run/user/${UID}}/${WAYLAND_DISPLAY}"
    fi

    [ -e "$wayland_socket" ] && display_type=wayland
fi

if [ "$display_type" = wayland ]; then
    # Set display_server_args for wayland
else
    # Set display_server_args for x11
fi

echo $display_server_args

Choose a reason for hiding this comment

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

Another way without using a regex would be [ "${WAYLAND_DISPLAY::1}" = / ].

Copy link

Choose a reason for hiding this comment

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

I think it would be easier to check if WAYLAND_DISPLAY is an absolute path. If not, then construct the path to the socket using the implicit path. Like:

This also works I think.

@daiyam
Copy link

daiyam commented May 8, 2024

Hello, sorry for the delay and thanks for the contribution. Sadly, I cannot test this myself atm. Did you try to build VSCod[ium] flatpak with this wrapper version and verify that it works as intended?

No problem. :)

The latest version should include it with the fix for KDE but I haven't test it myself...
But VSCodium has been using with the PR since the March releases.

@noonsleeper
Copy link
Contributor Author

Hi @gasinvein, Can you give me an update about this?

Copy link
Collaborator

@gasinvein gasinvein left a comment

Choose a reason for hiding this comment

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

LGTM.

@gasinvein gasinvein merged commit 7b72347 into flathub-infra:zypak Jun 8, 2024
1 check passed
@gasinvein
Copy link
Collaborator

gasinvein commented Jun 8, 2024

The zypak branch was in a WiP state, but it seems like several apps on Flathub are using it now. Do you folks consider it ready? If so, should we merge it into the main branch (see #13)?

@noonsleeper
Copy link
Contributor Author

The zypak branch was in a WiP state, but it seems like several apps on Flathub are using it now. Do you folks consider it ready? If so, should we merge it into the main branch (see #13)?

I was using this since nearly the creation of the branch, and at least for codium and codium-insiders it works like a charm.

function exec_editor() {
@EXPORT_ENVS@
exec "@WRAPPER_PATH@" @EDITOR_ARGS@ "$@"
# shellcheck disable=SC2046,SC2086
exec "@WRAPPER_PATH@" @EDITOR_ARGS@ $(display_server_args) ${EDITOR_RUNTIME_ARGS} "$@"
Copy link
Collaborator

@gasinvein gasinvein Jun 9, 2024

Choose a reason for hiding this comment

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

@noonsleeper Ok, there seems to be one thing I've missed. The wrapper isn't solely for Electron apps, thus electron-specific cli args shouldn't be added unconditionally.
Adding the display server args for electron should be gated by Zypak feature enabled.

@noonsleeper noonsleeper deleted the wayland-support branch June 9, 2024 16:20
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.

5 participants