gdk_window_add_filter not working as expected



Hello all,

Using gtk-2.2 on Fedora 14 and X11.

I have been trying to find out how to keep track of the mouse pointer location anywhere on the screen, so that whenever and whereever the mouse moves, my function will be called. All the other posts I have found through google tell me how I can get the mouse position at a single time point, but not how to have a event driven function into the GTK event loop to successfully capture the mouse co-ordinates (those that do, do not work as far as I can tell).

This is what I have so far:

// Event Handler for GDK events
extern "C" GdkFilterReturn
desktopMouseMotionHandler( GdkXEvent* xevent, GdkEvent *event, gpointer data ) {
        // event->type is always GDK_NOTHING (-1)
// xevent->type is mostly 28 which is only ever actived moving in and out of windows, a POINTER_MOTION_MASK is never passed through, nor for that matter any button or keyboard calls when using GTK_ALL_EVENTS_MASK
        XEvent* xe = (XEvent*) xevent;
cout << "desktop event handler (Event: " << xe->type << " gtk:" << event->type << ")" << endl;
}

...later on in the code...

GdkWindow *root_window;
root_window = gdk_get_default_root_window ();   // desktop window
gdk_window_set_events( root_window, (GdkEventMask) (GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK ) ); // tried GTK_ALL_EVENTS_MASK as well but still did not get any pointer motion or keyboard or button events through gdk_window_add_filter( root_window, desktopMouseMotionHandler, NULL ); // supposedly will pass all pointer motion events through to my function above

Using this method I can only capture GDK_PROPERTY_CHANGE_MASK events, not the ones I actually want. Everything else does not appear to be passed through to the filter function. When using this mask GTK_ALL_EVENTS_MASK with GdkEvent *event the type is always GTK_NOTHING (-1), which is useless.

There is a really old post http://www.digipedia.pl/usenet/thread/12440/768/ with a similar problem but no solution. There is a bug report as well on this for pygtk but again, this does not really deal with the fact that not all events are passed through to the filter.

I have tried looking at Xlib calls, but I would have to have a separate thread polling XQueryPointer and XNextEvent which seems inefficient when this polling and filtering already happens in the main GTK loop.

If there is a bug which has never got fixed, does anyone know what the workaround was?

I do not believe I can be the only person who has ever required to do this, so it must be possible -- can anyone suggest how to do this?

Many thanks for your help.

Tom



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