GTK C - How to edit the window close button function (X button in the upper right corner)?

I am wondering how to edit the close button (or minimize / enlarge buttons) in the upper right corner of the window that was created using the GTK library. I'm trying to remove a user ability in order to destroy this window, and only allow the top-level window to destroy it, so I want the X button (close the window) in the upper right corner to hide only the window, and not close it - still allowing to run in background mode.

I'm a little new to gtk and I went through a few beginner tutorials in terms of creating windows and adding buttons, but nothing very advanced.

I assume this can be accomplished by calling gtk_window_hide in a window instead of the current function of the X button, but I'm not sure where to use it, because the functions for the buttons by default do not seem to be easily accessible.

+5
source share
3 answers

In GTK, you listen to signals sent by widgets. In other languages, such as Java (in which you may be more familiar with terminology), they are often called events.

If an event occurs, such as the "removal" of the widget, a corresponding signal arises, which you can apply to by connecting to g_signal_connect and the like.

I suggest you install devhelp for good documentation / online help for GTK.

, , .

    #include <stdio.h>
    #include <gtk/gtk.h>
    #include <stdlib.h>

    int
    main (int argc, char **argv)
    {
      GtkWidget *window;

      gtk_init (&argc, &argv);

      window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
      g_signal_connect (window, "delete_event", G_CALLBACK (gtk_window_iconify), NULL);

      gtk_widget_show (window);
      gtk_main ();

      return EXIT_SUCCESS;
    }
+8

, gtk_widget_hide_on_delete .

g_signal_connect (window, "delete-event", G_CALLBACK (gtk_widget_hide_on_delete), NULL);

. , /.

"delete-event" - , "" .

+4

You need to listen to delete-event for the window widget.

+1
source

All Articles