Gdk sometimes gives wrong coordinates with X events
Submitted by Éric Brunet
Link to original bug (#735003)
Description
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.
Version: 2.24.x