GNOME Bugzilla – Bug 735003
Gdk sometimes gives wrong coordinates with X events
Last modified: 2018-05-02 16:13:27 UTC
In function _gdk_input_common_other_event of file gdk/x11/gdkinput-x11.c, X events are parsed and translated into gtk events. The X events (such as ButtonPress, MotionNotify, etc.) contains calibrated (x,y) coordinates computed by the X server, but also raw values of the valuators in the axis_data fields. To populate the (x,y) coordinates of the gtk event, gdk uses the raw valuators (in function gdk_input_translate_coordinates) rather than the (x,y) coordinates computed by the X server. (By way, I wonder why...) The function gdk_input_translate_coordinates dors not check that new values for all the valuators are available, and will use old data if no new value is available. The problem I have is that I have a pen for which X * only sends the changed valuators during motion * does not always sends valuators during ButtonPress (when the pen touches the screen) This gives many problems when drawing in gtk applications (I tried gimp, mypaint, xournal): for instance, if I select a tool and then hit the canvas, the canvas receives a ButtonPress event but with the coordinates of the point I touched when selecting the tool; indeed, no valuators are sent with the ButtonPress, so that the old values (the ones where I selected the tool) are used. This result in a weird line being drawn from the icon of the selected tool to the point I touched in the canvas. Just to make an experiment, I recompiled a gdk where after each call to gdk_input_translate_coordinates in _gdk_input_common_other_event I added something like event->button.axes[0] = event-> button.x = xdbe->x - ((GdkWindowObject *) window)->abs_x; (Idem for y. This is for buttonpress/release; replace button by motion and xdbe by xdme for the MotionNotify case). This modification helped a lot and made my pen usable in many gdk applications (I still have bugs, but they might be application bugs). To sum up: gdk should not assume that all X events come with a full set of valuators. Using the old value when a valuator is missing is not a good strategy for a pen (or a touch device) where the position can jump from a place to another. The simplest thing should be to use X (x,y) coordinates, but there might be some reason not to use them. At the very least, X coordinates should be used when the valuators are missing.
Yep, after more than 3 years this is a still a problem. Any feedback from the maintainers?
Let's Cc Carlo, given it's his area of expertise.
(In reply to Éric Brunet from comment #0) > In function _gdk_input_common_other_event of file gdk/x11/gdkinput-x11.c, > X events are parsed and translated into gtk events. The X events (such as > ButtonPress, MotionNotify, etc.) contains calibrated (x,y) coordinates > computed by the X server, but also raw values of the valuators in the > axis_data fields. > > To populate the (x,y) coordinates of the gtk event, gdk uses the raw > valuators > (in function gdk_input_translate_coordinates) rather than the (x,y) > coordinates computed by the X server. (By way, I wonder why...) IIRC this was for subpixel precision, because X11/XInput1 is stuck on ints for coordinates, and device axis ranges are quite larger than usual desktop resolutions. > The function > gdk_input_translate_coordinates dors not check that new values for all the > valuators are available, and will use old data if no new value is available. > > The problem I have is that I have a pen for which X > * only sends the changed valuators during motion > * does not always sends valuators during ButtonPress (when the pen > touches the screen) Ugh. > > This gives many problems when drawing in gtk applications (I tried gimp, > mypaint, xournal): for instance, if I select a tool and then hit the canvas, > the canvas receives a ButtonPress event but with the coordinates of the > point I touched when selecting the tool; indeed, no valuators are sent with > the ButtonPress, so that the old values (the ones where I selected the tool) > are used. This result in a weird line being drawn from the icon of the > selected tool to the point I touched in the canvas. > > Just to make an experiment, I recompiled a gdk where after each call to > gdk_input_translate_coordinates in _gdk_input_common_other_event I added > something like > event->button.axes[0] = event-> button.x = > xdbe->x - ((GdkWindowObject *) window)->abs_x; > (Idem for y. This is for buttonpress/release; replace button by motion and > xdbe by xdme for the MotionNotify case). > > This modification helped a lot and made my pen usable in many gdk > applications (I still have bugs, but they might be application bugs). > > To sum up: gdk should not assume that all X events come with a full set of > valuators. Using the old value when a valuator is missing is not a good > strategy for a pen (or a touch device) where the position can jump from a > place to another. The simplest thing should be to use X (x,y) coordinates, > but there might be some reason not to use them. At the very least, X > coordinates should be used when the valuators are missing. I agree to this last point for X/Y. The other axes still need to be looked up from old values so we can offer the full set of axes for each event. I'll come up with a patch if noone beats me to it.
-- GitLab Migration Automatic Message -- This bug has been migrated to GNOME's GitLab instance and has been closed from further activity. You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/gtk/issues/504.