mutter/0025-input-settings-Wire-up-middle-emulation.patch

292 lines
13 KiB
Diff
Raw Normal View History

From 0487e6f11fc9231214c03bd8eb5050a7e04a621d Mon Sep 17 00:00:00 2001
From: Andrew Gaul <andrew@gaul.org>
Date: Fri, 5 Oct 2018 17:06:58 -0700
Subject: [PATCH 25/48] 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
---
src/backends/meta-input-settings-private.h | 11 ++++
src/backends/meta-input-settings.c | 43 ++++++++++++
.../native/meta-input-settings-native.c | 65 +++++++++++++++++++
src/backends/x11/meta-input-settings-x11.c | 53 +++++++++++++++
4 files changed, 172 insertions(+)
diff --git a/src/backends/meta-input-settings-private.h b/src/backends/meta-input-settings-private.h
index a035db78f..135b17f1a 100644
--- a/src/backends/meta-input-settings-private.h
+++ b/src/backends/meta-input-settings-private.h
@@ -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,
diff --git a/src/backends/meta-input-settings.c b/src/backends/meta-input-settings.c
index 08762ac72..67dfd82b2 100644
--- a/src/backends/meta-input-settings.c
+++ b/src/backends/meta-input-settings.c
@@ -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
diff --git a/src/backends/native/meta-input-settings-native.c b/src/backends/native/meta-input-settings-native.c
index eb06911bf..fe82e8d1f 100644
--- a/src/backends/native/meta-input-settings-native.c
+++ b/src/backends/native/meta-input-settings-native.c
@@ -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;
}
diff --git a/src/backends/x11/meta-input-settings-x11.c b/src/backends/x11/meta-input-settings-x11.c
index 05f932420..a9658e702 100644
--- a/src/backends/x11/meta-input-settings-x11.c
+++ b/src/backends/x11/meta-input-settings-x11.c
@@ -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;
}
--
2.26.0.rc2