0

I write an xlib C application. I need different behavior of it, depending if it running with xinit ./myapp from CLI when no X server started, from running in normal KDE desktop.

argv[0] returns same value in both cases (i.e. not sees xinit prefix).

How i can determine when xinit was used for starting my app?

jpka
  • 131
  • 8
  • Not sure I understand the question. The xinit is going to start the X server, therefore in both cases you can assume that the X server is running. As far as I know there are no ways to determine such thing. – BЈовић Jun 26 '18 at 13:31
  • Are you just looking for whether a window manager is running? If so, then maybe [this question](https://stackoverflow.com/questions/758648/find-the-name-of-the-x-window-manager) will help. There are still other ways to start X without a DE / window manager besides using `xinit`, so checking for `xinit` is perhaps not a good idea. – Candy Gumdrop Jun 26 '18 at 14:23

1 Answers1

0

Thanks for comments. I do not know how to describe my task more precisely, not really i need about exactly xinit (or X server or so). Maybe yes i need to know is Window manager is running. In fact i just need to determine if kwin's color inversion is active (and this is answer why i need to detect, even when i know that A X program should not have to care under which window manager it is displayed. in URL above). But it is quite complex to determine inversion exactly. But because inversion is turned on permanently in KDE for me, i can maybe test for Window manager is running...

Currently, using suggested solution, i was able to solve it at least for my particular case. But not sure if it portable enough.

fp = popen("/usr/bin/xprop -root _NET_SUPPORTING_WM_CHECK", "r");
if (fp == NULL) {
    printf("Failed to run `/usr/bin/xprop -root _NET_SUPPORTING_WM_CHECK`\n" );
    exit(1);
}
fgets(cmdout, sizeof(cmdout), fp);
pclose(fp);
i = strncmp(cmdout, "_NET_SUPPORTING_WM_CHECK(WINDOW): window id #", 40);
if (i == 0) {
    inverted_colors = 1;
    printf ("Window manager detected.\n");
} else {
    inverted_colors = 0;
    printf ("No window manager detected.\n");
}
jpka
  • 131
  • 8