from
http://developer.gnome.org/gtk/2.24/GtkWidget.html#GtkWidget-motion-notify-event:
Quote:
To receive this signal, the GdkWindow associated to the widget needs to enable the GDK_POINTER_MOTION_MASK mask.
Have you done this?
I have done this in gtk2 (but don't know about mingw) so have some example code
https://github.com/pchilds/GtkPlot. Mine is for a custom widget so its a bit more involved. I also convert the widget space coordinates to plot saced coordinates.
Here's some of the code (first from the class definition
https://github.com/pchilds/GtkPlot/blob/master/gtk2plot/gtkplotlinear.h):
Code:
...
struct _GtkPlotLinearClass
{
GtkDrawingAreaClass parent_class;
void (*moved) (GtkPlotLinear *plot);
};
then the code for the custom widget (
https://github.com/pchilds/GtkPlot/blob/master/gtk2plot/gtkplotlinear.c)
Code:
G_DEFINE_TYPE (GtkPlotLinear, gtk_plot_linear, GTK_TYPE_DRAWING_AREA);
enum {MOVED, LAST_SIGNAL};
static guint gtk_plot_linear_signals[LAST_SIGNAL]={0};
...
static gboolean gtk_plot_linear_motion_notify(GtkWidget *widget, GdkEventMotion *event)
{
GtkPlotLinearPrivate *priv;
GtkPlotLinear *plot;
gdouble dx, dy;
priv=GTK_PLOT_LINEAR_GET_PRIVATE(widget);
plot=GTK_PLOT_LINEAR(widget);
dx=((event->x)-(priv->range.xj))/((priv->range.xn)-(priv->range.xj));
dy=((priv->range.yn)-(event->y))/((priv->range.yn)-(priv->range.yj));
if ((dx>=0)&&(dy>=0)&&(dx<=1)&&(dy<=1))
{
(plot->xps)=((priv->bounds.xmax)*dx)+((priv->bounds.xmin)*(1-dx));
(plot->yps)=((priv->bounds.ymax)*dy)+((priv->bounds.ymin)*(1-dy));
g_signal_emit(plot, gtk_plot_linear_signals[MOVED], 0);
}
return FALSE;
}
static void gtk_plot_linear_class_init(GtkPlotLinearClass *klass)
{
GObjectClass *obj_klass;
GtkWidgetClass *widget_klass;
obj_klass=G_OBJECT_CLASS(klass);
...
widget_klass=GTK_WIDGET_CLASS(klass);
(widget_klass->motion_notify_event)=gtk_plot_linear_motion_notify;
gtk_plot_linear_signals[MOVED]=g_signal_new("moved", G_OBJECT_CLASS_TYPE(obj_klass), G_SIGNAL_RUN_FIRST, G_STRUCT_OFFSET (GtkPlotLinearClass, moved), NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
}
static void gtk_plot_linear_init(GtkPlotLinear *plot)
{
...
gtk_widget_add_events(GTK_WIDGET(plot), GDK_BUTTON_PRESS_MASK|GDK_POINTER_MOTION_MASK|GDK_BUTTON_RELEASE_MASK);
...
}
and finally its implementation (
https://github.com/pchilds/GtkPlot/blob/master/gtk2plot/testplotlinear.c):
Code:
...
void pltmv(GtkPlotLinear *plt, gpointer data)
{
gchar *str;
str=g_strdup_printf("x: %f, y: %f", plt->xps, plt->yps);
gtk_statusbar_push(GTK_STATUSBAR(statusbar), gtk_statusbar_get_context_id(GTK_STATUSBAR(statusbar), str), str);
g_free(str);
}
int main(int argc, char *argv[])
{
GtkPlotLinear *plt;
...
plot=gtk_plot_linear_new();
g_signal_connect(plot, "moved", G_CALLBACK(pltmv), NULL);
}
As you can see apart from the custom widget stuff, its pretty much doing the same things as your code only for the gtk_widget_add_events line. Btw I use the same code here for both gtk2 and 3.