Skip to content

Commit 9c53c70

Browse files
Copilotlijy91
andcommitted
Improve Linux WindowManager headless environment handling
Co-authored-by: lijy91 <[email protected]>
1 parent d125a1b commit 9c53c70

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/platform/linux/window_manager_linux.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,22 @@
1212
namespace nativeapi {
1313

1414
WindowManager::WindowManager() {
15-
// Initialize GTK if not already initialized (check if default display exists)
15+
// Try to initialize GTK if not already initialized
16+
// In headless environments, this may fail, which is acceptable
1617
if (!gdk_display_get_default()) {
17-
gtk_init(nullptr, nullptr);
18+
// Temporarily redirect stderr to suppress GTK warnings in headless environments
19+
FILE* original_stderr = stderr;
20+
freopen("/dev/null", "w", stderr);
21+
22+
gboolean gtk_result = gtk_init_check(nullptr, nullptr);
23+
24+
// Restore stderr
25+
fflush(stderr);
26+
freopen("/dev/tty", "w", stderr);
27+
stderr = original_stderr;
28+
29+
// gtk_init_check returns FALSE if initialization failed (e.g., no display)
30+
// This is acceptable for headless environments
1831
}
1932
}
2033

0 commit comments

Comments
 (0)