7

For X11 I can start applications from the Linux console or via SSH (or shell scripts, etc.) with

DISPLAY=:0 application

And may need to make sure the application finds the authentication files or use commands like xhost.

But how do I start Wayland programs from outside the Wayland session? I only found information on how to start Wayland compositors from the console, but no hint how to start applications inside a Wayland session and how to select which session is used, if there are more than one.


X11 equivalent:

I want to start a program inside an existing session.

  • I am logged in, e.g., using lightdm into a KDE or GNOME session.
  • My user has access to the corresponding X11 cookies.
  • I switch to a Linux console, e.g., by pressing Ctrl-Alt-F3
  • I run DISPLAY=:0 xmessage "Hello!"
  • I switch back to the X11 session, e.g., by pressing Ctrl-Alt-F7 when the X-Server is using on VT 7.
  • I see the xmessage dialog and can interact with it.

This works for every X11 program as the programs behave like they were started from a terminal emulator, only that the DISPLAY variable is not set automatically on a Linux shell like it is in a X11 session.

After defining the DISPLAY variable, the programs use the same unix sockets and other IPC mechanisms as the programs that were started in the X11 session and do not have to know about not being started from a graphical application.

allo
  • 1,248

2 Answers2

5

The Wayland equivalent is to set the WAYLAND_DISPLAY environment variable. For example, when I run env | grep WAYLAND_DISPLAY in a terminal under Wayland, I see WAYLAND_DISPLAY=wayland-1.

Over SSH, I can run WAYLAND_DISPLAY=wayland-1 grim to capture a screenshot of what Wayland displays.

Michael
  • 151
2

Wayland is a protocol, not a server like X used to be. So technically you are going to run app under compositor, let's say kwin_wayland. You need set three variables before you can run an app.

  1. DBUS_SESSION_BUS_ADDRESS of a running session, so you can connect to the BUS and let application communicate with each other.
  2. XDG_RUNTIME_DIR
  3. WAYLAND_DISPLAY

Let's say you use kde plasma. We need to find out content of the three variables mentioned before.

  1. pgrep --uid $(id --user) --newest plasmashell
    5463

  2. tr '\0' '\n' < /proc/5463/environ | grep -E 'WAYLAND_DISPLAY|XDG_RUNTIME_DIR|DBUS_SESSION_BUS_ADDRESS'
    XDG_RUNTIME_DIR=/run/user/1000
    DBUS_SESSION_BUS_ADDRESS=unix:path=/tmp/dbus-VLYvZVxpdU,guid=d2b59c17cb0ac885a134913f670a9159
    WAYLAND_DISPLAY=wayland-0

Now I can run app (here RDP server) from (ssh) console inside already running kwin_wayland session.

XDG_RUNTIME_DIR=/run/user/1000 WAYLAND_DISPLAY=wayland-0 DBUS_SESSION_BUS_ADDRESS=unix:path=/tmp/dbus-VLYvZVxpdU krdpserver -u frank -p rdppassword

Onliner: tr '\0' '\n' < /proc/$(pgrep -u $(id -u) -n plasmashell)/environ | grep -E 'WAYLAND_DISPLAY|XDG_RUNTIME_DIR|DBUS_SESSION_BUS_ADDRESS'