[Top][All Lists]

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

change to gtk-1.2/threads.scm

From: Jon Wilson
Subject: change to gtk-1.2/threads.scm
Date: Sat, 01 Jul 2006 22:34:55 -0500
User-agent: Mozilla Thunderbird 1.0.2 (X11/20050324)

I was playing around with guile-gtk today. It looks quite nice. I'm trying to write a guile + gtk program that will give me both a useful window (to draw in), and a guile repl. I'll have some procedures available to guile which emit signals to the drawing area in the window to cause drawing to happen in the callbacks. So, given this, gtk-threads-ensure-handler seemed like the thing to use. However, it also seemed to do some slightly screwy things. One of them I think I have largely fixed. That is, after starting the gtk-main loop in another thread (via ensure-handler of course), the main guile thread in which the repl was running would no longer respond. I could type scheme expressions there and hit enter, and nothing would happen (well, as I typed, characters appeared, but it was plain that no evaluation was occuring), until I closed the gtk-window, at which time everything I had typed would be evaluated as normal. This, I believe I have fixed. If we change threads.scm to:

(define gtk-threads-handler? #f)
(define gtk-threads-ensure-handler #f)

(let ((handler-running? #f))
 (set! gtk-threads-handler?
       (lambda () handler-running?))
 (set! gtk-threads-ensure-handler
       (lambda ()
         (if (not handler-running?)
                       (lambda ()
                         (set! handler-running? #t))
                       (lambda ()
                         (while #t
                                (if (gtk-events-pending)
                       (lambda ()
                         (set! handler-running? #f)

This allows another thread to run unimpeded as long as there are not gtk events waiting. Also, by putting the definitions of these two functions into a let, we can protect handler-running? from getting clobbered, as well as avoiding taking up an extra top-level binding.

So, the second problem that I have is that after ending a guile session in which I had run ensure-handler, the terminal is broken. I type, but no text appears. However, the terminal is clearly getting what I type. If I don't look at what I am typing everything is as normal. Anybody know what might cause this? I exit the gtk-main loop by closing the window (thus calling gtk-main-quit, I believe), and then exit guile by pressing C-d at the remaining guile prompt. Is this the wrong thing?

reply via email to

[Prev in Thread] Current Thread [Next in Thread]