This is the mail archive of the
guile@sourceware.cygnus.com
mailing list for the Guile project.
Re: New Guile module: guile-gtkthreads
- To: guile at sourceware dot cygnus dot com
- Subject: Re: New Guile module: guile-gtkthreads
- From: Mikael Djurfeldt <mdj at mdj dot nada dot kth dot se>
- Date: 30 Mar 2000 08:00:28 +0200
- Cc: djurfeldt at nada dot kth dot se
- References: <E12aKBf-000457-00@mdj.nada.kth.se>
Mikael Djurfeldt <mdj@mdj.nada.kth.se> writes:
> I've made the frist version of a new Guile module:
>
> http://www.nada.kth.se/~mdj/guile-gtkthreads/guile-gtkthreads-0.1.0.tar.gz
New version: 0.1.2 can now be found at the same place.
Here's the new README:
This is a library for people who are using guile-gtk but prefer using
threads instead of an event loop.
Suggestions and contributions are welcome (mailto:djurfeldt@nada.kth.se).
Dependencies
------------
This library needs to be compiled with:
* libguile >2000-03-29 with thread support (--with-threads)
* guile-gtk
Getting started
---------------
(use-modules (gtk gtk) (gtk threads))
(define w (gtk-window-new 'toplevel))
(define b (gtk-button-new-with-label "Hello"))
(gtk-container-add w b)
(gtk-widget-show-all w)
(begin-thread (gtk-main)) ; this becomes the handler thread
Notes
-----
* guile-gtkthreads plugs in COOP-threads into glib. So, the GNOME
libraries will use COOP for threads administration instead of
pthreads.
* If the gtk commands above are placed after the handler thread is
started, nothing seems to happen. The reason is that the X queue
hasn't been flushed. You can flush the display with `gdk-flush'.
Flushing the X queue at every command could be inefficient,
especially if the application is running on a remote display.
* If one executes gtk commands which add new input sources, one might
think that the handler thread won't see them. In fact, the handler
wakes up when new input sources are added, so this is no problem.
Known problems
--------------
None.
Bug reports
-----------
Send bug reports to bug-guile@gnu.org.
Some details about glib, gdk and gtk internals
----------------------------------------------
* Waking the handler loop
GLIB has a static function gmain.c:g_main_wakeup. The polling
function listens to a special wakeup pipe and g_main_wakeup writes to
this. Functions such as g_source_add and g_main_add_poll_unlocked
calls g_main_wakeup. This way, the handler loop is wakes up when
needed.
* Emission hooks
The following code adds a show hook to the signal "show" in window
widgets. It is executed each time this signal is emitted.
#include <gtk/gtktypeutils.h>
static gboolean
show_emission (GtkObject *object,
guint signal_id,
guint n_params,
GtkArg *params,
gpointer data)
{
/* do stuff */
return TRUE; /* returning FALSE => hook is removed from list */
}
{
int sig = gtk_signal_lookup ("show", GTK_TYPE_WINDOW);
int ok = gtk_signal_add_emission_hook (sig, show_emission, NULL);
}