GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Sat Nov 01, 2014 4:06 am

All times are UTC




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: gtk_fixed_move called from size-allocated event freezes GUI
PostPosted: Wed Dec 17, 2008 9:15 am 
Offline
GTK+ Geek

Joined: Mon Aug 18, 2008 7:33 pm
Posts: 50
Hi,

I have a gtk fixed widget with a viewport as a child. I connected the
size-allocated signal to the gtk fixed widget:
[code lang=C]
hbox = gtk_hbox_new (FALSE, 0);
gtk_box_pack_start (GTK_BOX(vbox1), hbox, TRUE, TRUE, 0);

fixed = gtk_fixed_new ();
gtk_box_pack_start (GTK_BOX (hbox), fixed, TRUE, TRUE, 0);

img_struct->viewport = gtk_viewport_new(NULL,NULL);
gtk_fixed_put (GTK_FIXED (fixed), img_struct->viewport, 0, 0);
g_signal_connect (G_OBJECT (fixed), "size-allocate", G_CALLBACK
(img_size_allocate_event), img_struct);
[/code]
I need to move a fixed size viewport when the user resizes the window
so in the handler I have:
[code lang=C]
static void img_size_allocate_event (GtkWidget *widget, GtkAllocation
*allocation, img_window_struct *img)
{
gint x,y;

x = (widget->allocation.width - 720) / 2;
y = (widget->allocation.height - 576) / 2;

if (x == 0 || y == 0)
return;
gtk_fixed_move(GTK_FIXED(widget),img->viewport,x,y);
}
[/code]

The call to gtk_fixed_move freezes the GUI; this is the gdb stack:
(gdb) r
Starting program: /home/gt/Projects/imagination/src/imagination
[Thread debugging using libthread_db enabled]
[New Thread 0xb742f6c0 (LWP 17007)]

Program received signal SIGINT, Interrupt.
[Switching to Thread 0xb742f6c0 (LWP 17007)]
0xb795a7dd in g_atomic_int_exchange_and_add () from /usr/lib/libglib-2.0.so.0
(gdb) bt
#0 0xb795a7dd in g_atomic_int_exchange_and_add () from
/usr/lib/libglib-2.0.so.0
#1 0xb7a0ca53 in g_object_ref () from /usr/lib/libgobject-2.0.so.0
#2 0xb7a0eef9 in ?? () from /usr/lib/libgobject-2.0.so.0
#3 0xb7a2d1ee in g_value_set_instance () from /usr/lib/libgobject-2.0.so.0
#4 0xb7a208bf in g_signal_emit_valist () from /usr/lib/libgobject-2.0.so.0
#5 0xb7a20ed0 in g_signal_emit_by_name () from /usr/lib/libgobject-2.0.so.0
#6 0xb7d77536 in ?? () from /usr/lib/libgtk-x11-2.0.so.0
#7 0xb7d7776a in ?? () from /usr/lib/libgtk-x11-2.0.so.0
#8 0xb7e3253f in gtk_widget_size_request () from /usr/lib/libgtk-x11-2.0.so.0
#9 0xb7cc9225 in ?? () from /usr/lib/libgtk-x11-2.0.so.0
#10 0xb7a1715a in g_cclosure_marshal_VOID__BOXED () from
/usr/lib/libgobject-2.0.so.0
#11 0xb7a09069 in ?? () from /usr/lib/libgobject-2.0.so.0
#12 0xb7a0a81f in g_closure_invoke () from /usr/lib/libgobject-2.0.so.0
#13 0xb7a1ebbb in ?? () from /usr/lib/libgobject-2.0.so.0
#14 0xb7a20c0f in g_signal_emit_valist () from /usr/lib/libgobject-2.0.so.0
#15 0xb7a20ed0 in g_signal_emit_by_name () from /usr/lib/libgobject-2.0.so.0
#16 0xb7d77536 in ?? () from /usr/lib/libgtk-x11-2.0.so.0
#17 0xb7d7776a in ?? () from /usr/lib/libgtk-x11-2.0.so.0
#18 0xb7e3253f in gtk_widget_size_request () from /usr/lib/libgtk-x11-2.0.so.0
#19 0xb7e27c35 in ?? () from /usr/lib/libgtk-x11-2.0.so.0
#20 0xb7a1715a in g_cclosure_marshal_VOID__BOXED () from
/usr/lib/libgobject-2.0.so.0
#21 0xb7a09069 in ?? () from /usr/lib/libgobject-2.0.so.0
#22 0xb7a0a81f in g_closure_invoke () from /usr/lib/libgobject-2.0.so.0
#23 0xb7a1ebbb in ?? () from /usr/lib/libgobject-2.0.so.0
#24 0xb7a20c0f in g_signal_emit_valist () from /usr/lib/libgobject-2.0.so.0
#25 0xb7a20ed0 in g_signal_emit_by_name () from /usr/lib/libgobject-2.0.so.0
#26 0xb7d77536 in ?? () from /usr/lib/libgtk-x11-2.0.so.0

