linux check if x11

C++
echo $XDG_SESSION_TYPE
Source

Also in C++: