Qt - How to Detect Whether The Application Is Running on Gnome or Kde

Qt - how to detect whether the application is running on GNOME or KDE?

Use QProcess to run pidof foo, then check its stdout? If this is not what you want, search /proc/.

Macro detect KDE or GNOME in qt4

Qt does not provide this kind of defines based on the desktop environment. If you need to know the desktop environment at compilation time, then your best bet would be to modify your build system to pass the necessary defines to the compiler. The desktop environment can be concluded by different prerequisites such as environment variables, availability of applications, libraries or headers. The choice depends on what you're trying to do.

For instance, if you take the environment inspection route, KDE defines the KDE_FULL_SESSION variable whereas GNOME has the DESKTOP_SESSION variable set to "gnome". FYI, that's how Qt detects the DE at run time.

Do Qt Applications require KDE?

When running under X, Qt apps and the Window Manager are both X Clients. They both communicate with a XServer to draw, receive input, or manipulate windows. The XServer knows about the hardware and handles drawing to a specific monitor, receiving mouse input etc.

It is possible to run a Qt application without a desktop environment, and even without a window manager (although you won't be able to move/resize the program). Window managers etc are just normal X programs that are running that provide their own functionality but only indirectly interact with each other. They don't depend on another specific program running.

The state of windows (position, ordering, contents) are managed by the X Server, and can be queried and changed by a program such as the window manager.

The window manager handles the sizing, positioning and decoration of windows. It receives events when a window is created/changed so it can do so. It draws the frame around the outside of a window, and handles clicks on close, maximize, drags of the window etc.

The Qt application draws inside the main window and handles mouse clicks and keypresses inside the window.

Qt can communicate with the window manager by sending XEvents from the window (resize/move), or setting WM Hints (dialog, important, not resizable). These go through the XServer and won't have any effect if no program is listening for them.

Detect enter/exit session under KDE/Gnome with FreePascal

Yes, a dbus package is installed, and afaik I ran the examples end of last year.

See /packages/dbus/examples/busexample.pp for an example

Detect desktop environment in Linux programmatically in C

Pick a set of window managers you care about: metacity, xfwm4, flwm, etc. You can look for those in your grep of ps (or search through /proc). Gnome libraries don't necessarily mean that someone's running the whole gnome desktop environment, but then Gnome and KDE aren't window managers. If WMs are what you care about, look for those.

Can I write an application in Qt that runs with Gnome?

  1. If you write a Qt app, it will run fine under GNOME, provided that the user has the Qt libraries installed (or, and this is often better, you ship them with your app)

  2. Your Qt app will look almost native under GNOME if you make it use QGtkStyle as its widgetstyle (this is done via QApplication::setStyle). This means the app won't look ugly or foreign under GNOME (except for some very small details)

Detect control buttons position at window title bar with Qt (on X11)

I'm afraid Qt doesn't know anything about the window manager it is running on. It only provides the window contents to the WM.

You might want to have a look at this: Qt - how to detect whether the application is running on GNOME or KDE?

Basically they detect if the pid of a WM is present by name, but if a WM process name gets renamed at some point, your code will break.

Other than that (which is kind of specific to Linux), Qt can indeed tells you the platform it is running on (see documentation), therefore you can deduce the window controls displacement

Can we develop kde applications using a machine that runs gnome?

Yes. You just have to make sure you have the KDE libraries and development headers installed. (Should be a package named something like kdelibs-devel in your package manager.) You may find it difficult to test your application properly, though, for obvious reasons.



Related Topics



Leave a reply



Submit