wacom: Instaurate 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.
This commit is contained in:
parent
dbff3d9284
commit
cf408c27b0
4 changed files with 56 additions and 67 deletions
|
@ -697,7 +697,7 @@ calib_area_new (GdkScreen *screen,
|
||||||
g_return_val_if_fail (old_axis, NULL);
|
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: %d, %d, %d, %d\n",
|
g_debug ("Current calibration: %f, %f, %f, %f\n",
|
||||||
old_axis->x_min,
|
old_axis->x_min,
|
||||||
old_axis->y_min,
|
old_axis->y_min,
|
||||||
old_axis->x_max,
|
old_axis->x_max,
|
||||||
|
@ -739,10 +739,6 @@ calib_area_new (GdkScreen *screen,
|
||||||
if (screen == NULL)
|
if (screen == NULL)
|
||||||
screen = gdk_screen_get_default ();
|
screen = gdk_screen_get_default ();
|
||||||
gdk_screen_get_monitor_geometry (screen, monitor, &rect);
|
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;
|
calib_area->calibrator.geometry = rect;
|
||||||
|
|
||||||
|
@ -765,7 +761,7 @@ calib_area_new (GdkScreen *screen,
|
||||||
G_CALLBACK (on_fullscreen),
|
G_CALLBACK (on_fullscreen),
|
||||||
calib_area);
|
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);
|
visual = gdk_screen_get_rgba_visual (screen);
|
||||||
if (visual != NULL)
|
if (visual != NULL)
|
||||||
|
@ -790,7 +786,7 @@ calib_area_finish (CalibArea *area,
|
||||||
*swap_xy = area->swap;
|
*swap_xy = area->swap;
|
||||||
|
|
||||||
if (area->success)
|
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->x_min,
|
||||||
new_axis->y_min,
|
new_axis->y_min,
|
||||||
new_axis->x_max,
|
new_axis->x_max,
|
||||||
|
|
|
@ -29,10 +29,10 @@
|
||||||
/* struct to hold min/max info of the X and Y axis */
|
/* struct to hold min/max info of the X and Y axis */
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
int x_min;
|
gdouble x_min;
|
||||||
int x_max;
|
gdouble x_max;
|
||||||
int y_min;
|
gdouble y_min;
|
||||||
int y_max;
|
gdouble y_max;
|
||||||
} XYinfo;
|
} XYinfo;
|
||||||
|
|
||||||
typedef struct CalibArea CalibArea;
|
typedef struct CalibArea CalibArea;
|
||||||
|
|
|
@ -134,8 +134,8 @@ finish (struct Calib *c,
|
||||||
gboolean swap_xy;
|
gboolean swap_xy;
|
||||||
float scale_x;
|
float scale_x;
|
||||||
float scale_y;
|
float scale_y;
|
||||||
int delta_x;
|
float delta_x;
|
||||||
int delta_y;
|
float delta_y;
|
||||||
XYinfo axis = {-1, -1, -1, -1};
|
XYinfo axis = {-1, -1, -1, -1};
|
||||||
|
|
||||||
if (c->num_clicks != 4)
|
if (c->num_clicks != 4)
|
||||||
|
@ -152,8 +152,8 @@ finish (struct Calib *c,
|
||||||
|
|
||||||
/* Compute min/max coordinates. */
|
/* Compute min/max coordinates. */
|
||||||
/* These are scaled using the values of old_axis */
|
/* 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_x = (1 - 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_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
|
/* Swap back for usage with the collected click points, which are in screen
|
||||||
* coordinates, hence possibly rotated.
|
* coordinates, hence possibly rotated.
|
||||||
|
@ -162,25 +162,25 @@ finish (struct Calib *c,
|
||||||
SWAP(gdouble, scale_x, scale_y);
|
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_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_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
|
/* 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 = (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_min -= delta_x;
|
||||||
axis.x_max += delta_x;
|
axis.x_max -= delta_x;
|
||||||
delta_y = (axis.y_max - axis.y_min) / (float)(NUM_BLOCKS - 2);
|
delta_y = (1 - 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)
|
||||||
{
|
{
|
||||||
SWAP (int, axis.x_min, axis.y_min);
|
SWAP (gdouble, axis.x_min, axis.y_min);
|
||||||
SWAP (int, axis.x_max, axis.y_max);
|
SWAP (gdouble, axis.x_max, axis.y_max);
|
||||||
}
|
}
|
||||||
|
|
||||||
*new_axis = axis;
|
*new_axis = axis;
|
||||||
|
|
|
@ -132,12 +132,11 @@ get_layout_type (CcWacomDevice *device)
|
||||||
return layout;
|
return layout;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
|
||||||
static void
|
static void
|
||||||
set_calibration (GsdWacomDevice *device,
|
set_calibration (CcWacomDevice *device,
|
||||||
const gint display_width,
|
const gint display_width,
|
||||||
const gint display_height,
|
const gint display_height,
|
||||||
gint *cal,
|
gdouble *cal,
|
||||||
gsize ncal,
|
gsize ncal,
|
||||||
GSettings *settings)
|
GSettings *settings)
|
||||||
{
|
{
|
||||||
|
@ -148,7 +147,7 @@ set_calibration (GsdWacomDevice *device,
|
||||||
gint i;
|
gint i;
|
||||||
|
|
||||||
current = g_settings_get_value (settings, "area");
|
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)) {
|
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);
|
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;
|
return;
|
||||||
|
@ -156,14 +155,14 @@ set_calibration (GsdWacomDevice *device,
|
||||||
|
|
||||||
tmp = g_malloc (nvalues * sizeof (GVariant*));
|
tmp = g_malloc (nvalues * sizeof (GVariant*));
|
||||||
for (i = 0; i < ncal; i++)
|
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_settings_set_value (settings, "area", array);
|
||||||
|
|
||||||
g_free (tmp);
|
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],
|
cal[0], cal[1], cal[2], cal[3],
|
||||||
display_width, display_height);
|
display_width, display_height);
|
||||||
}
|
}
|
||||||
|
@ -176,7 +175,8 @@ finish_calibration (CalibArea *area,
|
||||||
CcWacomPagePrivate *priv = page->priv;
|
CcWacomPagePrivate *priv = page->priv;
|
||||||
XYinfo axis;
|
XYinfo axis;
|
||||||
gboolean swap_xy;
|
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)) {
|
if (calib_area_finish (area, &axis, &swap_xy)) {
|
||||||
cal[0] = axis.x_min;
|
cal[0] = axis.x_min;
|
||||||
|
@ -207,13 +207,11 @@ finish_calibration (CalibArea *area,
|
||||||
static gboolean
|
static gboolean
|
||||||
run_calibration (CcWacomPage *page,
|
run_calibration (CcWacomPage *page,
|
||||||
GVariant *old_calibration,
|
GVariant *old_calibration,
|
||||||
gint *cal,
|
gdouble *cal,
|
||||||
gint monitor)
|
gint monitor)
|
||||||
{
|
{
|
||||||
XYinfo old_axis;
|
XYinfo old_axis;
|
||||||
GdkDevice *gdk_device;
|
|
||||||
CcWacomPagePrivate *priv;
|
CcWacomPagePrivate *priv;
|
||||||
int device_id;
|
|
||||||
|
|
||||||
g_assert (page->priv->area == NULL);
|
g_assert (page->priv->area == NULL);
|
||||||
|
|
||||||
|
@ -223,16 +221,10 @@ run_calibration (CcWacomPage *page,
|
||||||
old_axis.y_max = cal[3];
|
old_axis.y_max = cal[3];
|
||||||
|
|
||||||
priv = page->priv;
|
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,
|
priv->area = calib_area_new (NULL,
|
||||||
monitor,
|
monitor,
|
||||||
device_id,
|
-1, /* FIXME: Pass GdkDevice/ClutterInputDevice */
|
||||||
finish_calibration,
|
finish_calibration,
|
||||||
page,
|
page,
|
||||||
&old_axis,
|
&old_axis,
|
||||||
|
@ -251,17 +243,31 @@ static void
|
||||||
calibrate (CcWacomPage *page)
|
calibrate (CcWacomPage *page)
|
||||||
{
|
{
|
||||||
CcWacomPagePrivate *priv;
|
CcWacomPagePrivate *priv;
|
||||||
int i, *calibration;
|
int i;
|
||||||
GVariant *old_calibration, **tmp, *array;
|
GVariant *old_calibration, **tmp, *array;
|
||||||
|
gdouble *calibration;
|
||||||
gsize ncal;
|
gsize ncal;
|
||||||
gint monitor;
|
gint monitor;
|
||||||
#ifdef FAKE_AREA
|
|
||||||
GdkScreen *screen;
|
GdkScreen *screen;
|
||||||
#endif
|
GnomeRRScreen *rr_screen;
|
||||||
|
GnomeRROutput *output;
|
||||||
|
GError *error = NULL;
|
||||||
|
gint x, y;
|
||||||
|
|
||||||
priv = page->priv;
|
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) {
|
if (monitor < 0) {
|
||||||
/* The display the tablet should be mapped to could not be located.
|
/* The display the tablet should be mapped to could not be located.
|
||||||
* This shouldn't happen if the EDID data is good...
|
* 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");
|
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) {
|
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);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef FAKE_AREA
|
calibration = g_new0 (gdouble, ncal);
|
||||||
/* 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 */
|
|
||||||
|
|
||||||
/* Reset the current values, to avoid old calibrations
|
/* Reset the current values, to avoid old calibrations
|
||||||
* from interfering with the calibration */
|
* from interfering with the calibration */
|
||||||
tmp = g_malloc (ncal * sizeof (GVariant*));
|
tmp = g_malloc (ncal * sizeof (GVariant*));
|
||||||
for (i = 0; i < ncal; i++)
|
for (i = 0; i < ncal; i++) {
|
||||||
tmp[i] = g_variant_new_int32 (calibration[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_settings_set_value (page->priv->wacom_settings, "area", array);
|
||||||
g_free (tmp);
|
g_free (tmp);
|
||||||
|
|
||||||
run_calibration (page, old_calibration, calibration, monitor);
|
run_calibration (page, old_calibration, calibration, monitor);
|
||||||
g_free (calibration);
|
g_free (calibration);
|
||||||
gtk_widget_set_sensitive (WID ("button-calibrate"), FALSE);
|
gtk_widget_set_sensitive (WID ("button-calibrate"), FALSE);
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
g_object_unref (rr_screen);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
calibrate_button_clicked_cb (GtkButton *button,
|
calibrate_button_clicked_cb (GtkButton *button,
|
||||||
CcWacomPage *page)
|
CcWacomPage *page)
|
||||||
{
|
{
|
||||||
#if 0
|
|
||||||
calibrate (page);
|
calibrate (page);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This avoids us crashing when a newer version of
|
/* 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));
|
g_return_if_fail (CC_IS_WACOM_PAGE (page));
|
||||||
|
|
||||||
#if 0
|
|
||||||
calibrate (page);
|
calibrate (page);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
|
|
Loading…
Add table
Reference in a new issue