input-settings: Wire up middle-emulation

This allows emulating middle click via simultaneous left and right
click.  Fixes #238.

https://gitlab.gnome.org/GNOME/mutter/merge_requests/256
This commit is contained in:
Andrew Gaul 2018-10-05 17:06:58 -07:00
parent 23da6c2426
commit 0487e6f11f
4 changed files with 172 additions and 0 deletions

View File

@ -114,6 +114,17 @@ struct _MetaInputSettingsClass
GDesktopStylusButtonAction primary,
GDesktopStylusButtonAction secondary,
GDesktopStylusButtonAction tertiary);
void (* set_mouse_middle_click_emulation) (MetaInputSettings *settings,
ClutterInputDevice *device,
gboolean enabled);
void (* set_touchpad_middle_click_emulation) (MetaInputSettings *settings,
ClutterInputDevice *device,
gboolean enabled);
void (* set_trackball_middle_click_emulation) (MetaInputSettings *settings,
ClutterInputDevice *device,
gboolean enabled);
gboolean (* has_two_finger_scroll) (MetaInputSettings *settings,
ClutterInputDevice *device);
gboolean (* is_trackball_device) (MetaInputSettings *settings,

View File

@ -418,6 +418,39 @@ get_settings_for_device_type (MetaInputSettings *input_settings,
}
}
static void
update_middle_click_emulation (MetaInputSettings *input_settings,
GSettings *settings,
ClutterInputDevice *device)
{
ConfigBoolFunc func;
const gchar *key = "emulate-middle";
MetaInputSettingsPrivate *priv = meta_input_settings_get_instance_private (input_settings);
if (!settings)
return;
if (settings == priv->mouse_settings)
func = META_INPUT_SETTINGS_GET_CLASS (input_settings)->set_mouse_middle_click_emulation;
else if (settings == priv->touchpad_settings)
func = META_INPUT_SETTINGS_GET_CLASS (input_settings)->set_touchpad_middle_click_emulation;
else if (settings == priv->trackball_settings)
func = META_INPUT_SETTINGS_GET_CLASS (input_settings)->set_trackball_middle_click_emulation;
else
return;
if (device)
{
settings_device_set_bool_setting (input_settings, device, func,
g_settings_get_boolean (settings, key));
}
else
{
settings_set_bool_setting (input_settings, CLUTTER_POINTER_DEVICE, func,
g_settings_get_boolean (settings, key));
}
}
static void
update_device_speed (MetaInputSettings *input_settings,
ClutterInputDevice *device)
@ -1141,6 +1174,8 @@ meta_input_settings_changed_cb (GSettings *settings,
update_device_natural_scroll (input_settings, NULL);
else if (strcmp (key, "accel-profile") == 0)
update_pointer_accel_profile (input_settings, settings, NULL);
else if (strcmp (key, "middle-click-emulation") == 0)
update_middle_click_emulation (input_settings, settings, NULL);
}
else if (settings == priv->touchpad_settings)
{
@ -1164,6 +1199,8 @@ meta_input_settings_changed_cb (GSettings *settings,
update_touchpad_two_finger_scroll (input_settings, NULL);
else if (strcmp (key, "click-method") == 0)
update_touchpad_click_method (input_settings, NULL);
else if (strcmp (key, "middle-click-emulation") == 0)
update_middle_click_emulation (input_settings, settings, NULL);
}
else if (settings == priv->trackball_settings)
{
@ -1171,6 +1208,8 @@ meta_input_settings_changed_cb (GSettings *settings,
update_trackball_scroll_button (input_settings, NULL);
else if (strcmp (key, "accel-profile") == 0)
update_pointer_accel_profile (input_settings, settings, NULL);
else if (strcmp (key, "middle-click-emulation") == 0)
update_middle_click_emulation (input_settings, settings, NULL);
}
else if (settings == priv->keyboard_settings)
{
@ -1687,6 +1726,10 @@ apply_device_settings (MetaInputSettings *input_settings,
device);
load_keyboard_a11y_settings (input_settings, device);
load_pointer_a11y_settings (input_settings, device);
update_middle_click_emulation (input_settings, priv->mouse_settings, device);
update_middle_click_emulation (input_settings, priv->touchpad_settings, device);
update_middle_click_emulation (input_settings, priv->trackball_settings, device);
}
static void

View File

@ -400,6 +400,13 @@ is_mouse_device (ClutterInputDevice *device)
!has_udev_property (device, "ID_INPUT_POINTINGSTICK"));
}
static gboolean
meta_input_settings_native_is_touchpad_device (MetaInputSettings *settings,
ClutterInputDevice *device)
{
return has_udev_property (device, "ID_INPUT_TOUCHPAD");
}
static gboolean
meta_input_settings_native_is_trackball_device (MetaInputSettings *settings,
ClutterInputDevice *device)
@ -562,6 +569,60 @@ meta_input_settings_native_set_stylus_button_map (MetaInputSettings *se
action_to_evcode (tertiary));
}
static void
meta_input_settings_native_set_mouse_middle_click_emulation (MetaInputSettings *settings,
ClutterInputDevice *device,
gboolean enabled)
{
struct libinput_device *libinput_device;
if (!is_mouse_device (device))
return;
libinput_device = meta_input_device_native_get_libinput_device (device);
if (!libinput_device)
return;
if (libinput_device_config_middle_emulation_is_available (libinput_device))
libinput_device_config_middle_emulation_set_enabled (libinput_device, enabled);
}
static void
meta_input_settings_native_set_touchpad_middle_click_emulation (MetaInputSettings *settings,
ClutterInputDevice *device,
gboolean enabled)
{
struct libinput_device *libinput_device;
if (!meta_input_settings_native_is_touchpad_device (settings, device))
return;
libinput_device = meta_input_device_native_get_libinput_device (device);
if (!libinput_device)
return;
if (libinput_device_config_middle_emulation_is_available (libinput_device))
libinput_device_config_middle_emulation_set_enabled (libinput_device, enabled);
}
static void
meta_input_settings_native_set_trackball_middle_click_emulation (MetaInputSettings *settings,
ClutterInputDevice *device,
gboolean enabled)
{
struct libinput_device *libinput_device;
if (!meta_input_settings_native_is_trackball_device (settings, device))
return;
libinput_device = meta_input_device_native_get_libinput_device (device);
if (!libinput_device)
return;
if (libinput_device_config_middle_emulation_is_available (libinput_device))
libinput_device_config_middle_emulation_set_enabled (libinput_device, enabled);
}
static void
meta_input_settings_native_class_init (MetaInputSettingsNativeClass *klass)
{
@ -591,6 +652,10 @@ meta_input_settings_native_class_init (MetaInputSettingsNativeClass *klass)
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;
input_settings_class->set_mouse_middle_click_emulation = meta_input_settings_native_set_mouse_middle_click_emulation;
input_settings_class->set_touchpad_middle_click_emulation = meta_input_settings_native_set_touchpad_middle_click_emulation;
input_settings_class->set_trackball_middle_click_emulation = meta_input_settings_native_set_trackball_middle_click_emulation;
input_settings_class->has_two_finger_scroll = meta_input_settings_native_has_two_finger_scroll;
input_settings_class->is_trackball_device = meta_input_settings_native_is_trackball_device;
}

