Detecting OS and Window Manager

Tim Hammerquist tim at vegeta.ath.cx
Wed Jun 5 16:33:45 EDT 2002


Andrew Wilkinson graced us by uttering:
> I'm writing a program that integrates with a number of different OSes
> and Window Managers (under Linux), but I need to check what the user
> is running.  I know that...
> 
> import os
> if os.name == 'nt':
> 
> will tell me they're running NT. But under Linux I'd like to know if
> they are running KDE or Gnome, does anyone know a (preferably) simple
> test for this?

Well, windowmanagers aren't as static as operating systems are.  It's
actually possible to run more than one wm at a time.

In any case, I went and experimented with the various wms on my system
and in all cases the $WINDOWMANAGER shell var was set to the full path
of the running wm executable.  This appears to be the only consistent
and reliable var in my environment; for instance, here's a dump of my
wm-related vars:

QTDIR=/usr/lib/qt2
GNOME_PATH=:/opt/gnome:/usr:/opt/gnome:/usr
KDEDIR=/opt/kde2
GNOMEDIR=/opt/gnome
EROOT=/usr/X11R6/share/enlightenment
WINDOWMANAGER=/usr/X11R6/bin/enlightenment

The qt lib on my box is used only by KDE apps.  I am indeed running KDE2
apps.  Gnome is in fact located under the /opt/ dir.  The Enlightenment
tree does start at $EROOT.

There are, of course, more KDE-related vars in a KDE session, and more
Gnome-related vars in a Gnome session, but $WINDOWMANAGER confirms that
I'm actually running Enlightenment (with the Gnome panel and one KDE
app).

However, I'm not sure how this works in instances (which I've had) when
the window manager and desktop environment are different. eg: KDE env
with sawfish wm.

KDE apps run fine under Gnome, Gnome apps run under KDE, and both KDE
and Gnome run under E.  As long as you have the correct libs available
(gtk, qt, etc) you shouldn't need to know what windowmanager is running
anyway.

Thoughts? Ideas?

Tim Hammerquist
-- 
Ford, you're turning into a penguin. Stop it.
    -- Arthur Dent, "The Hitchhiker's Guide to the Galaxy"



More information about the Python-list mailing list