GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Sun Dec 21, 2014 5:29 am

All times are UTC




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Signals from another thread
PostPosted: Tue Jun 17, 2008 8:10 pm 
Offline

Joined: Tue Jun 17, 2008 8:00 pm
Posts: 3
I have a GTK + JACK application... GTK handles the main loop and events, obviously, and the Jack Audio Connection Kit handles audio, calling a callback function in a different thread periodically.

To simplify the example.. let's say I have a GTK Oscillator... The window's contents change whenever JACK calls my callback. At that point I need to redraw it. What's the best way of doing this?

Currently, from my callback I use "gtk_widget_queue_draw", but this doesn't seem to work. The main loop in the main thread is still "sleeping", and it won't process my signal until something else 'wakes it up'... so what's the proper way to trigger a redraw from another thread?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 17, 2008 9:41 pm 
Offline
GTK+ Geek

Joined: Wed May 28, 2008 5:49 pm
Posts: 66
Just a shot in the dark, but look at gtk_main_iteration and the related methods.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 17, 2008 9:45 pm 
Offline

Joined: Tue Jun 17, 2008 8:00 pm
Posts: 3
That would run an iteration in the -other- thread (the callback thread), which is a Very Bad Thing. It needs to run in the main loop's thread.


Top
 Profile  
 
 Post subject: Re: Signals from another thread
PostPosted: Thu Jun 19, 2008 12:45 pm 
Offline
GTK+ Geek

Joined: Sat May 10, 2008 1:52 pm
Posts: 54
Akel wrote:
I have a GTK + JACK application... GTK handles the main loop and events, obviously, and the Jack Audio Connection Kit handles audio, calling a callback function in a different thread periodically.

To simplify the example.. let's say I have a GTK Oscillator... The window's contents change whenever JACK calls my callback. At that point I need to redraw it. What's the best way of doing this?

Currently, from my callback I use "gtk_widget_queue_draw", but this doesn't seem to work. The main loop in the main thread is still "sleeping", and it won't process my signal until something else 'wakes it up'... so what's the proper way to trigger a redraw from another thread?


Akel, did you remember to make all gtk calls in the thread
in between gdk_threads_enter() and gdk_threads_leave() calls?
All GTK calls from a thread should be done like that.

See important info here:
http://research.operationaldynamics.com/blogs/andrew/software/gnome-desktop/gtk-thread-awareness.html
Peter


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 19, 2008 5:39 pm 
Offline

Joined: Tue Jun 17, 2008 8:00 pm
Posts: 3
Ah, excellent, excellent! That indeed did it.

Thankyou!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 19, 2008 7:24 pm 
Offline
GTK+ Geek

Joined: Sat May 10, 2008 1:52 pm
Posts: 54
Akel wrote:
Ah, excellent, excellent! That indeed did it.

Thankyou!


You welcome! .P.


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: Google Adsense [Bot], Yahoo [Bot] and 3 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:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group