Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

minimize signal event gtk

By: a guest on Nov 23rd, 2011  |  syntax: None  |  size: 2.40 KB  |  views: 86  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. I was at the very same crossroads, wth only some info and code on python gtk, but not in C.
  2.  
  3. 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.
  4.  
  5. First:
  6.  
  7.     g_signal_connect(G_OBJECT(window), "window-state-event", G_CALLBACK(callback_func), userDataPointer);
  8.  
  9.  
  10. Then :
  11.  
  12.     gboolean callback_func(GtkWidget *widget,GdkEventWindowState *event,gpointer user_data){
  13.         //some code
  14.         if(event->new_window_state & GDK_WINDOW_STATE_ICONIFIED){//this means minimized
  15.         //some other code
  16.     }
  17.     //some more other code
  18.     return TRUE;
  19.     }
  20.  
  21. Remember this are bitfields and & is the "bit and" operator NOT the boolean &&
  22. GDK_WINDOW_STATE_ICONIFIED =2 or 10 on binary
  23. and event->new_window_state is an int which second bit is active
  24.  
  25. A Widget can be both maximized AND minimized at the same time,
  26. GDK_WINDOW_STATE_MAXIMIZED = 4 or 100
  27.  
  28. If you minimized a maximized window its event->new_window_state = 6 or 110
  29.  
  30. You can experiment and see what works best for you.
  31.  
  32. More info:
  33. http://developer.gnome.org/gtk/stable/GtkWidget.html#GtkWidget-window-state-event
  34. http://developer.gnome.org/gdk/stable/gdk-Event-Structures.html#GdkEventWindowState
  35.  
  36. Final Beware and caveats :
  37.  
  38. I'm using gtk+2, because of dual win&lin development. The newer gtk+3 might do some things different.
  39.  
  40. the http://developer.gnome.org site has some links broken or wrong, or partially re-writen, with some errors. The page on the first url I put above has
  41.  
  42. gboolean user_function (GtkWidget *widget,GdkEvent  *event,gpointer user_data){}
  43.  
  44. while the manual in the source code as well as other downloadable manuals has the correct:
  45.  
  46. gboolean user_function (GtkWidget *widget,GdkEventWindowState *event, gpointer user_data){}
  47.  
  48. The page also has the incorrect or broken link for the gtk3 page for GdkEventWindowState: developer.gnome.org/gdk3/stable/gdk-Event-Structures.html#GdkEventWindowState
  49. 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
  50.  
  51. 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.
  52.  
  53. I hope this helps
  54.