[cl-gtk2-devel] gtk_widget_add_events

Peter Keller psilord at cs.wisc.edu
Thu Jul 14 06:45:57 UTC 2011


On Thu, Jul 14, 2011 at 10:34:00AM +0400, Valeriy Fedotov wrote:
> Hello, Peter,
> 
> you can add events like this:
> 
> (pushnew :button-press-mask (gdk-window-events (widget-window widget)))
> 
> CONNECT-SIGNAL is indeed GOBJECT:CONNECT-SIGNAL.
> 
> Also, indeed I get the same warnings, but everything seems to work
> fine, including ARRAY-LIST-STORE mentioned in the warnings.

Thank you for your response, but I have some questions:

The C code I wish to emulate is:

    gtk_widget_add_events(drawing_area,
        GDK_POINTER_MOTION_MASK |
        GDK_BUTTON_PRESS_MASK |
        GDK_BUTTON_RELEASE_MASK |
		GDK_KEY_PRESS_MASK |
		GDK_KEY_RELEASE_MASK |
        GDK_SCROLL_MASK);

I want to initially associate a signal "key-press-event" with the drawing
area to handle that events.  However, your code seems to be getting
the window the widget is a part of and then adjusting the masks for
that instead. To me this would seem that the wrong widget is getting
the events.

Here is my lisp code. I'm sorry that this is a bit strange. I'm still learning
the cl-gtk2 API... When I run this code, (gtk:widget-window da) returns (NIL)
and gdk-window-events doesn't know what to do with that.

(defun doit ()
  (let (top-level)
    (gtk:within-main-loop
      (let ((builder (make-instance 'gtk:builder))
            (opengl-context (create-opengl-context)))

        (gtk:builder-add-from-file builder "./test-1.glade")

        (setf top-level (gtk:builder-get-object builder "top_level"))
        (format t "Created toplevel ~A~%" top-level)

        (let ((da (make-instance 'gtkglext:gl-drawing-area
                                 :on-expose #'draw
                                 ;; XXX Figure out how to do this!
                                 :xxx-width-request 320
                                 :xxx-height-request 240)))

          (gtkglext:gtk-widget-set-gl-capability da opengl-context
                                                 nil t :rgba-type)

          (gtk:box-pack-end (gtk:builder-get-object builder "hbox1") da)

	      ;; XXX How do I set the event mask for the drawing area?

	      (pushnew :key-press-mask
		           (gdk:gdk-window-events (gtk:widget-window da)))
	  
          (gobject:connect-signal da "key-press-event" #'da-key-press-event)

          ;; 60 fps
          (setf *timeout*
                (gtk:gtk-main-add-timeout
                 16
                 #'(lambda ()
                     (idle-func da))))

          (gtk:builder-connect-signals-simple
           builder `(("quit_button_clicked" ,#'quit-button-clicked)
                     ("white_button_clicked" ,#'white-button-clicked)
                     ("red_button_clicked" ,#'red-button-clicked)
                     ("green_button_clicked" ,#'green-button-clicked)
                     ("blue_button_clicked" ,#'blue-button-clicked)))

          (gtk:widget-show top-level :all t))))

    (gtk:join-gtk-main)

    (gtk:within-main-loop
      (gtk:object-destroy top-level))))

Thank you for your help.

-pete




More information about the cl-gtk2-devel mailing list