wacom: Drop old_axes from calibration API

The calibration utility was modified in cf408c27b0 to return unitless
padding measurements instead of axis values for storage in gsettings.
Unfortunately, the code still assumes in some places that it is working
with axes rather than paddings. This causes subtle math errors that
result in undesired cursor offsets after the calibration is applied.

Fortunately, this can be simplified, since tablet area is always reset
to the default state before starting calibration, we are sure that the
value will remain constant. Since both axes are in the same 0..1 scale,
calibration code doesn't need to swap X/Y back and forth to calculate
each axis scale.

Additionally, the code to get the calibrated axis values has been moved
into its own function along with a new function that returns padding
values suitable for consumption by g-c-c. All calculations are performed
internally in the 0..1 range.

https://bugzilla.gnome.org/show_bug.cgi?id=784009

Co-Authored-By: Carlos Garnacho <carlosg@gnome.org>
This commit is contained in:
Jason Gerecke 2017-06-20 12:09:39 -07:00 committed by Carlos Garnacho
parent 84d527645b
commit 50b39dc570
6 changed files with 61 additions and 65 deletions

View file

@ -669,7 +669,6 @@ calib_area_new (GdkScreen *screen,
GdkDevice *device, GdkDevice *device,
FinishCallback callback, FinishCallback callback,
gpointer user_data, gpointer user_data,
XYinfo *old_axis,
int threshold_doubleclick, int threshold_doubleclick,
int threshold_misclick) int threshold_misclick)
{ {
@ -683,23 +682,12 @@ calib_area_new (GdkScreen *screen,
GtkWidget *clutter_embed; GtkWidget *clutter_embed;
ClutterActor *stage; ClutterActor *stage;
g_return_val_if_fail (old_axis, NULL);
g_return_val_if_fail (callback, NULL); g_return_val_if_fail (callback, NULL);
g_debug ("Current calibration: %f, %f, %f, %f\n",
old_axis->x_min,
old_axis->y_min,
old_axis->x_max,
old_axis->y_max);
calib_area = g_new0 (CalibArea, 1); calib_area = g_new0 (CalibArea, 1);
calib_area->callback = callback; calib_area->callback = callback;
calib_area->user_data = user_data; calib_area->user_data = user_data;
calib_area->device = device; calib_area->device = device;
calib_area->calibrator.old_axis.x_min = old_axis->x_min;
calib_area->calibrator.old_axis.x_max = old_axis->x_max;
calib_area->calibrator.old_axis.y_min = old_axis->y_min;
calib_area->calibrator.old_axis.y_max = old_axis->y_max;
calib_area->calibrator.threshold_doubleclick = threshold_doubleclick; calib_area->calibrator.threshold_doubleclick = threshold_doubleclick;
calib_area->calibrator.threshold_misclick = threshold_misclick; calib_area->calibrator.threshold_misclick = threshold_misclick;
@ -769,21 +757,16 @@ calib_area_new (GdkScreen *screen,
/* Finishes the calibration. Note that CalibArea /* Finishes the calibration. Note that CalibArea
* needs to be destroyed with calib_area_free() afterwards */ * needs to be destroyed with calib_area_free() afterwards */
gboolean gboolean
calib_area_finish (CalibArea *area, calib_area_finish (CalibArea *area)
XYinfo *new_axis,
gboolean *swap_xy)
{ {
g_return_val_if_fail (area != NULL, FALSE); g_return_val_if_fail (area != NULL, FALSE);
*new_axis = area->axis;
*swap_xy = area->swap;
if (area->success) if (area->success)
g_debug ("Final calibration: %f, %f, %f, %f\n", g_debug ("Final calibration: %f, %f, %f, %f\n",
new_axis->x_min, area->axis.x_min,
new_axis->y_min, area->axis.y_min,
new_axis->x_max, area->axis.x_max,
new_axis->y_max); area->axis.y_max);
else else
g_debug ("Calibration was aborted or timed out"); g_debug ("Calibration was aborted or timed out");
@ -811,3 +794,30 @@ calib_area_get_display_size (CalibArea *area, gint *width, gint *height)
*width = area->display_width; *width = area->display_width;
*height = area->display_height; *height = area->display_height;
} }
void
calib_area_get_axis (CalibArea *area,
XYinfo *new_axis,
gboolean *swap_xy)
{
g_return_if_fail (area != NULL);
*new_axis = area->axis;
*swap_xy = area->swap;
}
void
calib_area_get_padding (CalibArea *area,
XYinfo *padding)
{
g_return_if_fail (area != NULL);
/* min/max values are monitor coordinates scaled to be between
* 0 and 1, padding starts at 0 on "the edge", and positive
* values grow towards the center of the rectangle.
*/
padding->x_min = area->axis.x_min;
padding->y_min = area->axis.y_min;
padding->x_max = 1 - area->axis.x_max;
padding->y_max = 1 - area->axis.y_max;
}

View file

@ -43,13 +43,10 @@ CalibArea * calib_area_new (GdkScreen *screen,
GdkDevice *device, GdkDevice *device,
FinishCallback callback, FinishCallback callback,
gpointer user_data, gpointer user_data,
XYinfo *old_axis,
int threshold_doubleclick, int threshold_doubleclick,
int threshold_misclick); int threshold_misclick);
gboolean calib_area_finish (CalibArea *area, gboolean calib_area_finish (CalibArea *area);
XYinfo *new_axis,
gboolean *swap_xy);
void calib_area_free (CalibArea *area); void calib_area_free (CalibArea *area);
@ -57,4 +54,10 @@ void calib_area_get_display_size (CalibArea *area,
gint *width, gint *width,
gint *height); gint *height);
void calib_area_get_axis (CalibArea *area,
XYinfo *new_axis,
gboolean *swap_xy);
void calib_area_get_padding (CalibArea *area,
XYinfo *padding);
#endif /* __CALIBRATOR_GUI_H__ */ #endif /* __CALIBRATOR_GUI_H__ */

View file

@ -143,38 +143,30 @@ finish (struct Calib *c,
/* Should x and y be swapped? If the device and output are wider /* Should x and y be swapped? If the device and output are wider
* towards different axes, swapping must be performed * towards different axes, swapping must be performed
*
* FIXME: Would be even better to know the actual output orientation,
* not just the direction.
*/ */
swap_xy = (c->geometry.width > c->geometry.height) != swap_xy = (c->geometry.width < c->geometry.height);
((c->old_axis.x_max - c->old_axis.x_min) > (c->old_axis.y_max - c->old_axis.y_min));
if (swap_xy) /* Compute the scale to transform from pixel positions to [0..1]. */
SWAP (int, c->geometry.width, c->geometry.height); scale_x = 1 / (float)c->geometry.width;
scale_y = 1 / (float)c->geometry.height;
/* Compute min/max coordinates. */ axis.x_min = ((((c->clicked_x[UL] + c->clicked_x[LL]) / 2)) * scale_x);
/* These are scaled using the values of old_axis */ axis.x_max = ((((c->clicked_x[UR] + c->clicked_x[LR]) / 2)) * scale_x);
scale_x = (1 - c->old_axis.x_max - c->old_axis.x_min)/(float)c->geometry.width; axis.y_min = ((((c->clicked_y[UL] + c->clicked_y[UR]) / 2)) * scale_y);
scale_y = (1 - c->old_axis.y_max - c->old_axis.y_min)/(float)c->geometry.height; axis.y_max = ((((c->clicked_y[LL] + c->clicked_y[LR]) / 2)) * scale_y);
/* Swap back for usage with the collected click points, which are in screen
* coordinates, hence possibly rotated.
*/
if (swap_xy)
SWAP(gdouble, scale_x, scale_y);
axis.x_min = ((((c->clicked_x[UL] + c->clicked_x[LL]) / 2)) * scale_x) + c->old_axis.x_min;
axis.x_max = 1 - ((((c->clicked_x[UR] + c->clicked_x[LR]) / 2)) * scale_x) + c->old_axis.x_min;
axis.y_min = ((((c->clicked_y[UL] + c->clicked_y[UR]) / 2)) * scale_y) + c->old_axis.y_min;
axis.y_max = 1 - ((((c->clicked_y[LL] + c->clicked_y[LR]) / 2)) * scale_y) + c->old_axis.y_min;
/* Add/subtract the offset that comes from not having the points in the /* Add/subtract the offset that comes from not having the points in the
* corners (using the same coordinate system they are currently in) * corners (using the same coordinate system they are currently in)
*/ */
delta_x = (1 - axis.x_max - axis.x_min) / (float)(NUM_BLOCKS - 2); delta_x = (axis.x_max - axis.x_min) / (float)(NUM_BLOCKS - 2);
axis.x_min -= delta_x; axis.x_min -= delta_x;
axis.x_max -= delta_x; axis.x_max += delta_x;
delta_y = (1 - axis.y_max - axis.y_min) / (float)(NUM_BLOCKS - 2); delta_y = (axis.y_max - axis.y_min) / (float)(NUM_BLOCKS - 2);
axis.y_min -= delta_y; axis.y_min -= delta_y;
axis.y_max -= delta_y; axis.y_max += delta_y;
/* If x and y has to be swapped we also have to swap the parameters */ /* If x and y has to be swapped we also have to swap the parameters */
if (swap_xy) if (swap_xy)

View file

@ -66,9 +66,6 @@ enum
struct Calib struct Calib
{ {
/* original axis values */
XYinfo old_axis;
/* Geometry of the calibration window */ /* Geometry of the calibration window */
GdkRectangle geometry; GdkRectangle geometry;

View file

@ -173,13 +173,12 @@ static void usage(char* cmd, unsigned thr_misclick)
static struct Calib* CalibratorXorgPrint(const char* const device_name0, const XYinfo *axis0, const gboolean verbose0, const int thr_misclick, const int thr_doubleclick) static struct Calib* CalibratorXorgPrint(const char* const device_name0, const XYinfo *axis0, const gboolean verbose0, const int thr_misclick, const int thr_doubleclick)
{ {
struct Calib* c = (struct Calib*)calloc(1, sizeof(struct Calib)); struct Calib* c = (struct Calib*)calloc(1, sizeof(struct Calib));
c->old_axis = *axis0;
c->threshold_misclick = thr_misclick; c->threshold_misclick = thr_misclick;
c->threshold_doubleclick = thr_doubleclick; c->threshold_doubleclick = thr_doubleclick;
printf("Calibrating standard Xorg driver \"%s\"\n", device_name0); printf("Calibrating standard Xorg driver \"%s\"\n", device_name0);
printf("\tcurrent calibration values: min_x=%lf, max_x=%lf and min_y=%lf, max_y=%lf\n", printf("\tcurrent calibration values: min_x=%lf, max_x=%lf and min_y=%lf, max_y=%lf\n",
c->old_axis.x_min, c->old_axis.x_max, c->old_axis.y_min, c->old_axis.y_max); axis0->x_min, axis0->x_max, axis0->y_min, axis0->y_max);
printf("\tIf these values are estimated wrong, either supply it manually with the --precalib option, or run the 'get_precalib.sh' script to automatically get it (through HAL).\n"); printf("\tIf these values are estimated wrong, either supply it manually with the --precalib option, or run the 'get_precalib.sh' script to automatically get it (through HAL).\n");
return c; return c;
@ -376,9 +375,12 @@ calibration_finished_cb (CalibArea *area,
XYinfo axis; XYinfo axis;
gboolean swap_xy; gboolean swap_xy;
success = calib_area_finish (area, &axis, &swap_xy); success = calib_area_finish (area);
if (success) if (success)
{
calib_area_get_axis (area, &axis, &swap_xy);
success = finish_data (axis, swap_xy); success = finish_data (axis, swap_xy);
}
else else
fprintf(stderr, "Error: unable to apply or save configuration values\n"); fprintf(stderr, "Error: unable to apply or save configuration values\n");
@ -409,7 +411,6 @@ int main(int argc, char** argv)
NULL, /* NULL to accept input from any device */ NULL, /* NULL to accept input from any device */
calibration_finished_cb, calibration_finished_cb,
NULL, NULL,
&calibrator->old_axis,
calibrator->threshold_doubleclick, calibrator->threshold_doubleclick,
calibrator->threshold_misclick); calibrator->threshold_misclick);

View file

@ -181,11 +181,11 @@ finish_calibration (CalibArea *area,
CcWacomPage *page = (CcWacomPage *) user_data; CcWacomPage *page = (CcWacomPage *) user_data;
CcWacomPagePrivate *priv = page->priv; CcWacomPagePrivate *priv = page->priv;
XYinfo axis; XYinfo axis;
gboolean swap_xy;
gdouble cal[4]; gdouble cal[4];
gint display_width, display_height; gint display_width, display_height;
if (calib_area_finish (area, &axis, &swap_xy)) { if (calib_area_finish (area)) {
calib_area_get_padding (area, &axis);
cal[0] = axis.x_min; cal[0] = axis.x_min;
cal[1] = axis.y_min; cal[1] = axis.y_min;
cal[2] = axis.x_max; cal[2] = axis.x_max;
@ -259,16 +259,10 @@ run_calibration (CcWacomPage *page,
gdouble *cal, gdouble *cal,
gint monitor) gint monitor)
{ {
XYinfo old_axis;
CcWacomPagePrivate *priv; CcWacomPagePrivate *priv;
g_assert (page->priv->area == NULL); g_assert (page->priv->area == NULL);
old_axis.x_min = cal[0];
old_axis.y_min = cal[1];
old_axis.x_max = cal[2];
old_axis.y_max = cal[3];
priv = page->priv; priv = page->priv;
priv->area = calib_area_new (NULL, priv->area = calib_area_new (NULL,
@ -276,7 +270,6 @@ run_calibration (CcWacomPage *page,
cc_wacom_page_get_gdk_device (page), cc_wacom_page_get_gdk_device (page),
finish_calibration, finish_calibration,
page, page,
&old_axis,
THRESHOLD_MISCLICK, THRESHOLD_MISCLICK,
THRESHOLD_DOUBLECLICK); THRESHOLD_DOUBLECLICK);