Re: Motion Notify Event



Hi,

Here's what I do:

In your widget creation code, "turn on" the events you want to see for the widget:

gtk_widget_set_events (widget, gtk_widget_get_events (widget)
                                              | GDK_BUTTON_PRESS_MASK
                                              | GDK_BUTTON_RELEASE_MASK
                                              | GDK_POINTER_MOTION_MASK
                                              | GDK_POINTER_MOTION_HINT_MASK
                                              | GDK_BUTTON_RELEASE_MASK);

And connect the signal to your drag event:

g_signal_connect (widget, "motion_notify_event",
                                                     G_CALLBACK (M_N_callback), (gpointer) data);


You didn't provide your complete code so it's a bit difficult to tell exactly what's going on, but:
  1. you should call gtk_widget_set_events() before the widget is realized, setting all events you wish to be enabled for the widget in question;
  2. n.b.: take note of the gtk_widget_get_events() call - default events that automatically come with the widget are, thus, not lost;
  3. unless you need to add events after a widget has been realized, use of gtk_widget_add_events() is unnecessary.
One other very important note.  In your callback, the absolute last executing piece of code before returning to the main loop should/must be:

gdk_window_get_pointer(gdkWindow, &x, &y, &state);

Even though you don't use the resulting values, this call tells the main loop (managing the motion events) that the callback is done with its work and is ready to be called again by the main loop. 

This is essentially the synchronization hook used to connect back to the HINT motion type event; as long as your callback has been called and gdk_window_get_pointer() hasn't been called, your callback won't get called again.  OR - From the mainloop perspective: once your callback has been called, all succeeding user motion events are "eaten up" and not passed on until gdk_window_get_pointer() has been called.

cheers,

richard

On 7/5/07, Dean McCullough <dpmccul comcast net> wrote:
I am trying to write a tool that uses mouse button presses and motion to
do something useful.  The mouse press is working, but I never get into
the routine from a mouse motion event any action appears to be captured
by the button press event).  The add event and signal connect calls I am
using are below.  Is there an obvious error?  (I saw a recommendation to
use  GDK_POINTER_MOTION_HINT_MASK rather than GDK_POINTER_MOTION_MASK to
keep the application from bogging down.

-------------------------------------------------------------------------

   gtk_widget_add_events(GTK_WIDGET(view),
                         GDK_POINTER_MOTION_HINT_MASK);

   gtk_widget_add_events(GTK_WIDGET(view),
                         GDK_BUTTON_PRESS_MASK);

   gtk_signal_connect(GTK_OBJECT(view), "motion_notify_event",
                   GTK_SIGNAL_FUNC(event_mv), NULL);

   gtk_signal_connect(GTK_OBJECT(view), "button_press_event",
                      GTK_SIGNAL_FUNC(event_cb), NULL);

--
-----------------
Dean P McCullough

_______________________________________________
gtk-list mailing list
gtk-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-list



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