GTK4 Hello World

I’ve just built and run the GTK4 Hello World program, and am finding that the text “Hello World” is in the center of an empty screen. However, the documentation example shows that text in a button. So there is no boundary (button) around the text. The window is titled “Window”, but in the example, it is titled “Hello”. However, the code says “Window”, so I suspect that the sample image is wrong.
Can anyone tell me - should there be a button image around the text “Hello World”, or just text on an empty window? No surprise - This is my first GTK4 program.
Thanks!

Code from gtk.org reads:

#include <gtk/gtk.h>

static void
print_hello (GtkWidget *widget,
             gpointer   data)
{
  g_print ("Hello World\n");
}

static void
activate (GtkApplication *app,
          gpointer        user_data)
{
  GtkWidget *window;
  GtkWidget *button;

  window = gtk_application_window_new (app);
  gtk_window_set_title (GTK_WINDOW (window), "Window");
  gtk_window_set_default_size (GTK_WINDOW (window), 200, 200);

  button = gtk_button_new_with_label ("Hello World");
  g_signal_connect (button, "clicked", G_CALLBACK (print_hello), NULL);
  gtk_window_set_child (GTK_WINDOW (window), button);

  gtk_window_present (GTK_WINDOW (window));
}

int
main (int    argc,
      char **argv)
{
  GtkApplication *app;
  int status;

  app = gtk_application_new ("org.gtk.example", G_APPLICATION_FLAGS_NONE);
  g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
  status = g_application_run (G_APPLICATION (app), argc, argv);
  g_object_unref (app);

  return status;
}

Since you’re apparently using X11 on a Parallels VM on macOS, you’re likely not running a window manager, and GTK is not using client-side decorations on X11.

I have just come back to Linux after programming in it over 10 years ago, so I am very rusty on it at present. How would I know if I am running a window manager? I thought it was all included with Debian.
However, you make an excellent point about GTK on MacOS. I may make more sense to switch back to MacOS, which is where I was developing a couple of years back (but using Carbon). I will look into GTK on MAC. Thank you for a great suggestion!

The screenshot has just diverged from the code of hello-world.c. I’ve made them match again now.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.