Where am I wrong?

_________________
Imagination, a GTK+2 simple DVD slideshow creator
http://imagination.sf.net

Xarchiver, a lightweight GTK+2 archive manager
http://xarchiver.sf.net


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 17, 2008 12:40 pm 
Offline
Never Seen the Sunlight

Joined: Wed Jul 23, 2008 10:31 am
Posts: 2406
Location: Slovenia
Hi.

You get dead-locked because gtk_fixed_move will cause "size-allocate" signal to be emitted.

You may think about replacing the GtkFixed widget, since most other container widgets can handle centering of their contents without programmers intervention. Or are there any special requirements that make using GtkFixed a necessity?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 17, 2008 12:50 pm 
Offline
GTK+ Geek

Joined: Mon Aug 18, 2008 7:33 pm
Posts: 50
Hi Tadeboro,

I don't think the dead-lock is caused by the gtk_fixed_move itself because I surrounded (after posting here) it with g_signal_handlers_block_by_func and with g_signal_handlers_unblock_by_func and it still freezes. By the way I solved the problem by adding

while (gtk_events_pending())
gtk_main_iteration()

just after the call to gtk_fixed_move.
My problem is to center a viewport of 720x576 pixels in the main window when the user resizes it. If you know any other container that could be fitting for this please let me know. If you want to download the code for playing with it:

$ svn co http://imagination.svn.sourceforge.net/ ... magination

Thanks for replying,

_________________
Imagination, a GTK+2 simple DVD slideshow creator
http://imagination.sf.net

Xarchiver, a lightweight GTK+2 archive manager
http://xarchiver.sf.net


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 17, 2008 1:47 pm 
Offline
Never Seen the Sunlight

Joined: Wed Jul 23, 2008 10:31 am
Posts: 2406
Location: Slovenia
Hi.

I've checked out your code and made some minor modifications, which enables you to remove that annoying "size-allocate" callback.

main-window.c
Code:
...

   /* Create the image area and the other widgets */
   hbox = gtk_hbox_new (FALSE, 0);
   gtk_box_pack_start ((GtkBox*)vbox1, hbox, TRUE, TRUE, 0);

   /* tadeboro edit */
   /*fixed = gtk_fixed_new ();*/
   fixed = gtk_alignment_new( 0.5, 0.5, 0, 0 );
   /* tadeboro edit end */
   gtk_box_pack_start (GTK_BOX (hbox), fixed, TRUE, TRUE, 0);

   img_struct->viewport = gtk_viewport_new(NULL,NULL);
   /* tadeboro edit */
   /*gtk_fixed_put (GTK_FIXED (fixed), img_struct->viewport, 0, 0);*/
   gtk_container_add( GTK_CONTAINER( fixed ), img_struct->viewport );
   /* tadeboro edit end */
   gtk_widget_set_size_request (img_struct->viewport, 720, 576);
   gtk_widget_modify_bg(img_struct->viewport,GTK_STATE_NORMAL,&background_color);
   gtk_viewport_set_shadow_type((GtkViewport*)img_struct->viewport, GTK_SHADOW_IN);
   gtk_container_set_border_width((GtkContainer*)img_struct->viewport,10);
   /* tadeboro edit */
   /*g_signal_connect (G_OBJECT (fixed), "size-allocate", G_CALLBACK (img_size_allocate_event), img_struct);*/
   /* tadeboro edit end */

   img_struct->image_area = gtk_image_new();
   gtk_container_add (GTK_CONTAINER (img_struct->viewport), img_struct->image_area);

...


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 17, 2008 1:53 pm 
Offline
GTK+ Geek

Joined: Mon Aug 18, 2008 7:33 pm
Posts: 50
tadeboro wrote:
Hi.
I've checked out your code and made some minor modifications, which enables you to remove that annoying "size-allocate" callback.


Tadeboro, you are a genius!!!! I'm surprised how it is so easy sometimes to solve problems. This way it's GTK itself to handle the move of the fixed viewport.

Thank you a lot!

_________________
Imagination, a GTK+2 simple DVD slideshow creator
http://imagination.sf.net

Xarchiver, a lightweight GTK+2 archive manager
http://xarchiver.sf.net


Top
 Profile  
 
 Post subject: Re: gtk_fixed_move called from size-allocated event freezes
PostPosted: Mon Feb 20, 2012 7:04 pm 
Offline
GTK+ Geek

Joined: Mon Aug 18, 2008 7:33 pm
Posts: 50
Better late than ever buddy. Thank you. Would you be interested to continue Imagination development?

Cheers,
colossus73

_________________
Imagination, a GTK+2 simple DVD slideshow creator
http://imagination.sf.net

Xarchiver, a lightweight GTK+2 archive manager
http://xarchiver.sf.net


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group