I’m doing some testing with Wayland and at the moment I’m oscillating between it and X11.
As some of the options in my autostart scripts at present cause problems in Wayland, I want to bypass those if I’m not running an X11 session.
The ways I’ve found so far to detect which is running are:
Any one of these works once I’ve logged out then back in, but none of them works in the first session logged in after a reboot. Hence my point abour reliably detecting the session type.
Has anyone come across this and/or found a workaround (other than just to log out after a reboot)?
Thanks.
[Edit]: unfortunately, commenters seem to be missing the point. That such things as $XDG_SESSION_TYPE are, for some reason, not available during the first login after a boot. (My suspicion is that this is some sort of SDDM bug).
So what I need is something that will work in an autostart script on the first login after a boot.
# wayland - sway - console - gtk
if (
os.environ.get("XDG_SESSION_TYPE") == "wayland"
or os.environ.get("XDG_SESSION_TYPE") == "tty"
or not os.environ.get("DISPLAY")
or not gtk_available
):
self.no_display = True
Easystroke - X11 mouse gestures - shouldn’t launch on Wayland.
So I do this:
#!/bin/bash
is_wayland() {
if [ "$XDG_SESSION_TYPE" = "wayland" ]; then
return 0
else
return 1
fi
}
if is_wayland; then
echo "The session is running on Wayland. Easystroke will not be started."
else
echo "The session is not running on Wayland. Starting Easystroke..."
easystroke &
fi
Hi there @manyroads - I think you missed the ‘KDE Plasma’ flag in the title - OP wants to launch Plasma desktop with X11 and Wayland available, so ONE script in Autostart has to detect the desktop before deciding what to do.
You might consider upgrading your autostart routine - then just one script can cope with multiple situations.
As the OP asked how to detect a Wayland or X11 session, I slightly modified @Ben’s script so that it runs only when an x11 session is detected (yes, I know I’m being pedantic as, if it isn’t Wayland, it must be x11, but…):
#!/usr/bin/env bash
is_x11() {
if [ "$XDG_SESSION_TYPE" = "x11" ]; then
return 0
else
return 1
fi
}
if is_x11; then
echo "The session is running on X11. Starting the command..."
# (uncomment line below to run the command)
# thecommand &
else
echo "The session is not running on X11. The command will not be started."
fi
I’ll answer my own question (for the benefit of anyone who might come along later needing to do the same thing) as unfortunately everyone has missed the problem that the suggested environment variables aren’t getting set for the first login after a reboot.
The answer is to run: pgrep -f /usr/bin/startplasma-wayland
Then either test for the return code or count the number of lines returned.
There is wayland-detector (python script) which, as the name suggests, detects the current Wayland session.
If Wayland isn’t detected, we can presume that X11 is being used; although it would also be nice to detect when using only a TTY, which this script seems to lack.