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
This commit is contained in:
@ -107,6 +107,16 @@ struct _MetaInputSettingsClass
|
||||
void (* set_trackball_accel_profile) (MetaInputSettings *settings,
|
||||
ClutterInputDevice *device,
|
||||
GDesktopPointerAccelProfile profile);
|
||||
|
||||
void (* set_stylus_pressure) (MetaInputSettings *settings,
|
||||
ClutterInputDevice *device,
|
||||
ClutterInputDeviceTool *tool,
|
||||
const gint32 curve[4]);
|
||||
void (* set_stylus_button_map) (MetaInputSettings *settings,
|
||||
ClutterInputDevice *device,
|
||||
ClutterInputDeviceTool *tool,
|
||||
GDesktopStylusButtonAction primary,
|
||||
GDesktopStylusButtonAction secondary);
|
||||
};
|
||||
|
||||
GType meta_input_settings_get_type (void) G_GNUC_CONST;
|
||||
@ -121,15 +131,6 @@ MetaMonitorInfo * meta_input_settings_get_tablet_monitor_info (MetaInputSett
|
||||
GDesktopTabletMapping meta_input_settings_get_tablet_mapping (MetaInputSettings *settings,
|
||||
ClutterInputDevice *device);
|
||||
|
||||
GDesktopStylusButtonAction meta_input_settings_get_stylus_button_action (MetaInputSettings *settings,
|
||||
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);
|
||||
|
||||
gboolean meta_input_settings_is_pad_button_grabbed (MetaInputSettings *input_settings,
|
||||
ClutterInputDevice *pad,
|
||||
guint button);
|
||||
|
@ -1275,6 +1275,77 @@ apply_device_settings (MetaInputSettings *input_settings,
|
||||
device);
|
||||
}
|
||||
|
||||
static void
|
||||
update_stylus_pressure (MetaInputSettings *input_settings,
|
||||
ClutterInputDevice *device,
|
||||
ClutterInputDeviceTool *tool)
|
||||
{
|
||||
MetaInputSettingsClass *input_settings_class;
|
||||
ToolSettings *tool_settings;
|
||||
const gint32 *curve;
|
||||
GVariant *variant;
|
||||
gsize n_elems;
|
||||
|
||||
if (clutter_input_device_get_device_type (device) != CLUTTER_TABLET_DEVICE &&
|
||||
clutter_input_device_get_device_type (device) != CLUTTER_PEN_DEVICE &&
|
||||
clutter_input_device_get_device_type (device) != CLUTTER_ERASER_DEVICE)
|
||||
return;
|
||||
|
||||
if (!tool)
|
||||
return;
|
||||
|
||||
tool_settings = lookup_tool_settings (tool, device);
|
||||
|
||||
if (clutter_input_device_tool_get_tool_type (tool) ==
|
||||
CLUTTER_INPUT_DEVICE_TOOL_ERASER)
|
||||
variant = g_settings_get_value (tool_settings->settings, "eraser-pressure-curve");
|
||||
else
|
||||
variant = g_settings_get_value (tool_settings->settings, "pressure-curve");
|
||||
|
||||
curve = g_variant_get_fixed_array (variant, &n_elems, sizeof (gint32));
|
||||
if (n_elems != 4)
|
||||
return;
|
||||
|
||||
input_settings_class = META_INPUT_SETTINGS_GET_CLASS (input_settings);
|
||||
input_settings_class->set_stylus_pressure (input_settings, device, tool, curve);
|
||||
}
|
||||
|
||||
static void
|
||||
update_stylus_buttonmap (MetaInputSettings *input_settings,
|
||||
ClutterInputDevice *device,
|
||||
ClutterInputDeviceTool *tool)
|
||||
{
|
||||
MetaInputSettingsClass *input_settings_class;
|
||||
GDesktopStylusButtonAction primary, secondary;
|
||||
ToolSettings *tool_settings;
|
||||
|
||||
if (clutter_input_device_get_device_type (device) != CLUTTER_TABLET_DEVICE &&
|
||||
clutter_input_device_get_device_type (device) != CLUTTER_PEN_DEVICE &&
|
||||
clutter_input_device_get_device_type (device) != CLUTTER_ERASER_DEVICE)
|
||||
return;
|
||||
|
||||
if (!tool)
|
||||
return;
|
||||
|
||||
tool_settings = lookup_tool_settings (tool, device);
|
||||
|
||||
primary = g_settings_get_enum (tool_settings->settings, "button-action");
|
||||
secondary = g_settings_get_enum (tool_settings->settings, "secondary-button-action");
|
||||
|
||||
input_settings_class = META_INPUT_SETTINGS_GET_CLASS (input_settings);
|
||||
input_settings_class->set_stylus_button_map (input_settings, device, tool,
|
||||
primary, secondary);
|
||||
}
|
||||
|
||||
static void
|
||||
apply_stylus_settings (MetaInputSettings *input_settings,
|
||||
ClutterInputDevice *device,
|
||||
ClutterInputDeviceTool *tool)
|
||||
{
|
||||
update_stylus_pressure (input_settings, device, tool);
|
||||
update_stylus_buttonmap (input_settings, device, tool);
|
||||
}
|
||||
|
||||
static void
|
||||
meta_input_settings_device_added (ClutterDeviceManager *device_manager,
|
||||
ClutterInputDevice *device,
|
||||
@ -1298,6 +1369,18 @@ meta_input_settings_device_removed (ClutterDeviceManager *device_manager,
|
||||
g_hash_table_remove (priv->mappable_devices, device);
|
||||
}
|
||||
|
||||
static void
|
||||
meta_input_settings_tool_changed (ClutterDeviceManager *device_manager,
|
||||
ClutterInputDevice *device,
|
||||
ClutterInputDeviceTool *tool,
|
||||
MetaInputSettings *input_settings)
|
||||
{
|
||||
if (!tool)
|
||||
return;
|
||||
|
||||
apply_stylus_settings (input_settings, device, tool);
|
||||
}
|
||||
|
||||
static void
|
||||
check_mappable_devices (MetaInputSettings *input_settings)
|
||||
{
|
||||
@ -1351,6 +1434,8 @@ meta_input_settings_init (MetaInputSettings *settings)
|
||||
G_CALLBACK (meta_input_settings_device_added), settings);
|
||||
g_signal_connect (priv->device_manager, "device-removed",
|
||||
G_CALLBACK (meta_input_settings_device_removed), settings);
|
||||
g_signal_connect (priv->device_manager, "tool-changed",
|
||||
G_CALLBACK (meta_input_settings_tool_changed), settings);
|
||||
|
||||
priv->mouse_settings = g_settings_new ("org.gnome.desktop.peripherals.mouse");
|
||||
g_signal_connect (priv->mouse_settings, "changed",
|
||||
@ -1461,29 +1546,6 @@ meta_input_settings_get_tablet_mapping (MetaInputSettings *settings,
|
||||
return g_settings_get_enum (info->settings, "mapping");
|
||||
}
|
||||
|
||||
GDesktopStylusButtonAction
|
||||
meta_input_settings_get_stylus_button_action (MetaInputSettings *input_settings,
|
||||
ClutterInputDeviceTool *tool,
|
||||
ClutterInputDevice *current_tablet,
|
||||
guint button)
|
||||
{
|
||||
ToolSettings *tool_settings;
|
||||
|
||||
g_return_val_if_fail (META_IS_INPUT_SETTINGS (input_settings),
|
||||
G_DESKTOP_STYLUS_BUTTON_ACTION_DEFAULT);
|
||||
g_return_val_if_fail (CLUTTER_IS_INPUT_DEVICE_TOOL (tool),
|
||||
G_DESKTOP_STYLUS_BUTTON_ACTION_DEFAULT);
|
||||
|
||||
tool_settings = lookup_tool_settings (tool, current_tablet);
|
||||
|
||||
if (button == 2)
|
||||
return tool_settings->button_action;
|
||||
else if (button == 3)
|
||||
return tool_settings->secondary_button_action;
|
||||
else
|
||||
return G_DESKTOP_STYLUS_BUTTON_ACTION_DEFAULT;
|
||||
}
|
||||
|
||||
static GDesktopPadButtonAction
|
||||
meta_input_settings_get_pad_button_action (MetaInputSettings *input_settings,
|
||||
ClutterInputDevice *pad,
|
||||
@ -1672,50 +1734,6 @@ meta_input_settings_emulate_keybinding (MetaInputSettings *input_settings,
|
||||
emulate_modifiers (priv->virtual_pad_keyboard, mods, state);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
ToolSettings *tool_settings;
|
||||
|
||||
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);
|
||||
|
||||
tool_settings = lookup_tool_settings (tool, current_tablet);
|
||||
pressure = calculate_bezier_position (pressure,
|
||||
tool_settings->curve[0],
|
||||
tool_settings->curve[1],
|
||||
tool_settings->curve[2],
|
||||
tool_settings->curve[3]);
|
||||
return pressure;
|
||||
}
|
||||
|
||||
gboolean
|
||||
meta_input_settings_is_pad_button_grabbed (MetaInputSettings *input_settings,
|
||||
ClutterInputDevice *pad,
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include "config.h"
|
||||
|
||||
#include <clutter/evdev/clutter-evdev.h>
|
||||
#include <linux/input-event-codes.h>
|
||||
#include <libinput.h>
|
||||
|
||||
#include "meta-input-settings-native.h"
|
||||
@ -395,6 +396,54 @@ meta_input_settings_native_set_tablet_area (MetaInputSettings *settings,
|
||||
/* FIXME: Implement */
|
||||
}
|
||||
|
||||
static void
|
||||
meta_input_settings_native_set_stylus_pressure (MetaInputSettings *settings,
|
||||
ClutterInputDevice *device,
|
||||
ClutterInputDeviceTool *tool,
|
||||
const gint curve[4])
|
||||
{
|
||||
gdouble pressure_curve[4];
|
||||
|
||||
pressure_curve[0] = (gdouble) curve[0] / 100;
|
||||
pressure_curve[1] = (gdouble) curve[1] / 100;
|
||||
pressure_curve[2] = (gdouble) curve[2] / 100;
|
||||
pressure_curve[3] = (gdouble) curve[3] / 100;
|
||||
|
||||
clutter_evdev_input_device_tool_set_pressure_curve (tool, pressure_curve);
|
||||
}
|
||||
|
||||
static guint
|
||||
action_to_evcode (GDesktopStylusButtonAction action)
|
||||
{
|
||||
switch (action)
|
||||
{
|
||||
case G_DESKTOP_STYLUS_BUTTON_ACTION_MIDDLE:
|
||||
return BTN_STYLUS;
|
||||
case G_DESKTOP_STYLUS_BUTTON_ACTION_RIGHT:
|
||||
return BTN_STYLUS2;
|
||||
case G_DESKTOP_STYLUS_BUTTON_ACTION_BACK:
|
||||
return BTN_BACK;
|
||||
case G_DESKTOP_STYLUS_BUTTON_ACTION_FORWARD:
|
||||
return BTN_FORWARD;
|
||||
case G_DESKTOP_STYLUS_BUTTON_ACTION_DEFAULT:
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
meta_input_settings_native_set_stylus_button_map (MetaInputSettings *settings,
|
||||
ClutterInputDevice *device,
|
||||
ClutterInputDeviceTool *tool,
|
||||
GDesktopStylusButtonAction primary,
|
||||
GDesktopStylusButtonAction secondary)
|
||||
{
|
||||
clutter_evdev_input_device_tool_set_button_code (tool, CLUTTER_BUTTON_MIDDLE,
|
||||
action_to_evcode (primary));
|
||||
clutter_evdev_input_device_tool_set_button_code (tool, CLUTTER_BUTTON_SECONDARY,
|
||||
action_to_evcode (secondary));
|
||||
}
|
||||
|
||||
static void
|
||||
meta_input_settings_native_class_init (MetaInputSettingsNativeClass *klass)
|
||||
{
|
||||
@ -418,6 +467,9 @@ meta_input_settings_native_class_init (MetaInputSettingsNativeClass *klass)
|
||||
|
||||
input_settings_class->set_mouse_accel_profile = meta_input_settings_native_set_mouse_accel_profile;
|
||||
input_settings_class->set_trackball_accel_profile = meta_input_settings_native_set_trackball_accel_profile;
|
||||
|
||||
input_settings_class->set_stylus_pressure = meta_input_settings_native_set_stylus_pressure;
|
||||
input_settings_class->set_stylus_button_map = meta_input_settings_native_set_stylus_button_map;
|
||||
}
|
||||
|
||||
static void
|
||||
|
Reference in New Issue
Block a user