View File

@ -512,6 +512,13 @@ is_mouse (MetaInputSettings *settings,
!has_udev_property (settings, device, "ID_INPUT_POINTINGSTICK"));
}
static gboolean
meta_input_settings_x11_is_touchpad_device (MetaInputSettings *settings,
ClutterInputDevice *device)
{
return has_udev_property (settings, device, "ID_INPUT_TOUCHPAD");
}
static gboolean
meta_input_settings_x11_is_trackball_device (MetaInputSettings *settings,
ClutterInputDevice *device)
@ -820,6 +827,48 @@ meta_input_settings_x11_set_stylus_button_map (MetaInputSettings *setti
}
}
static void
meta_input_settings_x11_set_mouse_middle_click_emulation (MetaInputSettings *settings,
ClutterInputDevice *device,
gboolean enabled)
{
guchar value = enabled ? 1 : 0;
if (!is_mouse (settings, device))
return;
change_property (device, "libinput Middle Click Emulation Enabled",
XA_INTEGER, 8, &value, 1);
}
static void
meta_input_settings_x11_set_touchpad_middle_click_emulation (MetaInputSettings *settings,
ClutterInputDevice *device,
gboolean enabled)
{
guchar value = enabled ? 1 : 0;
if (!meta_input_settings_x11_is_touchpad_device (settings, device))
return;
change_property (device, "libinput Middle Click Emulation Enabled",
XA_INTEGER, 8, &value, 1);
}
static void
meta_input_settings_x11_set_trackball_middle_click_emulation (MetaInputSettings *settings,
ClutterInputDevice *device,
gboolean enabled)
{
guchar value = enabled ? 1 : 0;
if (!meta_input_settings_x11_is_trackball_device (settings, device))
return;
change_property (device, "libinput Middle Click Emulation Enabled",
XA_INTEGER, 8, &value, 1);
}
static void
meta_input_settings_x11_set_stylus_pressure (MetaInputSettings *settings,
ClutterInputDevice *device,
@ -864,6 +913,10 @@ meta_input_settings_x11_class_init (MetaInputSettingsX11Class *klass)
input_settings_class->set_stylus_pressure = meta_input_settings_x11_set_stylus_pressure;
input_settings_class->set_stylus_button_map = meta_input_settings_x11_set_stylus_button_map;
input_settings_class->set_mouse_middle_click_emulation = meta_input_settings_x11_set_mouse_middle_click_emulation;
input_settings_class->set_touchpad_middle_click_emulation = meta_input_settings_x11_set_touchpad_middle_click_emulation;
input_settings_class->set_trackball_middle_click_emulation = meta_input_settings_x11_set_trackball_middle_click_emulation;
input_settings_class->has_two_finger_scroll = meta_input_settings_x11_has_two_finger_scroll;
input_settings_class->is_trackball_device = meta_input_settings_x11_is_trackball_device;
}