shell script: test for graphical session
A (bash) script wants to put up a GUI (yad) if it can, or otherwise try
to interact with the user on the terminal.
Previously I was using loginctl:
loginctl show-session -p Type $XDG_SESSION_ID
and looking for 'Type=x11' or 'Type=wayland'
However, if a user logs in on a tty and then runs 'startx' (I don't know
if Wayland has an equivalent) then the above command returns 'Type=tty'
even when X is running.
($XDG_SESSION_TYPE gives the same results.)
I've replaced the test with
[[ -n $DISPLAY || -n $WAYLAND_DISPLAY ]] && <use GUI>
but environment variables are a bit fragile and I was wondering if there
might be a better way.
For example, is there a scriptable GTK test for whether widgets can be
drawn?
--
John
Reply to: