Shrinking and growing widgets in GTK+ 3.x



Heya,

One of the features of Totem (and one implemented in a number of movie
players) is to resize the video to match the actual video size (or a
multiple of it). For example, a 320x480 video would see Totem resize its
video canvas to 480x320, if the preference is enabled.

The old GTK+ 2.x code did that by:
- shrinking the toplevel to 1x1 (so all the widgets in the window get
their minimum size set)
- wait for the "size-request"
- request our real size (480x320) in the size-request signal
- and unset that size request in an idle (so that the window can be
shrinked)

http://git.gnome.org/browse/totem/tree/src/backend/video-utils.c#n197

It's pretty gruesome, but mostly works.

For GTK+ 3.x, I wanted to clean that code.

I tried saving our wanted size, calling gtk_widget_queue_resize() and
wait for ->get_preferred_{width,height} to be called, and set the wanted
size as the natural size. Problem is that this only worked when growing
the window, not shrinking it.

My current backup plan was to do the above in 2 steps:
- save our wanted size and queue a resize
* set the natural size to 1x1, and queue an idle handler
- idle handler calls gtk_widget_queue_resize()
* set the natural size to the actual wanted size

This is just about as gruesome as the original GTK+ 2.x code.

Does anyone have a better idea on how i implement my own sync-ish
"gtk_widget_resize()".

Cheers



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]