If I want some function to be called when a window gets closed I connect with delete_event
. What should I connect with if I want the function to be called when the user minimizes a Gtk Window. Something like: minimize_event
? I couldn't find anything in the docs.
I was at the very same crossroads, wth only some info and code on python gtk, but not in C.
After looking the docs again and again I realized I got confuse by same sounding names, unions, structures and enums and bitfields. I was handling things as booleans, when it was a bitfield thingy all along.
First:
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 this are bitfields and &
is the "bit and" operator not the boolean &&
.
GDK_WINDOW_STATE_ICONIFIED =2
or 10
in binary
and event->new_window_state
is an int
of which the second bit is active
A Widget can be both maximized and minimized at the same time,
GDK_WINDOW_STATE_MAXIMIZED = 4
or 100
If you minimized a maximized window itsevent->new_window_state = 6
or 110
You can experiment and see what works best for you.
More info:
Final Beware and caveats:
I'm using gtk+2, because of dual win&lin development. The newer gtk+3 might do some things different.
The Gnome Developer Site site has some links broken or wrong, or partially re-writen, with some errors. The page on the first url I put above has
gboolean user_function (GtkWidget *widget,GdkEvent *event,gpointer user_data){}
while the manual in the source code as well as other downloadable manuals has the correct:
gboolean user_function (
GtkWidget *widget,
GdkEventWindowState *event,
gpointer user_data){}
The page also has the incorrect or broken link for the gtk3 page for GdkEventWindowState
.
The gtk+3 version seems as wrong as the gtk+2, I have not seen the gtk+3 manuals with the source code or separate so I don't know if gtk+3 truly modifies the callback for the event and the gdk structures
For the moment as gtk+3 stabilizes*expect* inconsistencies. Use preferably the manuals that came with your source code or linux distro and version gtk+2.
I hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With