[cl-gtk2-devel] how to send messages to a window?

Tamas Papp tkpapp at gmail.com
Wed Apr 21 08:50:47 UTC 2010


Hi,

How can I send an "expose" message to a window from _outside_ the main
loop?

I need this for the following: I have a Cairo xlib image surface on
which I am drawing.  Whenever the window needs to be repainted
(configure/expose events), the contents of the xlib image surface are
copied onto the window.  But I need the window to be manually updated
whenever I have drawn something new on it (basically, I am drawing
from the REPL).

I have tried the following: I save the widget created by GTK2 as a
slot in a class (cairo-drawing-area), and whenever the surface is
drawn on, this method is called automatically:

(defmethod sync ((object gtk2-xlib-context))
           (gtk:within-main-loop
             (with-slots (sync-counter cairo-drawing-area) object
               (when (zerop sync-counter)
                 (repaint-drawing-area cairo-drawing-area)))))

The function inside is

(defun repaint-drawing-area (widget)
  (cl-gtk2-cairo:with-gdk-context (target-context (gtk:widget-window widget))
    (set-source-surface (source-surface widget) 0 0 target-context)
    (paint target-context)))

When called by GTK2, it works:

(defmethod initialize-instance :after ((w cairo-drawing-area) &rest initargs)
           (declare (ignore initargs))
           (gobject:connect-signal w "configure-event"
                                   (lambda (widget event)
                                     (declare (ignore event))
                                     (repaint-drawing-area widget)))
           (gobject:connect-signal w "expose-event"
                                   (lambda (widget event)
                                     (declare (ignore event))
                                     (repaint-drawing-area widget))))

But when I call sync, sometimes I get "unmapped memory area" errors
for GObject callbacks.  The whole code is available here:
http://github.com/tpapp/cl-cairo2/tree/master/src/gtk2/

Thanks,

Tamas




More information about the cl-gtk2-devel mailing list