MCPcopy Create free account
hub / github.com/TheAssassin/AppImageLauncher / isHeadless

Function isHeadless

src/shared/shared.cpp:210–241  ·  view source on GitHub ↗

TODO: check if this works with Wayland

Source from the content-addressed store, hash-verified

208
209// TODO: check if this works with Wayland
210bool isHeadless() {
211 bool isHeadless = true;
212
213 // not really clean to abuse env vars as "global storage", but hey, it works
214 if (getenv("_FORCE_HEADLESS")) {
215 return true;
216 }
217
218 QProcess proc;
219 proc.setProgram("xhost");
220 proc.setStandardOutputFile(QProcess::nullDevice());
221 proc.setStandardErrorFile(QProcess::nullDevice());
222
223 proc.start();
224 proc.waitForFinished();
225
226 switch (proc.exitCode()) {
227 case 255: {
228 // program not found, using fallback method
229 isHeadless = (getenv("DISPLAY") == nullptr);
230 break;
231 }
232 case 0:
233 case 1:
234 isHeadless = proc.exitCode() == 1;
235 break;
236 default:
237 throw std::runtime_error("Headless detection failed: unexpected exit code from xhost");
238 }
239
240 return isHeadless;
241}
242
243// avoids code duplication, and works for both graphical and non-graphical environments
244void displayMessageBox(const QString& title, const QString& message, const QMessageBox::Icon icon) {

Callers 3

displayMessageBoxFunction · 0.85
getAppFunction · 0.85
mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected