You are not logged in.
This topic keeps coming up. If we want to be able to use the same BL utilities in X11 or Wayland sessions, sometimes they have to adjust their behaviour according to the type of session they're in. It's come up already with eg xwwall and bl-exit and probably many more soon enough.
https://forums.bunsenlabs.org/viewtopic … 13#p145013
https://forums.bunsenlabs.org/viewtopic … 70#p145170
https://forums.bunsenlabs.org/viewtopic … 62#p144962
It would be good to "standardise" a test to use anywhere, maybe even set something in our own environment?
The difficulty depends on whether you're making a test for BL only, or something portable enough to run on different systems (eg xwwall).
Possible tests that have come up:
1) Check the environment variables $DISPLAY and $WAYLAND_DISPLAY. Just be aware that if xwayland is running (it usually is) then both of those will be set in a Wayland session. A check like this should be OK:
if [[ -n $WAYLAND_DISPLAY ]]
then
session_type='wayland'
elif [[ -n $DISPLAY ]]
then
session_type='xorg'
else
: # check if on a terminal
fi
Unfortunately, WAYLAND_SESSION is...
not always reliably set in sway, and I assume in other compositors.
But as BL uses labwc, that might not be an issue for us.
2) Check the envvar $XDG_SESSION_TYPE, which usually returns "wayland" "x11" or "tty". Unfortunately, it returns "tty" on an X11 session started from 'startx'. It's OK with 'labwc' from a terminal though.
3)
loginctl show-session $XDG_SESSION_ID -p Type
This is probably the same under the hood as 2) and also reports 'tty' for X sessions launched from a terminal with 'startx'.
4) If wlr-randr (small utility that ships with BL for Wayland) will run, it means it's found access to a Wayland server, so we can test:
if wlr-randr >/dev/null 2>&1
then
session_type=wayland
fi
The snag is that even on a tty it will say yes as long as there's a Wayland compositor running somewhere.
5) If we're just dealing with a BL session then it should be very easy though! The BL session script of course knows if it's trying to start up a Wayland or X11 session and we can use Micko's idea of setting an environment variable BUNSEN_SESSION_TYPE or whatever, and all other utilities can refer to it.
I have to leave it here today, but any comments are welcome.
...elevator in the Brain Hotel, broken down but just as well...
( a boring Japan blog (currently paused), now on Bluesky, there's also some GitStuff )
Offline
{read mode off}
My first thought it to make it work in BL and state as much.
Interested parties can tweak it to their environment.
{read mod on}
Debian 12 Beardog, SoxDog and still a Conky 1.9er
Offline
5) The BL session script of course knows if it's trying to start up a Wayland or X11 session and we can use Micko's idea of setting an environment variable BUNSEN_SESSION_TYPE or whatever, and all other utilities can refer to it.
We're almost doing this already - in a BL Wayland session the envvar BL_SESSION is available and set to wayland.
At the moment it's only exported in the wayland case so in X11 'echo $BL_SESSION' returns nothing. All we'd need to do to implement this simple test is to export BL_SESSION in both Wayland and X11 sessions. ie edit this section of /usr/bin/bunsenlabs-session:
BL_SESSION=xorg
# check who calls here
case $0 in
*bunsenlabs-session-wayland)
BL_SESSION=wayland
export BL_SESSION
;;
esac
to
BL_SESSION=xorg
export BL_SESSION
# check who calls here
case $0 in
*bunsenlabs-session-wayland)
BL_SESSION=wayland
;;
esac
Possibly rename BL_SESSION to the more obvious BUNSEN_SESSION_TYPE?
...elevator in the Brain Hotel, broken down but just as well...
( a boring Japan blog (currently paused), now on Bluesky, there's also some GitStuff )
Offline
I think the BUNSEN_SESSION_TYPE envar is a good idea (the name ). I have always thought that the envar itself is a good idea.
This can easily be patched in to xwwall and still keep it distro agnostic (well, unless you dive into the code ).
Many other apps can benefit from this approach too, including but certainly not limited to, bl-exit.
#!/bin/sh
echo '#include <stdio.h>\nvoid main() { printf("Hi, bunsenlabs\\n"); return; }' > bunsen.c
gcc bunsen.c -o bunsen
./bunsen
Offline
^Looks like the way to go, and very easily applied - just a tiny edit to bunsenlabs-session.
I guess scripts that want to be portable to non-BL setups could check BUNSEN_SESSION_TYPE first (very fast) and move on to other tests if that envvar isn't set.
Also, trivial change but let's make the X11 value of BUNSEN_SESSION_TYPE "x11" to match $XDG_SESSION_TYPE and the loginctl test.
...elevator in the Brain Hotel, broken down but just as well...
( a boring Japan blog (currently paused), now on Bluesky, there's also some GitStuff )
Offline
BL_SESSION renamed to BUNSEN_SESSION_TYPE and Xorg value set to 'x11' in bunsen-configs on github.
The envvar is now exported whether it's x11 or wayland.
These changes will go in the next upgrade of bunsen-configs.
Last edited by johnraff (2025-08-30 06:34:17)
...elevator in the Brain Hotel, broken down but just as well...
( a boring Japan blog (currently paused), now on Bluesky, there's also some GitStuff )
Offline