[mutter/wip/tablet-protocol-v2: 50/65] backends: Add function to apply pressure sensitivity to tablet tools
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [mutter/wip/tablet-protocol-v2: 50/65] backends: Add function to apply pressure sensitivity to tablet tools
- Date: Wed, 29 Jun 2016 12:24:32 +0000 (UTC)
commit c6b3447f94cd8fd903b43031d5ab9087c6076650
Author: Carlos Garnacho <carlosg gnome org>
Date: Wed Jun 22 15:58:33 2016 +0200
backends: Add function to apply pressure sensitivity to tablet tools
A bezier curve is created out of the 2 control points in settings, so
the pressure is made to follow the stablished curve between 0 and 1.
src/backends/meta-input-settings-private.h | 5 ++
src/backends/meta-input-settings.c | 59 ++++++++++++++++++++++++++++
2 files changed, 64 insertions(+), 0 deletions(-)
---
diff --git a/src/backends/meta-input-settings-private.h b/src/backends/meta-input-settings-private.h
index 8131086..8c8fed6 100644
--- a/src/backends/meta-input-settings-private.h
+++ b/src/backends/meta-input-settings-private.h
@@ -110,6 +110,11 @@ GDesktopStylusButtonAction meta_input_settings_get_stylus_button_action (MetaInp
ClutterInputDeviceTool *tool,
ClutterInputDevice
*current_device,
guint button);
+gdouble meta_input_settings_translate_tablet_tool_pressure (MetaInputSettings
*input_settings,
+ ClutterInputDeviceTool *tool,
+ ClutterInputDevice
*current_tablet,
+ gdouble
pressure);
+
#ifdef HAVE_LIBWACOM
WacomDevice * meta_input_settings_get_tablet_wacom_device (MetaInputSettings *settings,
ClutterInputDevice *device);
diff --git a/src/backends/meta-input-settings.c b/src/backends/meta-input-settings.c
index 049d1b8..0fec343 100644
--- a/src/backends/meta-input-settings.c
+++ b/src/backends/meta-input-settings.c
@@ -1243,3 +1243,62 @@ meta_input_settings_get_tablet_wacom_device (MetaInputSettings *settings,
return info->wacom_device;
}
#endif /* HAVE_LIBWACOM */
+
+static gdouble
+calculate_bezier_position (gdouble pos,
+ gdouble x1,
+ gdouble y1,
+ gdouble x2,
+ gdouble y2)
+{
+ gdouble int1_y, int2_y;
+
+ pos = CLAMP (pos, 0, 1);
+
+ /* Intersection between 0,0 and x1,y1 */
+ int1_y = pos * y1;
+
+ /* Intersection between x2,y2 and 1,1 */
+ int2_y = (pos * (1 - y2)) + y2;
+
+ /* Find the new position in the line traced by the previous points */
+ return (pos * (int2_y - int1_y)) + int1_y;
+}
+
+gdouble
+meta_input_settings_translate_tablet_tool_pressure (MetaInputSettings *input_settings,
+ ClutterInputDeviceTool *tool,
+ ClutterInputDevice *current_tablet,
+ gdouble pressure)
+{
+ GSettings *settings;
+ GVariant *variant;
+ const gint32 *curve;
+ gsize n_elems;
+
+ pressure = CLAMP (pressure, 0, 1);
+
+ g_return_val_if_fail (META_IS_INPUT_SETTINGS (input_settings), pressure);
+ g_return_val_if_fail (CLUTTER_IS_INPUT_DEVICE_TOOL (tool), pressure);
+ g_return_val_if_fail (CLUTTER_IS_INPUT_DEVICE (current_tablet), pressure);
+
+ settings = lookup_tool_settings (tool, current_tablet);
+
+ if (clutter_input_device_tool_get_tool_type (tool) == CLUTTER_INPUT_DEVICE_TOOL_ERASER)
+ variant = g_settings_get_value (settings, "eraser-pressure-curve");
+ else
+ variant = g_settings_get_value (settings, "pressure-curve");
+
+ curve = g_variant_get_fixed_array (variant, &n_elems, sizeof (gint32));
+ if (n_elems != 4)
+ return pressure;
+
+ pressure = calculate_bezier_position (pressure,
+ (gdouble) curve[0] / 100,
+ (gdouble) curve[1] / 100,
+ (gdouble) curve[2] / 100,
+ (gdouble) curve[3] / 100);
+ g_variant_unref (variant);
+
+ return pressure;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]