linquize
linquize

Reputation: 20386

Check if running in X Window

Linux C program:

What function call can check if running in X Window?

If not in X Window, then printf.

Upvotes: 0

Views: 270

Answers (2)

Leo Chapiro
Leo Chapiro

Reputation: 13984

Do you mean something like this:

#include <X11/Xlib.h>

  // ...

  char *display_name = NULL;

  /* connect to X server */
  if ( (display=XOpenDisplay(display_name)) == NULL )
  {
    //printf or whatever
  }

Upvotes: 4

Nik Bougalis
Nik Bougalis

Reputation: 10613

What do you mean "running in X Window"? Do you mean whether your app is running inside a terminal emulator, like rxvt or xterm instead of a physical console? If so you could use the TERM variable I guess, but it's not reliable (since the user can change it to whatever).

The more important quesion is why is this information important to your application?

Upvotes: 0

Related Questions