How could I get name in Python of the display server that is used in current Linux session? I want to know if user uses Xorg or Wayland for example.
- you need to clarify what you mean by current session. The X-Protocol as used by the various X-Server implementations is a network-protocol. The X-Server(s) running on the machine executing an application might be different than the X-Server displaying the application.niko– niko2012-06-06 19:38:29 +00:00Commented Jun 6, 2012 at 19:38
2 Answers
You will need an Xlib Display pointer and a way to call ServerVendor() and possibly VendorRelease().
With .pygtk, you can use gdk_x11_display_get_xdisplay() to get a Display *
Update: I stand corrected: gtkmm has a binding to this function but pygtk apparently does not.
The library still might provide access to the information returned by ServerVendor() (a quick search shows several calls but most of them seem to be used for compatibility workarounds).
Even Python-Xlib does not seem to provide a binding to ServerVendor(). You may have to write your own module.
Comments
I don't know precisely what this does with Wayland, but you may be able to use xdpyinfo like so:
import subprocess p = subprocess.Popen(['xdpyinfo'], stdout=subprocess.PIPE) for line in p.communicate()[0].split('\n'): if line.startswith('vendor'): k, v = line.split(':') v = v.strip() print "%s=%s" % (k, v)