How can I find out, using the C language, which graphical environment is installed on Linux?

Asked

Viewed 40 times

-1

How can I find out which graphical environment is installed? Example:

KDE, GNOME, XFCE or LXDE?

  • Your question seems to have some problems and your experience here in Stack Overflow may not be the best because of it. We want you to do well here and get what you want, but for that we need you to do your part. Here are some guidelines that will help you: Stack Overflow Survival Guide in English (short version). If the solution is very simple it is still possible for someone to do so in the comments.

  • Not to be rude, but why is this publication out of scope? I have seen several publications with extremely simple concepts being answered (and not closed).

1 answer

1


With exactly I believe that is not possible, each graphical environment has its own implementation, something that would not have within the language, unless it uses a third party API.

But I don’t think it needs to go that far you could get the environment variables in case XDG_CURRENT_DESKTOP, however according to this reply https://unix.stackexchange.com/a/116694/182604 depending on the distro or environments this variable may not be available, so the author suggested using with fallback the XDG_DATA_DIRS

You can combine with getenv()

#include <stdlib.h>

int main() {
    char* desk = getenv("XDG_CURRENT_DESKTOP");

    ...

    return 0;
}

This is just hypothetical, you can do the part as you wish, I haven’t had the opportunity to test on Centos yet, but once tested I will return the values.

Still I would like to suggest one thing, I see no reason to worry about the graphical environment that the user uses, in linux desktop environments I find it ideal that windows of their programs style with the same style of the user’s GUI, instead of having to adjust one by one, is to create the basic and "inherit" measures, elements and resources (icons for example) proper to the system, since the user is already familiar with such a visual, assuming that the interest is to adjust something in the GUI

Now if your intention is to use some program that comes with gnome, you could simply try running the exec() or fork() (depends on the need) and if it fails you would inform the user that something is missing.

  • Thank you very much, friend! You helped me a lot! :)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.