wacom: Reset the calibration before starting a new one
We shouldn't be using the old calibration values to create the new ones, so reset the "area" settings before starting a new calibration, and re-apply the saved calibration if the calibration is cancelled or fails. https://bugzilla.gnome.org/show_bug.cgi?id=707784
This commit is contained in:
parent
21a2a53fea
commit
6aa409ffdb
1 changed files with 39 additions and 34 deletions
|
@ -192,6 +192,13 @@ finish_calibration (CalibArea *area,
|
||||||
display_width,
|
display_width,
|
||||||
display_height,
|
display_height,
|
||||||
cal, 4, priv->wacom_settings);
|
cal, 4, priv->wacom_settings);
|
||||||
|
} else {
|
||||||
|
/* Reset the old values */
|
||||||
|
GVariant *old_calibration;
|
||||||
|
|
||||||
|
old_calibration = g_object_get_data (G_OBJECT (page), "old-calibration");
|
||||||
|
g_settings_set_value (page->priv->wacom_settings, "area", old_calibration);
|
||||||
|
g_object_set_data (G_OBJECT (page), "old-calibration", NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
calib_area_free (area);
|
calib_area_free (area);
|
||||||
|
@ -201,6 +208,7 @@ finish_calibration (CalibArea *area,
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
run_calibration (CcWacomPage *page,
|
run_calibration (CcWacomPage *page,
|
||||||
|
GVariant *old_calibration,
|
||||||
gint *cal,
|
gint *cal,
|
||||||
gint monitor)
|
gint monitor)
|
||||||
{
|
{
|
||||||
|
@ -233,6 +241,11 @@ run_calibration (CcWacomPage *page,
|
||||||
THRESHOLD_MISCLICK,
|
THRESHOLD_MISCLICK,
|
||||||
THRESHOLD_DOUBLECLICK);
|
THRESHOLD_DOUBLECLICK);
|
||||||
|
|
||||||
|
g_object_set_data_full (G_OBJECT (page),
|
||||||
|
"old-calibration",
|
||||||
|
old_calibration,
|
||||||
|
(GDestroyNotify) g_variant_unref);
|
||||||
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -240,11 +253,13 @@ static void
|
||||||
calibrate (CcWacomPage *page)
|
calibrate (CcWacomPage *page)
|
||||||
{
|
{
|
||||||
CcWacomPagePrivate *priv;
|
CcWacomPagePrivate *priv;
|
||||||
int i, calibration[4];
|
int i, *calibration;
|
||||||
GVariant *variant;
|
GVariant *old_calibration, **tmp, *array;
|
||||||
int *current;
|
|
||||||
gsize ncal;
|
gsize ncal;
|
||||||
gint monitor;
|
gint monitor;
|
||||||
|
#ifdef FAKE_AREA
|
||||||
|
GdkScreen *screen;
|
||||||
|
#endif
|
||||||
|
|
||||||
priv = page->priv;
|
priv = page->priv;
|
||||||
|
|
||||||
|
@ -257,49 +272,39 @@ calibrate (CcWacomPage *page)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
variant = g_settings_get_value (page->priv->wacom_settings, "area");
|
old_calibration = g_settings_get_value (page->priv->wacom_settings, "area");
|
||||||
current = (int *) g_variant_get_fixed_array (variant, &ncal, sizeof (gint32));
|
g_variant_get_fixed_array (old_calibration, &ncal, sizeof (gint32));
|
||||||
|
|
||||||
if (ncal != 4) {
|
if (ncal != 4) {
|
||||||
g_warning("Device calibration property has wrong length. Got %"G_GSIZE_FORMAT" items; expected %d.\n", ncal, 4);
|
g_warning("Device calibration property has wrong length. Got %"G_GSIZE_FORMAT" items; expected %d.\n", ncal, 4);
|
||||||
g_free (current);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < 4; i++)
|
|
||||||
calibration[i] = current[i];
|
|
||||||
|
|
||||||
if (calibration[0] == -1 &&
|
|
||||||
calibration[1] == -1 &&
|
|
||||||
calibration[2] == -1 &&
|
|
||||||
calibration[3] == -1) {
|
|
||||||
gint *device_cal;
|
|
||||||
|
|
||||||
#ifdef FAKE_AREA
|
#ifdef FAKE_AREA
|
||||||
GdkScreen *screen;
|
/* Prepare the monitor attachment */
|
||||||
screen = gdk_screen_get_default ();
|
screen = gdk_screen_get_default ();
|
||||||
|
|
||||||
device_cal = g_new0 (int, 4);
|
calibration = g_new0 (int, 4);
|
||||||
device_cal[0] = 0;
|
calibration[0] = 0;
|
||||||
device_cal[1] = gdk_screen_get_width (screen);
|
calibration[1] = gdk_screen_get_width (screen);
|
||||||
device_cal[2] = 0;
|
calibration[2] = 0;
|
||||||
device_cal[3] = gdk_screen_get_height (screen);
|
calibration[3] = gdk_screen_get_height (screen);
|
||||||
#else
|
#else
|
||||||
device_cal = gsd_wacom_device_get_area (page->priv->stylus);
|
calibration = gsd_wacom_device_get_default_area (priv->stylus);
|
||||||
|
|
||||||
if (device_cal == NULL) {
|
|
||||||
g_warning ("Failed to get device's area. "
|
|
||||||
"Not running calibration.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
#endif /* FAKE_AREA */
|
#endif /* FAKE_AREA */
|
||||||
|
|
||||||
for (i = 0; i < 4; i++)
|
/* Reset the current values, to avoid old calibrations
|
||||||
calibration[i] = device_cal[i];
|
* from interfering with the calibration */
|
||||||
g_free (device_cal);
|
tmp = g_malloc (ncal * sizeof (GVariant*));
|
||||||
}
|
for (i = 0; i < ncal; i++)
|
||||||
|
tmp[i] = g_variant_new_int32 (calibration[i]);
|
||||||
|
g_free (calibration);
|
||||||
|
|
||||||
run_calibration (page, calibration, monitor);
|
array = g_variant_new_array (G_VARIANT_TYPE_INT32, tmp, 4);
|
||||||
|
g_settings_set_value (page->priv->wacom_settings, "area", array);
|
||||||
|
g_free (tmp);
|
||||||
|
|
||||||
|
run_calibration (page, old_calibration, calibration, monitor);
|
||||||
gtk_widget_set_sensitive (WID ("button-calibrate"), FALSE);
|
gtk_widget_set_sensitive (WID ("button-calibrate"), FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue