From a2827573fd927ad14c7170a9ebf5557b0847d176 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20Kr=C3=BChlmann?= Date: Thu, 8 Jan 2026 16:33:39 +0100 Subject: [PATCH] Add wayland support for testing --- Makefile | 6 ++- README.md | 16 +++++-- shell.nix | 7 ++++ src/main/shell/run-electron-app-in-wayland | 49 ++++++++++++++++++++++ 4 files changed, 74 insertions(+), 4 deletions(-) create mode 100755 src/main/shell/run-electron-app-in-wayland diff --git a/Makefile b/Makefile index 567634d..4961fd4 100644 --- a/Makefile +++ b/Makefile @@ -53,10 +53,14 @@ package: run-client: IMGFLOAT_CHANNELS_URL=http://localhost:8080/channels $(ELECTRON) ./src/main/node/app.js -.PHONY: runx +.PHONY: run-client-x run-client-x: IMGFLOAT_CHANNELS_URL=http://localhost:8080/channels ./src/main/shell/run-electron-app-in-xorg $(ELECTRON) +.PHONY: run-client-wl +run-client-wl: + IMGFLOAT_CHANNELS_URL=http://localhost:8080/channels ./src/main/shell/run-electron-app-in-xorg $(ELECTRON) + .PHONY: fix fix: node_modules ./node_modules/.bin/prettier --write src diff --git a/README.md b/README.md index ed4e195..360d54b 100644 --- a/README.md +++ b/README.md @@ -79,11 +79,11 @@ This automatically re-compiles the project when source files change. `entr` is r ### Running the electron client -There are two methods of running the electron app during development. Both methods require access to an Xorg server. +There are two methods of running the electron app during development. -#### Running in the current X server +#### Running in the current display server -This spawns the window in your current Xorg server. +This spawns the window in your current display server. ```sh $ make run-client @@ -100,3 +100,13 @@ $ make run-client-x ... ^C ``` + +#### Running in a sandboxed wayland server + +This method spawns an Xorg server with `Xephyr` and `openbox` to ensure a floating window manager, which will more accurately reflect the common user environment. Killing either the Xephyr or electron process shuts both down. + +```sh +$ make run-client-x +... +^C +``` diff --git a/shell.nix b/shell.nix index d084c6b..942b3ef 100644 --- a/shell.nix +++ b/shell.nix @@ -4,12 +4,19 @@ pkgs.mkShell { packages = [ pkgs.electron pkgs.jdt-language-server + pkgs.libxkbcommon pkgs.maven + pkgs.mesa pkgs.nodePackages.prettier pkgs.nodejs pkgs.nss pkgs.openbox pkgs.openjdk + pkgs.vulkan-loader + pkgs.wayland + pkgs.wayland-protocols + pkgs.weston pkgs.xorg.xorgserver + pkgs.xwayland ]; } diff --git a/src/main/shell/run-electron-app-in-wayland b/src/main/shell/run-electron-app-in-wayland new file mode 100755 index 0000000..fb99d07 --- /dev/null +++ b/src/main/shell/run-electron-app-in-wayland @@ -0,0 +1,49 @@ +#!/usr/bin/env sh +set -eu + +ELECTRON="$1" +APP_ENTRY="src/main/node/app.js" +SIZE="1280x800" +RUNTIME="${XDG_RUNTIME_DIR:-/tmp}" + +# Find free WAYLAND_DISPLAY +for d in 1 2 3 4 5; do + if [ ! -S "$RUNTIME/wayland-$d" ]; then + WAYLAND_NUM="$d" + break + fi +done + +[ -n "${WAYLAND_NUM:-}" ] || { + echo "No free WAYLAND_DISPLAY found" >&2 + exit 1 +} + +export WAYLAND_DISPLAY="wayland-$WAYLAND_NUM" +export XDG_RUNTIME_DIR="$RUNTIME" + +cleanup() { + kill "$ELECTRON_PID" "$WESTON_PID" 2>/dev/null || true +} +trap cleanup EXIT INT TERM + +weston \ + --backend=wayland-backend.so \ + --width="${SIZE%x*}" \ + --height="${SIZE#*x}" \ + --xwayland \ + --socket="$WAYLAND_DISPLAY" & +WESTON_PID=$! + +sleep 1 + +WAYLAND_DISPLAY="$WAYLAND_DISPLAY" \ +DISPLAY="" \ +"${ELECTRON}" "$APP_ENTRY" & +ELECTRON_PID=$! + +while :; do + kill -0 "$ELECTRON_PID" 2>/dev/null || break + kill -0 "$WESTON_PID" 2>/dev/null || break + sleep 0.5 +done