[gnome-control-center/gnome-3-24] wacom: Drop old_axes from calibration API



commit be835b321a2657721eedfe0c6b34c3e462a93476
Author: Jason Gerecke <killertofu gmail com>
Date:   Tue Jun 20 12:09:39 2017 -0700

    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>

 panels/wacom/calibrator/calibrator-gui.c |   54 +++++++++++++++++------------
 panels/wacom/calibrator/calibrator-gui.h |   11 ++++--
 panels/wacom/calibrator/calibrator.c     |   38 ++++++++-------------
 panels/wacom/calibrator/calibrator.h     |    3 --
 panels/wacom/calibrator/main.c           |    9 +++--
 panels/wacom/cc-wacom-page.c             |   11 +-----
 6 files changed, 61 insertions(+), 65 deletions(-)
---
diff --git a/panels/wacom/calibrator/calibrator-gui.c b/panels/wacom/calibrator/calibrator-gui.c
index c4e145e..ed4a8ec 100644
--- a/panels/wacom/calibrator/calibrator-gui.c
+++ b/panels/wacom/calibrator/calibrator-gui.c
@@ -669,7 +669,6 @@ calib_area_new (GdkScreen      *screen,
                 GdkDevice      *device,
                 FinishCallback  callback,
                 gpointer        user_data,
-                XYinfo         *old_axis,
                 int             threshold_doubleclick,
                 int             threshold_misclick)
 {
@@ -683,23 +682,12 @@ calib_area_new (GdkScreen      *screen,
   GtkWidget *clutter_embed;
   ClutterActor *stage;
 
-  g_return_val_if_fail (old_axis, 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->callback = callback;
   calib_area->user_data = user_data;
   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_misclick = threshold_misclick;
 
@@ -769,21 +757,16 @@ calib_area_new (GdkScreen      *screen,
 /* Finishes the calibration. Note that CalibArea
  * needs to be destroyed with calib_area_free() afterwards */
 gboolean
-calib_area_finish (CalibArea *area,
-                   XYinfo    *new_axis,
-                   gboolean  *swap_xy)
+calib_area_finish (CalibArea *area)
 {
   g_return_val_if_fail (area != NULL, FALSE);
 
-  *new_axis = area->axis;
-  *swap_xy  = area->swap;
-
   if (area->success)
     g_debug ("Final calibration: %f, %f, %f, %f\n",
-             new_axis->x_min,
-             new_axis->y_min,
-             new_axis->x_max,
-             new_axis->y_max);
+             area->axis.x_min,
+             area->axis.y_min,
+             area->axis.x_max,
+             area->axis.y_max);
   else
     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;
   *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;
+}
diff --git a/panels/wacom/calibrator/calibrator-gui.h b/panels/wacom/calibrator/calibrator-gui.h
index 787a5b0..bf3e84a 100644
--- a/panels/wacom/calibrator/calibrator-gui.h
+++ b/panels/wacom/calibrator/calibrator-gui.h
@@ -43,13 +43,10 @@ CalibArea * calib_area_new (GdkScreen      *screen,
                            GdkDevice      *device,
                            FinishCallback  callback,
                            gpointer        user_data,
-                           XYinfo         *old_axis,
                            int             threshold_doubleclick,
                            int             threshold_misclick);
 
-gboolean calib_area_finish (CalibArea *area,
-                           XYinfo    *new_axis,
-                           gboolean  *swap_xy);
+gboolean calib_area_finish (CalibArea *area);
 
 void calib_area_free (CalibArea *area);
 
@@ -57,4 +54,10 @@ void calib_area_get_display_size (CalibArea *area,
                                  gint      *width,
                                  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__ */
diff --git a/panels/wacom/calibrator/calibrator.c b/panels/wacom/calibrator/calibrator.c
index 71adcf6..4ac316e 100644
--- a/panels/wacom/calibrator/calibrator.c
+++ b/panels/wacom/calibrator/calibrator.c
@@ -143,38 +143,30 @@ finish (struct Calib *c,
 
     /* Should x and y be swapped? If the device and output are wider
      * 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) !=
-        ((c->old_axis.x_max - c->old_axis.x_min) > (c->old_axis.y_max - c->old_axis.y_min));
+    swap_xy = (c->geometry.width < c->geometry.height);
 
-    if (swap_xy)
-        SWAP (int, c->geometry.width, c->geometry.height);
-
-    /* Compute min/max coordinates. */
-    /* These are scaled using the values of old_axis */
-    scale_x = (1 - c->old_axis.x_max - c->old_axis.x_min)/(float)c->geometry.width;
-    scale_y = (1 - c->old_axis.y_max - c->old_axis.y_min)/(float)c->geometry.height;
-
-    /* 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);
+    /* Compute the scale to transform from pixel positions to [0..1]. */
+    scale_x = 1 / (float)c->geometry.width;
+    scale_y = 1 / (float)c->geometry.height;
 
-    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;
+    axis.x_min = ((((c->clicked_x[UL] + c->clicked_x[LL]) / 2)) * scale_x);
+    axis.x_max = ((((c->clicked_x[UR] + c->clicked_x[LR]) / 2)) * scale_x);
+    axis.y_min = ((((c->clicked_y[UL] + c->clicked_y[UR]) / 2)) * scale_y);
+    axis.y_max = ((((c->clicked_y[LL] + c->clicked_y[LR]) / 2)) * scale_y);
 
     /* Add/subtract the offset that comes from not having the points in the
      * 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_max -= delta_x;
-    delta_y = (1 - axis.y_max - axis.y_min) / (float)(NUM_BLOCKS - 2);
+    axis.x_max += delta_x;
+    delta_y = (axis.y_max - axis.y_min) / (float)(NUM_BLOCKS - 2);
     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 (swap_xy)
diff --git a/panels/wacom/calibrator/calibrator.h b/panels/wacom/calibrator/calibrator.h
index 659232f..786fd61 100644
--- a/panels/wacom/calibrator/calibrator.h
+++ b/panels/wacom/calibrator/calibrator.h
@@ -66,9 +66,6 @@ enum
 
 struct Calib
 {
-    /* original axis values */
-    XYinfo old_axis;
-
     /* Geometry of the calibration window */
     GdkRectangle geometry;
 
diff --git a/panels/wacom/calibrator/main.c b/panels/wacom/calibrator/main.c
index 281ea1e..135a862 100644
--- a/panels/wacom/calibrator/main.c
+++ b/panels/wacom/calibrator/main.c
@@ -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)
 {
     struct Calib* c = (struct Calib*)calloc(1, sizeof(struct Calib));
-    c->old_axis = *axis0;
     c->threshold_misclick = thr_misclick;
     c->threshold_doubleclick = thr_doubleclick;
 
     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",
-                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");
 
     return c;
@@ -376,9 +375,12 @@ calibration_finished_cb (CalibArea *area,
        XYinfo axis;
        gboolean swap_xy;
 
-       success = calib_area_finish (area, &axis, &swap_xy);
+       success = calib_area_finish (area);
        if (success)
+       {
+               calib_area_get_axis (area, &axis, &swap_xy);
                success = finish_data (axis, swap_xy);
+       }
        else
                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 */
                                 calibration_finished_cb,
                                 NULL,
-                                &calibrator->old_axis,
                                 calibrator->threshold_doubleclick,
                                 calibrator->threshold_misclick);
 
diff --git a/panels/wacom/cc-wacom-page.c b/panels/wacom/cc-wacom-page.c
index e8c5ca9..13b0729 100644
--- a/panels/wacom/cc-wacom-page.c
+++ b/panels/wacom/cc-wacom-page.c
@@ -181,11 +181,11 @@ finish_calibration (CalibArea *area,
        CcWacomPage *page = (CcWacomPage *) user_data;
        CcWacomPagePrivate *priv = page->priv;
        XYinfo axis;
-       gboolean swap_xy;
        gdouble cal[4];
        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[1] = axis.y_min;
                cal[2] = axis.x_max;
@@ -259,16 +259,10 @@ run_calibration (CcWacomPage *page,
                 gdouble     *cal,
                 gint         monitor)
 {
-       XYinfo              old_axis;
        CcWacomPagePrivate *priv;
 
        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->area = calib_area_new (NULL,
@@ -276,7 +270,6 @@ run_calibration (CcWacomPage *page,
                                     cc_wacom_page_get_gdk_device (page),
                                     finish_calibration,
                                     page,
-                                    &old_axis,
                                     THRESHOLD_MISCLICK,
                                     THRESHOLD_DOUBLECLICK);
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]