[gnome-control-center/wip/garnacho/wayland-tablet: 25/31] wacom: Reinstaurate calibration



commit d8b7c3a4bec80dcd70e4a19a91a0fc5529732aa8
Author: Carlos Garnacho <carlosg gnome org>
Date:   Fri Jun 24 17:38:08 2016 +0200

    wacom: Reinstaurate calibration
    
    The "area" setting has a different treatment in the gsettings-desktop-schemas
    tablet schema, the 4 double values express the padding (in unitless 0..1
    range) on each of the sides of the tablet. It's been done so we don't rely
    on input/output units, which we might have not the luxury to access.
    
    Besides that, the dependency on GsdWacomDevice has been cleared.

 panels/wacom/calibrator/calibrator-gui.c |   10 +---
 panels/wacom/calibrator/calibrator-gui.h |    8 ++--
 panels/wacom/calibrator/calibrator.c     |   24 ++++----
 panels/wacom/cc-wacom-page.c             |   81 ++++++++++++++----------------
 4 files changed, 56 insertions(+), 67 deletions(-)
---
diff --git a/panels/wacom/calibrator/calibrator-gui.c b/panels/wacom/calibrator/calibrator-gui.c
index 5b9bcba..921405f 100644
--- a/panels/wacom/calibrator/calibrator-gui.c
+++ b/panels/wacom/calibrator/calibrator-gui.c
@@ -697,7 +697,7 @@ calib_area_new (GdkScreen      *screen,
   g_return_val_if_fail (old_axis, NULL);
   g_return_val_if_fail (callback, NULL);
 
-  g_debug ("Current calibration: %d, %d, %d, %d\n",
+  g_debug ("Current calibration: %f, %f, %f, %f\n",
            old_axis->x_min,
            old_axis->y_min,
            old_axis->x_max,
@@ -739,10 +739,6 @@ calib_area_new (GdkScreen      *screen,
   if (screen == NULL)
     screen = gdk_screen_get_default ();
   gdk_screen_get_monitor_geometry (screen, monitor, &rect);
-  gtk_window_move (GTK_WINDOW (calib_area->window), rect.x, rect.y);
-  gtk_window_set_default_size (GTK_WINDOW (calib_area->window),
-                               rect.width,
-                               rect.height);
 
   calib_area->calibrator.geometry = rect;
 
@@ -765,7 +761,7 @@ calib_area_new (GdkScreen      *screen,
                     G_CALLBACK (on_fullscreen),
                     calib_area);
 
-  gtk_window_fullscreen (GTK_WINDOW (calib_area->window));
+  gtk_window_fullscreen_on_monitor (GTK_WINDOW (calib_area->window), screen, monitor);
 
   visual = gdk_screen_get_rgba_visual (screen);
   if (visual != NULL)
@@ -790,7 +786,7 @@ calib_area_finish (CalibArea *area,
   *swap_xy  = area->swap;
 
   if (area->success)
-    g_debug ("Final calibration: %d, %d, %d, %d\n",
+    g_debug ("Final calibration: %f, %f, %f, %f\n",
              new_axis->x_min,
              new_axis->y_min,
              new_axis->x_max,
diff --git a/panels/wacom/calibrator/calibrator-gui.h b/panels/wacom/calibrator/calibrator-gui.h
index 6741215..d65eb8b 100644
--- a/panels/wacom/calibrator/calibrator-gui.h
+++ b/panels/wacom/calibrator/calibrator-gui.h
@@ -29,10 +29,10 @@
 /* struct to hold min/max info of the X and Y axis */
 typedef struct
 {
-       int x_min;
-       int x_max;
-       int y_min;
-       int y_max;
+       gdouble x_min;
+       gdouble x_max;
+       gdouble y_min;
+       gdouble y_max;
 } XYinfo;
 
 typedef struct CalibArea CalibArea;
diff --git a/panels/wacom/calibrator/calibrator.c b/panels/wacom/calibrator/calibrator.c
index b78f328..71adcf6 100644
--- a/panels/wacom/calibrator/calibrator.c
+++ b/panels/wacom/calibrator/calibrator.c
@@ -134,8 +134,8 @@ finish (struct Calib *c,
     gboolean swap_xy;
     float scale_x;
     float scale_y;
-    int delta_x;
-    int delta_y;
+    float delta_x;
+    float delta_y;
     XYinfo axis = {-1, -1, -1, -1};
 
     if (c->num_clicks != 4)
@@ -152,8 +152,8 @@ finish (struct Calib *c,
 
     /* Compute min/max coordinates. */
     /* These are scaled using the values of old_axis */
-    scale_x = (c->old_axis.x_max - c->old_axis.x_min)/(float)c->geometry.width;
-    scale_y = (c->old_axis.y_max - c->old_axis.y_min)/(float)c->geometry.height;
+    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.
@@ -162,25 +162,25 @@ finish (struct Calib *c,
         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 = ((((c->clicked_x[UR] + c->clicked_x[LR]) / 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 = ((((c->clicked_y[LL] + c->clicked_y[LR]) / 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
      * corners (using the same coordinate system they are currently in)
      */
-    delta_x = (axis.x_max - axis.x_min) / (float)(NUM_BLOCKS - 2);
+    delta_x = (1 - axis.x_max - axis.x_min) / (float)(NUM_BLOCKS - 2);
     axis.x_min -= delta_x;
-    axis.x_max += delta_x;
-    delta_y = (axis.y_max - axis.y_min) / (float)(NUM_BLOCKS - 2);
+    axis.x_max -= delta_x;
+    delta_y = (1 - 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)
     {
-        SWAP (int, axis.x_min, axis.y_min);
-        SWAP (int, axis.x_max, axis.y_max);
+        SWAP (gdouble, axis.x_min, axis.y_min);
+        SWAP (gdouble, axis.x_max, axis.y_max);
     }
 
     *new_axis = axis;
diff --git a/panels/wacom/cc-wacom-page.c b/panels/wacom/cc-wacom-page.c
index 2d29b61..7ddbeb4 100644
--- a/panels/wacom/cc-wacom-page.c
+++ b/panels/wacom/cc-wacom-page.c
@@ -132,12 +132,11 @@ get_layout_type (CcWacomDevice *device)
        return layout;
 }
 
-#if 0
 static void
-set_calibration (GsdWacomDevice *device,
+set_calibration (CcWacomDevice  *device,
                  const gint      display_width,
                  const gint      display_height,
-                 gint           *cal,
+                 gdouble        *cal,
                  gsize           ncal,
                  GSettings      *settings)
 {
@@ -148,7 +147,7 @@ set_calibration (GsdWacomDevice *device,
        gint         i;
 
        current = g_settings_get_value (settings, "area");
-       g_variant_get_fixed_array (current, &nvalues, sizeof (gint32));
+       g_variant_get_fixed_array (current, &nvalues, sizeof (gdouble));
        if ((ncal != 4) || (nvalues != 4)) {
                g_warning("Unable set set device calibration property. Got %"G_GSIZE_FORMAT" items to put in 
%"G_GSIZE_FORMAT" slots; expected %d items.\n", ncal, nvalues, 4);
                return;
@@ -156,14 +155,14 @@ set_calibration (GsdWacomDevice *device,
 
        tmp = g_malloc (nvalues * sizeof (GVariant*));
        for (i = 0; i < ncal; i++)
-               tmp[i] = g_variant_new_int32 (cal[i]);
+               tmp[i] = g_variant_new_double (cal[i]);
 
-       array = g_variant_new_array (G_VARIANT_TYPE_INT32, tmp, nvalues);
+       array = g_variant_new_array (G_VARIANT_TYPE_DOUBLE, tmp, nvalues);
        g_settings_set_value (settings, "area", array);
 
        g_free (tmp);
 
-       g_debug ("Setting area top (%d, %d) bottom (%d, %d) (last used resolution: %d x %d)",
+       g_debug ("Setting area top (%f, %f) bottom (%f, %f) (last used resolution: %d x %d)",
                 cal[0], cal[1], cal[2], cal[3],
                 display_width, display_height);
 }
@@ -176,7 +175,8 @@ finish_calibration (CalibArea *area,
        CcWacomPagePrivate *priv = page->priv;
        XYinfo axis;
        gboolean swap_xy;
-       gint cal[4], display_width, display_height;
+       gdouble cal[4];
+       gint display_width, display_height;
 
        if (calib_area_finish (area, &axis, &swap_xy)) {
                cal[0] = axis.x_min;
@@ -207,13 +207,11 @@ finish_calibration (CalibArea *area,
 static gboolean
 run_calibration (CcWacomPage *page,
                 GVariant    *old_calibration,
-                gint        *cal,
+                gdouble     *cal,
                 gint         monitor)
 {
        XYinfo              old_axis;
-       GdkDevice          *gdk_device;
        CcWacomPagePrivate *priv;
-       int                 device_id;
 
        g_assert (page->priv->area == NULL);
 
@@ -223,16 +221,10 @@ run_calibration (CcWacomPage *page,
        old_axis.y_max = cal[3];
 
        priv = page->priv;
-       gdk_device = gsd_wacom_device_get_gdk_device (priv->stylus);
-
-       if (gdk_device != NULL)
-               g_object_get (gdk_device, "device-id", &device_id, NULL);
-       else
-               device_id = -1;
 
        priv->area = calib_area_new (NULL,
                                     monitor,
-                                    device_id,
+                                    -1, /* FIXME: Pass GdkDevice/ClutterInputDevice */
                                     finish_calibration,
                                     page,
                                     &old_axis,
@@ -251,17 +243,31 @@ static void
 calibrate (CcWacomPage *page)
 {
        CcWacomPagePrivate *priv;
-       int i, *calibration;
+       int i;
        GVariant *old_calibration, **tmp, *array;
+       gdouble *calibration;
        gsize ncal;
        gint monitor;
-#ifdef FAKE_AREA
        GdkScreen *screen;
-#endif
+       GnomeRRScreen *rr_screen;
+       GnomeRROutput *output;
+       GError *error = NULL;
+       gint x, y;
 
        priv = page->priv;
 
-       monitor = gsd_wacom_device_get_display_monitor (page->priv->stylus);
+       screen = gdk_screen_get_default ();
+       rr_screen = gnome_rr_screen_new (screen, &error);
+       if (error) {
+               g_warning ("Could not connect to display manager: %s", error->message);
+               g_error_free (error);
+               return;
+       }
+
+       output = cc_wacom_device_get_output (page->priv->stylus, rr_screen);
+       gnome_rr_output_get_position (output, &x, &y);
+       monitor = gdk_screen_get_monitor_at_point (screen, x, y);
+
        if (monitor < 0) {
                /* The display the tablet should be mapped to could not be located.
                 * This shouldn't happen if the EDID data is good...
@@ -271,50 +277,39 @@ calibrate (CcWacomPage *page)
        }
 
        old_calibration = g_settings_get_value (page->priv->wacom_settings, "area");
-       g_variant_get_fixed_array (old_calibration, &ncal, sizeof (gint32));
+       g_variant_get_fixed_array (old_calibration, &ncal, sizeof (gdouble));
 
        if (ncal != 4) {
                g_warning("Device calibration property has wrong length. Got %"G_GSIZE_FORMAT" items; 
expected %d.\n", ncal, 4);
                return;
        }
 
-#ifdef FAKE_AREA
-       /* Prepare the monitor attachment */
-       screen = gdk_screen_get_default ();
-
-       calibration = g_new0 (int, 4);
-       calibration[0] = 0;
-       calibration[1] = gdk_screen_get_width (screen);
-       calibration[2] = 0;
-       calibration[3] = gdk_screen_get_height (screen);
-#else
-       calibration = gsd_wacom_device_get_default_area (priv->stylus);
-#endif /* FAKE_AREA */
+       calibration = g_new0 (gdouble, ncal);
 
        /* Reset the current values, to avoid old calibrations
         * from interfering with the calibration */
        tmp = g_malloc (ncal * sizeof (GVariant*));
-       for (i = 0; i < ncal; i++)
-               tmp[i] = g_variant_new_int32 (calibration[i]);
+       for (i = 0; i < ncal; i++) {
+               calibration[i] = 0.0;
+               tmp[i] = g_variant_new_double (calibration[i]);
+       }
 
-       array = g_variant_new_array (G_VARIANT_TYPE_INT32, tmp, 4);
+       array = g_variant_new_array (G_VARIANT_TYPE_DOUBLE, tmp, ncal);
        g_settings_set_value (page->priv->wacom_settings, "area", array);
        g_free (tmp);
 
        run_calibration (page, old_calibration, calibration, monitor);
        g_free (calibration);
        gtk_widget_set_sensitive (WID ("button-calibrate"), FALSE);
-}
 
-#endif
+       g_object_unref (rr_screen);
+}
 
 static void
 calibrate_button_clicked_cb (GtkButton   *button,
                             CcWacomPage *page)
 {
-#if 0
        calibrate (page);
-#endif
 }
 
 /* This avoids us crashing when a newer version of
@@ -937,9 +932,7 @@ cc_wacom_page_calibrate (CcWacomPage *page)
 {
        g_return_if_fail (CC_IS_WACOM_PAGE (page));
 
-#if 0
        calibrate (page);
-#endif
 }
 
 gboolean


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