I have a program that should behave a little bit differently if run from terminal or desktop. If I launch from the desktop I’m looking for a message box pop up, and if run from terminal a simple yes/no command prompt.
So, there’s three things I need to detect. If running on a headless system it should just exit, and if there is an actual user present show a dialogue choice.
I know about
getenv("DISPLAY") for detecting whether there is a monitor or not, and
isatty(filno(stdin)) for detecting whether an application was launched through a pipe, which is how most of the Linux desktops launch applications.
Is there a more standardized or reliable means of detecting desktop or terminal launch?