gtk-builder-tool: Operate without display
authorMatthias Clasen <mclasen@redhat.com>
Mon, 14 Mar 2022 19:40:12 +0000 (15:40 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Mon, 14 Mar 2022 19:40:12 +0000 (15:40 -0400)
The simplify and validate commands can function
without a display connection, only preview absolutely
needs one. Allow this, by using gtk_init_check().

tools/gtk-builder-tool.c

index bc8920704917bfe01e309915d13e0ec04c9c4c73..b62773738aa1d1ceebde4b8a6c20c25a23ce5303 100644 (file)
@@ -109,11 +109,13 @@ log_writer_func (GLogLevelFlags   level,
 int
 main (int argc, const char *argv[])
 {
+  gboolean has_display;
+
   g_set_prgname ("gtk-builder-tool");
 
   g_log_set_writer_func (log_writer_func, NULL, NULL);
 
-  gtk_init ();
+  has_display = gtk_init_check ();
 
   gtk_test_register_all_types ();
 
@@ -133,7 +135,15 @@ main (int argc, const char *argv[])
   else if (strcmp (argv[0], "enumerate") == 0)
     do_enumerate (&argc, &argv);
   else if (strcmp (argv[0], "preview") == 0)
-    do_preview (&argc, &argv);
+    {
+      if (!has_display)
+        {
+          g_printerr ("Could not initialize windowing system\n");
+          return 1;
+        }
+
+      do_preview (&argc, &argv);
+    }
   else
     usage ();