浏览代码

snap: use native wayland client when possible (#2386)

Marco Trevisan 1 周之前
父节点
当前提交
19811fd824

+ 7 - 0
stores/snapcraft/insider/snap/hooks/configure

@@ -0,0 +1,7 @@
+#!/usr/bin/env bash
+set -eu
+
+wayland_native="$(snapctl get wayland-native)"
+if [[ -z "$wayland_native" ]]; then
+    snapctl set wayland-native=false
+fi

+ 21 - 11
stores/snapcraft/insider/snap/local/bin/electron-launch

@@ -67,6 +67,10 @@ fi
 # Set $REALHOME to the users real home directory
 REALHOME=$(getent passwd $UID | cut -d ':' -f 6)
 
+
+# Extra launch arguments
+declare -a launch_args
+
 # Set config folder to local path
 ensure_dir_exists "$SNAP_USER_DATA/.config"
 chmod 700 "$SNAP_USER_DATA/.config"
@@ -105,6 +109,7 @@ copy_env_variable GDK_BACKEND
 copy_env_variable GTK_PATH
 copy_env_variable GTK_EXE_PREFIX
 copy_env_variable GTK_IM_MODULE_FILE
+copy_env_variable LIBGL_DRIVERS_PATH
 
 # XDG Config
 prepend_dir XDG_CONFIG_DIRS "$SNAP/etc/xdg"
@@ -122,6 +127,11 @@ ensure_dir_exists "$SNAP_USER_DATA/.local/share"
 #   https://bugzilla.gnome.org/show_bug.cgi?id=741335
 prepend_dir XDG_DATA_DIRS "$SNAP_USER_DATA/.local/share"
 
+# Use the snap MESA drivers to launch the snap.
+# This is required by wayland, but electron will make better use under X11 too
+prepend_dir LIBGL_DRIVERS_PATH "$SNAP/usr/lib/dri"
+prepend_dir LIBGL_DRIVERS_PATH "$SNAP/usr/lib/$ARCH/dri"
+
 # Set cache folder to local path
 if [[ -d "$SNAP_USER_DATA/.cache" && ! -e "$SNAP_USER_COMMON/.cache" ]]; then
   # the .cache directory used to be stored under $SNAP_USER_DATA, migrate it
@@ -138,28 +148,22 @@ append_dir LOCPATH "$SNAP/usr/lib/locale"
 
 # If detect wayland server socket, then set environment so applications prefer
 # wayland, and setup compat symlink (until we use user mounts. Remember,
-# XDG_RUNTIME_DIR is /run/user/<uid>/snap.$SNAP so look in the parent directory
-# for the socket. For details:
-# https://forum.snapcraft.io/t/wayland-dconf-and-xdg-runtime-dir/186/10
+# XDG_RUNTIME_DIR is /run/user/<uid> for classic snaps.
 # Applications that don't support wayland natively may define DISABLE_WAYLAND
 # (to any non-empty value) to skip that logic entirely.
 wayland_available=false
-if [[ -n "$XDG_RUNTIME_DIR" && -z "$DISABLE_WAYLAND" ]]; then
+if [[ -n "$XDG_RUNTIME_DIR" && -z "$DISABLE_WAYLAND" ]] && \
+   [[ "$(snapctl get wayland-native)" == "true" ]]; then
     wdisplay="wayland-0"
     if [ -n "$WAYLAND_DISPLAY" ]; then
         wdisplay="$WAYLAND_DISPLAY"
     fi
-    wayland_sockpath="$XDG_RUNTIME_DIR/../$wdisplay"
     wayland_snappath="$XDG_RUNTIME_DIR/$wdisplay"
-    if [ -S "$wayland_sockpath" ]; then
+    if [ -S "$wayland_snappath" ]; then
         # if running under wayland, use it
         #export WAYLAND_DEBUG=1
         # shellcheck disable=SC2034
         wayland_available=true
-        # create the compat symlink for now
-        if [ ! -e "$wayland_snappath" ]; then
-            ln -s "$wayland_sockpath" "$wayland_snappath"
-        fi
     fi
 fi
 
@@ -234,6 +238,8 @@ fi
 # shellcheck disable=SC2154
 if [ "$wayland_available" = true ]; then
   export GDK_BACKEND="wayland"
+  launch_args+=(--ozone-platform-hint=auto)
+  launch_args+=(--enable-features=WaylandWindowDecorations)
 fi
 
 append_dir GTK_PATH "$SNAP/usr/lib/$ARCH/gtk-3.0"
@@ -261,4 +267,8 @@ fi
 
 wait_for_async_execs
 
-exec "$@"
+
+binary="$1"
+shift
+
+exec "$binary" "${launch_args[@]}" "$@"

+ 8 - 0
stores/snapcraft/insider/snap/snapcraft.yaml

@@ -59,6 +59,8 @@ parts:
       - libnss3
       - libpango-1.0-0
       - libsecret-1-0
+      - libvulkan1
+      - libwayland-egl1
       - libxcomposite1
       - libxdamage1
       - libxfixes3
@@ -68,14 +70,20 @@ parts:
       - libxss1
       - locales-all
       - packagekit-gtk3-module
+      - gnome-settings-daemon-common
       - xdg-utils
     prime:
+      - -lib/udev
+      - -usr/lib/systemd
       - -usr/share/doc
       - -usr/share/fonts
       - -usr/share/icons
       - -usr/share/lintian
       - -usr/share/man
       - -usr/share/codium/chrome-sandbox
+      - -usr/share/@@NAME@@/libEGL.so*
+      - -usr/share/@@NAME@@/libGLESv2.so*
+      - -usr/share/@@NAME@@/libvulkan.so*
     build-attributes:
       - enable-patchelf
     override-prime: |

+ 7 - 0
stores/snapcraft/stable/snap/hooks/configure

@@ -0,0 +1,7 @@
+#!/usr/bin/env bash
+set -eu
+
+wayland_native="$(snapctl get wayland-native)"
+if [[ -z "$wayland_native" ]]; then
+    snapctl set wayland-native=false
+fi

+ 21 - 11
stores/snapcraft/stable/snap/local/bin/electron-launch

@@ -67,6 +67,10 @@ fi
 # Set $REALHOME to the users real home directory
 REALHOME=$(getent passwd $UID | cut -d ':' -f 6)
 
+
+# Extra launch arguments
+declare -a launch_args
+
 # Set config folder to local path
 ensure_dir_exists "$SNAP_USER_DATA/.config"
 chmod 700 "$SNAP_USER_DATA/.config"
@@ -105,6 +109,7 @@ copy_env_variable GDK_BACKEND
 copy_env_variable GTK_PATH
 copy_env_variable GTK_EXE_PREFIX
 copy_env_variable GTK_IM_MODULE_FILE
+copy_env_variable LIBGL_DRIVERS_PATH
 
 # XDG Config
 prepend_dir XDG_CONFIG_DIRS "$SNAP/etc/xdg"
@@ -122,6 +127,11 @@ ensure_dir_exists "$SNAP_USER_DATA/.local/share"
 #   https://bugzilla.gnome.org/show_bug.cgi?id=741335
 prepend_dir XDG_DATA_DIRS "$SNAP_USER_DATA/.local/share"
 
+# Use the snap MESA drivers to launch the snap.
+# This is required by wayland, but electron will make better use under X11 too
+prepend_dir LIBGL_DRIVERS_PATH "$SNAP/usr/lib/dri"
+prepend_dir LIBGL_DRIVERS_PATH "$SNAP/usr/lib/$ARCH/dri"
+
 # Set cache folder to local path
 if [[ -d "$SNAP_USER_DATA/.cache" && ! -e "$SNAP_USER_COMMON/.cache" ]]; then
   # the .cache directory used to be stored under $SNAP_USER_DATA, migrate it
@@ -138,28 +148,22 @@ append_dir LOCPATH "$SNAP/usr/lib/locale"
 
 # If detect wayland server socket, then set environment so applications prefer
 # wayland, and setup compat symlink (until we use user mounts. Remember,
-# XDG_RUNTIME_DIR is /run/user/<uid>/snap.$SNAP so look in the parent directory
-# for the socket. For details:
-# https://forum.snapcraft.io/t/wayland-dconf-and-xdg-runtime-dir/186/10
+# XDG_RUNTIME_DIR is /run/user/<uid> for classic snaps.
 # Applications that don't support wayland natively may define DISABLE_WAYLAND
 # (to any non-empty value) to skip that logic entirely.
 wayland_available=false
-if [[ -n "$XDG_RUNTIME_DIR" && -z "$DISABLE_WAYLAND" ]]; then
+if [[ -n "$XDG_RUNTIME_DIR" && -z "$DISABLE_WAYLAND" ]] && \
+   [[ "$(snapctl get wayland-native)" == "true" ]]; then
     wdisplay="wayland-0"
     if [ -n "$WAYLAND_DISPLAY" ]; then
         wdisplay="$WAYLAND_DISPLAY"
     fi
-    wayland_sockpath="$XDG_RUNTIME_DIR/../$wdisplay"
     wayland_snappath="$XDG_RUNTIME_DIR/$wdisplay"
-    if [ -S "$wayland_sockpath" ]; then
+    if [ -S "$wayland_snappath" ]; then
         # if running under wayland, use it
         #export WAYLAND_DEBUG=1
         # shellcheck disable=SC2034
         wayland_available=true
-        # create the compat symlink for now
-        if [ ! -e "$wayland_snappath" ]; then
-            ln -s "$wayland_sockpath" "$wayland_snappath"
-        fi
     fi
 fi
 
@@ -234,6 +238,8 @@ fi
 # shellcheck disable=SC2154
 if [ "$wayland_available" = true ]; then
   export GDK_BACKEND="wayland"
+  launch_args+=(--ozone-platform-hint=auto)
+  launch_args+=(--enable-features=WaylandWindowDecorations)
 fi
 
 append_dir GTK_PATH "$SNAP/usr/lib/$ARCH/gtk-3.0"
@@ -261,4 +267,8 @@ fi
 
 wait_for_async_execs
 
-exec "$@"
+
+binary="$1"
+shift
+
+exec "$binary" "${launch_args[@]}" "$@"

+ 8 - 0
stores/snapcraft/stable/snap/snapcraft.yaml

@@ -59,6 +59,8 @@ parts:
       - libnss3
       - libpango-1.0-0
       - libsecret-1-0
+      - libvulkan1
+      - libwayland-egl1
       - libxcomposite1
       - libxdamage1
       - libxfixes3
@@ -68,14 +70,20 @@ parts:
       - libxss1
       - locales-all
       - packagekit-gtk3-module
+      - gnome-settings-daemon-common
       - xdg-utils
     prime:
+      - -lib/udev
+      - -usr/lib/systemd
       - -usr/share/doc
       - -usr/share/fonts
       - -usr/share/icons
       - -usr/share/lintian
       - -usr/share/man
       - -usr/share/codium/chrome-sandbox
+      - -usr/share/@@NAME@@/libEGL.so*
+      - -usr/share/@@NAME@@/libGLESv2.so*
+      - -usr/share/@@NAME@@/libvulkan.so*
     build-attributes:
       - enable-patchelf
     override-prime: |