diff options
author | Carlos Garnacho <carlosg@gnome.org> | 2016-10-31 17:43:38 +0100 |
---|---|---|
committer | Carlos Garnacho <carlosg@gnome.org> | 2016-11-04 21:25:31 +0100 |
commit | b252771a8f08932fc1fadaa3d971ff931c4ba568 (patch) | |
tree | ca8f84d94314da30ac11667a2e5027da21f5c6ef /clutter/clutter/evdev | |
parent | 75c3f0ffbad1b9606b31ac073c10c9c0e75e7c91 (diff) | |
download | mutter-b252771a8f08932fc1fadaa3d971ff931c4ba568.tar.gz |
clutter/evdev: Take over stylus configuration
Stylus configuration (stylus buttons, pressure) was handled
at the very high level, doing the button and pressure translations
right before sending these to wayland clients.
However, it makes more sense to store these settings into the
ClutterInputDeviceTool itself, and have clutter apply the config
at the lower level so 1) the settings actually apply desktop-wide,
not just in clients and 2) X11 and wayland may share similar
configuration paths. The settings are now just applied whenever
the tool enters proximity, in reaction to
ClutterDeviceManager::tool-changed.
This commit moves all handling of these two settings to
the clutter level, and removes the wayland-specific paths
https://bugzilla.gnome.org/show_bug.cgi?id=773779
Diffstat (limited to 'clutter/clutter/evdev')
-rw-r--r-- | clutter/clutter/evdev/clutter-device-manager-evdev.c | 7 | ||||
-rw-r--r-- | clutter/clutter/evdev/clutter-evdev.h | 8 | ||||
-rw-r--r-- | clutter/clutter/evdev/clutter-input-device-tool-evdev.c | 96 | ||||
-rw-r--r-- | clutter/clutter/evdev/clutter-input-device-tool-evdev.h | 7 | ||||
-rw-r--r-- | clutter/clutter/evdev/clutter-seat-evdev.c | 16 |
5 files changed, 129 insertions, 5 deletions
diff --git a/clutter/clutter/evdev/clutter-device-manager-evdev.c b/clutter/clutter/evdev/clutter-device-manager-evdev.c index eeddc22f4..732f0a301 100644 --- a/clutter/clutter/evdev/clutter-device-manager-evdev.c +++ b/clutter/clutter/evdev/clutter-device-manager-evdev.c @@ -1219,7 +1219,8 @@ input_device_update_tool (ClutterInputDevice *input_device, } static gdouble * -translate_tablet_axes (struct libinput_event_tablet_tool *tablet_event) +translate_tablet_axes (struct libinput_event_tablet_tool *tablet_event, + ClutterInputDeviceTool *tool) { GArray *axes = g_array_new (FALSE, FALSE, sizeof (gdouble)); struct libinput_tablet_tool *libinput_tool; @@ -1241,6 +1242,7 @@ translate_tablet_axes (struct libinput_event_tablet_tool *tablet_event) if (libinput_tablet_tool_has_pressure (libinput_tool)) { value = libinput_event_tablet_tool_get_pressure (tablet_event); + value = clutter_input_device_tool_evdev_translate_pressure (tool, value); g_array_append_val (axes, value); } @@ -1718,7 +1720,8 @@ process_device_event (ClutterDeviceManagerEvdev *manager_evdev, if (!stage) break; - axes = translate_tablet_axes (tablet_event); + axes = translate_tablet_axes (tablet_event, + evdev_device->last_tool); if (!axes) break; diff --git a/clutter/clutter/evdev/clutter-evdev.h b/clutter/clutter/evdev/clutter-evdev.h index 1f5485c17..8e8f8d94c 100644 --- a/clutter/clutter/evdev/clutter-evdev.h +++ b/clutter/clutter/evdev/clutter-evdev.h @@ -150,6 +150,14 @@ gboolean clutter_evdev_event_get_relative_motion (const ClutterEvent *event, double *dx_unaccel, double *dy_unaccel); +CLUTTER_AVAILABLE_IN_ALL +void clutter_evdev_input_device_tool_set_pressure_curve (ClutterInputDeviceTool *tool, + gdouble curve[4]); +CLUTTER_AVAILABLE_IN_ALL +void clutter_evdev_input_device_tool_set_button_code (ClutterInputDeviceTool *tool, + guint button, + guint evcode); + G_END_DECLS #endif /* __CLUTTER_EVDEV_H__ */ diff --git a/clutter/clutter/evdev/clutter-input-device-tool-evdev.c b/clutter/clutter/evdev/clutter-input-device-tool-evdev.c index e0cdb31a4..12106069a 100644 --- a/clutter/clutter/evdev/clutter-input-device-tool-evdev.c +++ b/clutter/clutter/evdev/clutter-input-device-tool-evdev.c @@ -26,6 +26,7 @@ #endif #include "clutter-input-device-tool-evdev.h" +#include "clutter-evdev.h" G_DEFINE_TYPE (ClutterInputDeviceToolEvdev, clutter_input_device_tool_evdev, CLUTTER_TYPE_INPUT_DEVICE_TOOL) @@ -35,6 +36,7 @@ clutter_input_device_tool_evdev_finalize (GObject *object) { ClutterInputDeviceToolEvdev *tool = CLUTTER_INPUT_DEVICE_TOOL_EVDEV (object); + g_hash_table_unref (tool->button_map); libinput_tablet_tool_unref (tool->tool); G_OBJECT_CLASS (clutter_input_device_tool_evdev_parent_class)->finalize (object); @@ -51,6 +53,7 @@ clutter_input_device_tool_evdev_class_init (ClutterInputDeviceToolEvdevClass *kl static void clutter_input_device_tool_evdev_init (ClutterInputDeviceToolEvdev *tool) { + tool->button_map = g_hash_table_new (NULL, NULL); } ClutterInputDeviceTool * @@ -70,3 +73,96 @@ clutter_input_device_tool_evdev_new (struct libinput_tablet_tool *tool, return CLUTTER_INPUT_DEVICE_TOOL (evdev_tool); } + +void +clutter_evdev_input_device_tool_set_pressure_curve (ClutterInputDeviceTool *tool, + gdouble curve[4]) +{ + ClutterInputDeviceToolEvdev *evdev_tool; + + g_return_if_fail (CLUTTER_IS_INPUT_DEVICE_TOOL_EVDEV (tool)); + g_return_if_fail (curve[0] >= 0 && curve[0] <= 1 && + curve[1] >= 0 && curve[1] <= 1 && + curve[2] >= 0 && curve[2] <= 1 && + curve[3] >= 0 && curve[3] <= 1); + + evdev_tool = CLUTTER_INPUT_DEVICE_TOOL_EVDEV (tool); + evdev_tool->pressure_curve[0] = curve[0]; + evdev_tool->pressure_curve[1] = curve[1]; + evdev_tool->pressure_curve[2] = curve[2]; + evdev_tool->pressure_curve[3] = curve[3]; +} + +void +clutter_evdev_input_device_tool_set_button_code (ClutterInputDeviceTool *tool, + guint button, + guint evcode) +{ + ClutterInputDeviceToolEvdev *evdev_tool; + + g_return_if_fail (CLUTTER_IS_INPUT_DEVICE_TOOL_EVDEV (tool)); + + evdev_tool = CLUTTER_INPUT_DEVICE_TOOL_EVDEV (tool); + + if (evcode == 0) + { + g_hash_table_remove (evdev_tool->button_map, GUINT_TO_POINTER (button)); + } + else + { + g_hash_table_insert (evdev_tool->button_map, GUINT_TO_POINTER (button), + GUINT_TO_POINTER (evcode)); + } +} + +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 +clutter_input_device_tool_evdev_translate_pressure (ClutterInputDeviceTool *tool, + gdouble pressure) +{ + ClutterInputDeviceToolEvdev *evdev_tool; + + g_return_val_if_fail (CLUTTER_IS_INPUT_DEVICE_TOOL (tool), pressure); + + evdev_tool = CLUTTER_INPUT_DEVICE_TOOL_EVDEV (tool); + + return calculate_bezier_position (CLAMP (pressure, 0, 1), + evdev_tool->pressure_curve[0], + evdev_tool->pressure_curve[1], + evdev_tool->pressure_curve[2], + evdev_tool->pressure_curve[3]); +} + +guint +clutter_input_device_tool_evdev_get_button_code (ClutterInputDeviceTool *tool, + guint button) +{ + ClutterInputDeviceToolEvdev *evdev_tool; + + g_return_val_if_fail (CLUTTER_IS_INPUT_DEVICE_TOOL (tool), 0); + + evdev_tool = CLUTTER_INPUT_DEVICE_TOOL_EVDEV (tool); + + return GPOINTER_TO_UINT (g_hash_table_lookup (evdev_tool->button_map, + GUINT_TO_POINTER (button))); +} diff --git a/clutter/clutter/evdev/clutter-input-device-tool-evdev.h b/clutter/clutter/evdev/clutter-input-device-tool-evdev.h index c92a2ca6b..91eaf8e04 100644 --- a/clutter/clutter/evdev/clutter-input-device-tool-evdev.h +++ b/clutter/clutter/evdev/clutter-input-device-tool-evdev.h @@ -59,6 +59,8 @@ struct _ClutterInputDeviceToolEvdev { ClutterInputDeviceTool parent_instance; struct libinput_tablet_tool *tool; + GHashTable *button_map; + gdouble pressure_curve[4]; }; struct _ClutterInputDeviceToolEvdevClass @@ -72,6 +74,11 @@ ClutterInputDeviceTool * clutter_input_device_tool_evdev_new (struct libinp guint64 serial, ClutterInputDeviceToolType type); +gdouble clutter_input_device_tool_evdev_translate_pressure (ClutterInputDeviceTool *tool, + gdouble pressure); +guint clutter_input_device_tool_evdev_get_button_code (ClutterInputDeviceTool *tool, + guint button); + G_END_DECLS #endif /* __CLUTTER_INPUT_DEVICE_EVDEV_TOOL_H__ */ diff --git a/clutter/clutter/evdev/clutter-seat-evdev.c b/clutter/clutter/evdev/clutter-seat-evdev.c index f5ae1dd46..b803286c2 100644 --- a/clutter/clutter/evdev/clutter-seat-evdev.c +++ b/clutter/clutter/evdev/clutter-seat-evdev.c @@ -32,6 +32,7 @@ #include "clutter-event-private.h" #include "clutter-input-device-evdev.h" +#include "clutter-input-device-tool-evdev.h" #include "clutter-main.h" /* Try to keep the pointer inside the stage. Hopefully no one is using @@ -433,6 +434,7 @@ clutter_seat_evdev_notify_button (ClutterSeatEvdev *seat, uint32_t button, uint32_t state) { + ClutterInputDeviceEvdev *device_evdev = (ClutterInputDeviceEvdev *) input_device; ClutterStage *stage; ClutterEvent *event = NULL; gint button_nr; @@ -528,13 +530,21 @@ clutter_seat_evdev_notify_button (ClutterSeatEvdev *seat, clutter_event_set_device (event, seat->core_pointer); clutter_event_set_source_device (event, input_device); + if (device_evdev->last_tool) + { + /* Apply the button event code as per the tool mapping */ + guint mapped_button; + + mapped_button = clutter_input_device_tool_evdev_get_button_code (device_evdev->last_tool, + button_nr); + if (mapped_button != 0) + button = mapped_button; + } + _clutter_evdev_event_set_event_code (event, button); if (clutter_input_device_get_device_type (input_device) == CLUTTER_TABLET_DEVICE) { - ClutterInputDeviceEvdev *device_evdev = - CLUTTER_INPUT_DEVICE_EVDEV (input_device); - clutter_event_set_device_tool (event, device_evdev->last_tool); clutter_event_set_device (event, input_device); } |