TODO: check if this works with Wayland
| 208 | |
| 209 | // TODO: check if this works with Wayland |
| 210 | bool 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 |
| 244 | void displayMessageBox(const QString& title, const QString& message, const QMessageBox::Icon icon) { |
no outgoing calls
no test coverage detected