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");
}