"motion-notify-event"



Hi All,

I am not able to capture the mouse motion event on my window. I have written the following piece of code:

#include <gtk/gtk.h>
#include <stdio.h>

static gboolean motion_event_callback(GtkWidget *widget,GdkEvent *event,gpointer data)
{
    printf("Motion Event called ");
    return FALSE;
}

int main(int argc, char* argv[])
{
    gtk_init(&argc,&argv);
   
    GtkWidget *window;
    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_widget_set_size_request(window,100,100);
    gtk_widget_add_events(window,GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK);
    g_signal_connect(G_OBJECT(window),"motion_notify_event",G_CALLBACK(motion_event_callback),NULL);

    gtk_widget_show_all(window);

    gtk_main();
    return 0;
}

However I am not getting any output. When I tried writing the output to the file (assuming buffering optimization of printf), the output was not what it should have been.
I am not able to understand what I am missing to capture the mouse motion event.

A few more questions on GtkEvent:

There are 2 ways I can get data of mouse position: event->button.x or event->motion.x. Out of these two, which one should be used to capture the location of the  mouse pointer relative to the window.
Some examples use the following piece of code too:
if(event->is_hint)
     gdk_window_get_pointer(window,&x.&y,&state);


Thanks,
Mohit


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