Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How I can find out if a Linux system uses Wayland or X11?

Used language

I am using C++14 with cmake for my program.

Problem:

I would like to know how I can find out if a Linux system uses Wayland or X11 as a window system to be able to use both APIs in my source code without conflict. Thus creating a window with Wayland when Wayland is available and otherwise use the X11 API.

Note: I know there is XWayland, but I want to use native X11 and native Wayland without something like XWayland.

EDIT: To clarify some things: I don't want to check for X11 or Wayland at compile-time, but instead at runtime, because then I just have to compile the code once and it doesn't require the user to think about which version to use.

like image 544
ShadowDragon Avatar asked Aug 06 '17 20:08

ShadowDragon


People also ask

How do I know if I have Wayland or X11?

Determining whether you are using Wayland If the window is running in wayland it will say “MetaWindowWayland” and if it is running in X11 it will say “MetaWindowX11”.

How do I know if X11 is running?

To test to make sure X11 is working properly, run “xeyes” and a simple GUI should appear on the screen. That's it! Any other application (Emacs, Matlab, etc) that you'd like to run the GUI for, simply start the program and a window will appear.

How do I know if redhat is installed X11?

If you want to check whether x11 is installed, run dpkg -l | grep xorg . If you want to check if x11 is currently running (if logged in) then run echo $XDG_SESSION_TYPE . Paste the output.

How do I know if an app is using Wayland?

Run xwininfo in a terminal window — when you hover over an xwayland window the mouse pointer will turn into a + sign. If you click the window it'll display some information and end, but it won't do anything with native Wayland windows. You can use Ctrl + C to end it.


2 Answers

use the environment variable XDG_SESSION_TYPE

on x11

echo $XDG_SESSION_TYPE
x11

on wayland

$ echo $XDG_SESSION_TYPE
wayland
like image 185
skr Avatar answered Sep 23 '22 05:09

skr


X11 uses the DISPLAY environment variable to find the X server. Wayland uses WAYLAND_DISPLAY. Look for the Wayland variable first. Then if you don't find it or you can't connect go on to using X11.

Do not skip checking the WAYLAND_DISPLAY variable or assume Wayland is running on "wayland-0". Some people want to use nested compositors, which you would bypass. Other people may be running Wayland but want to force X11 rendering by deleting the WAYLAND_DISPLAY variable.

like image 21
Zan Lynx Avatar answered Sep 22 '22 05:09

Zan Lynx