Does gdk_window_get_pointer() work?

Hi,

There's a gdk_window_get_pointer() call in my program to sense shift and ctrl key status when the mouse generates a motion-notify-event. This program works well on MacOS+X11, Linux, FreeBSD and Windows. However, all modifier key state is always same with GTK+-Quartz so I can't detect anything.

Does anybody have same problem, or workaround?

Thanks.

It works for me, but maybe

It works for me, but maybe you could provide a minimal test case that reproduces the issue for you so I can test it? Also what version of gtk are you using?

I've tested the code below

I've tested the code below with MacOS X 10.5.6 (Intel), with GTK+-2.14.7 (for both Quartz and X11, built by myself) and the latest GTK Framework. It works fine with X11, but it didn't with Quartz (both my hand-built GTK and the framework from gtk-osx.org).

Do I need gtk_widget_add_events() or something to use gdk_window_get_pointer()??

Thank you.

Yasunori

--------------
// I'm sorry that the format isn't good because blockcode tag didn't work
#include

void destroy(GtkWidget *widget, gpointer data)
{
gtk_main_quit();
}

gboolean motion_handler(GtkWidget* w, GdkEventMotion *ev, gpointer data){
GdkModifierType gm;
gdk_window_get_pointer(gtk_widget_get_parent_window(w), NULL, NULL, &gm);

printf("%l3.0f, %l3.0f shift=%d\n", ev->x, ev->y, gm & GDK_SHIFT_MASK);
}

int main( int argc,
char *argv[] )
{
GtkWidget *window;
GtkWidget *eventbox;
GtkWidget *label;

gtk_init(&argc, &argv);
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(destroy), NULL);

label = gtk_label_new("Debug!\nDebug!");
eventbox = gtk_event_box_new();
gtk_container_add(GTK_CONTAINER(eventbox), label);
gtk_container_add(GTK_CONTAINER(window), eventbox);

gtk_widget_add_events(eventbox, GDK_POINTER_MOTION_MASK);
g_signal_connect (G_OBJECT(eventbox), "motion-notify-event",
G_CALLBACK(motion_handler), NULL);

gtk_widget_show_all(window);
gtk_main();

return 0;
}

Ah, you're right, I was

Ah, you're right, I was thinking of the state value in events. The reason this is broken is that we overwrite the "current state" in all events, and the right information is not always available. I will try to fix this soon.

In the meantime, you should be able to use the information from the event instead (event->state or something like that).

OK, I'll try to use event

OK, I'll try to use event info. Thank you!
Also I hope to hear you soon about gdk_window_get_pointer() :)

Yasunori

I've got it by checking

I've got it by checking (GdkEventMotion->state & GDK_*_MASK) in motion notification event handler.
Thank you very much!

Yasunori