GNOME Bugzilla – Bug 85229
rewrite_events_translate caculates (x,y) in a wrong way
Last modified: 2004-12-22 21:47:04 UTC
This is the rewrite_event_translate in gtkmain.c: rewrite_events_translate (GdkWindow *old_window, GdkWindow *new_window, gdouble *x, gdouble *y) { gint old_origin_x, old_origin_y; gint new_origin_x, new_origin_y; gdk_window_get_origin (old_window, &old_origin_x, &old_origin_y); gdk_window_get_origin (new_window, &new_origin_x, &new_origin_y); *x += new_origin_x - old_origin_x; *y += new_origin_y - old_origin_y; } As I understand, this will translate the (x,y) relative to old window to (x,y) relative to new window. Firstly, we can caculate the (x,y) relative to the origin point by: *x += old_origin_x; *y += old_origin_y; Then, we can caculate the (x,y) relative to the new window by: *x -= new_origin_x; *y -= new_origin_y; So, we should have: *x -= new_origin_x - old_origin_x; *y -= new_origin_y - old_origin_y; You can reproduce the error by: 1. create two GtkWindow (window A and B)in the same application and add them to diffrent GtkWindowGroups. 2. gdk_pointer_grab one of the GtkWindow (window A), with owner_even=TRUE and mask=GDK_POINTER_MOTION_MASK. 3. print out the event->x and event->y or log them to a file when the motion_notify_event is triggered. 4. run the application. move mouse pointer to window B (which is not grabed and is not in the same group as A). result we expect: the value of event->x and event->y which are relative to window A is right. in fact we got: wrong (x,y).
Created attachment 9217 [details] [review] patch
Erwann, when are porting mozilla to gtk2, we found a mozilla bug http://bugzilla.mozilla.org/show_bug.cgi?id=140867 is probably casued by this bug. or perhaps this bug is invalid? can you help to take a look at this bug? thanks. and I will add you to the cclist of that mozilla bug. Jay
Fixed in CVS, will be in 2.0.4. Fri Jun 14 10:00:29 2002 Owen Taylor <otaylor@redhat.com> * gtk/gtkmain.c (rewrite_events_translate): Fix sign problem with coordinate translation. (Fix from Robin Lu, #85229)