What is a Gtk event raised when a window is minimized?

If I want a function to be called when the window is closed, I connect to delete_event . What should I connect with if I want the function to be called when the user minimizes the Gtk window. Something like: minimize_event ? I could not find anything in the documents.

+4
source share
1 answer

I was at the same crossroads, only with some information and python gtk code, but not C.

After viewing the documents again and again, I realized that I was confused in the same sound of names, unions, structures and enumerations and bit fields. I treated things like Boolean when it was all cue ball.

Firstly:

 g_signal_connect( G_OBJECT(window), "window-state-event", G_CALLBACK(callback_func), userDataPointer); 

Then:

 gboolean callback_func( GtkWidget *widget, GdkEventWindowState *event, gpointer user_data) { //some code //Minimized window check if(event->new_window_state & GDK_WINDOW_STATE_ICONIFIED){ //some other code } //some more other code return TRUE; } 

Remember that these are bit fields, and & is the bit and operator is not a logical && . GDK_WINDOW_STATE_ICONIFIED =2 or 10 in binary and event->new_window_state is int , of which the second bit is active

The widget can be either maximized or minimized at the same time, GDK_WINDOW_STATE_MAXIMIZED = 4 or 100

If you minimized the maximally maximized window, its event->new_window_state = 6 or 110

You can experiment and see what works best for you.

Additional Information:

Final Beware and Caveats:

I am using gtk + 2 due to the development of dual win & lin. New gtk + 3 can do something else.

Website The Gnome developer website contains some messages that were broken or erroneous or partially overwritten, with some errors. The page on the first url that I set above has

 gboolean user_function (GtkWidget *widget,GdkEvent *event,gpointer user_data){} 

while the manual in the source code, as well as in other downloadable manuals, has the correct meaning:

 gboolean user_function ( GtkWidget *widget, GdkEventWindowState *event, gpointer user_data){} 

The page also has an invalid or broken link for the gtk3 page for GdkEventWindowState . The gtk + 3 version seems to be wrong, like gtk + 2, I havenโ€™t seen the gtk + 3 manual with source code or separately, so I donโ€™t know if gtk + 3 really changes the callback for the gdk event and structure

At the moment, when gtk + 3 stabilizes * expects * inconsistencies. Use preferably the manuals provided with the source code or the Linux distribution and the gtk + 2 version.

Hope this helps.

+5
source

Source: https://habr.com/ru/post/1379749/


All Articles