backends/x11: Support plain old X device configuration

We re-use part of the code added to support synaptics and add a few
bits specific for xorg-x11-drv-evdev devices.
This commit is contained in:
Rui Matos 2017-10-10 19:07:27 +02:00 committed by Ray Strode
parent b0067b45b9
commit d720a0a366

View File

@ -179,35 +179,35 @@ is_device_synaptics (ClutterInputDevice *device)
return TRUE; return TRUE;
} }
static gboolean
is_device_libinput (ClutterInputDevice *device)
{
guchar *has_setting;
/* We just need looking for a synaptics-specific property */
has_setting = get_property (device, "libinput Send Events Modes Available", XA_INTEGER, 8, 2);
if (!has_setting)
return FALSE;
meta_XFree (has_setting);
return TRUE;
}
static void static void
change_synaptics_tap_left_handed (ClutterInputDevice *device, change_x_device_left_handed (ClutterInputDevice *device,
gboolean tap_enabled, gboolean left_handed)
gboolean left_handed)
{ {
MetaDisplay *display = meta_get_display (); MetaDisplay *display = meta_get_display ();
MetaBackend *backend = meta_get_backend (); MetaBackend *backend = meta_get_backend ();
Display *xdisplay = meta_backend_x11_get_xdisplay (META_BACKEND_X11 (backend)); Display *xdisplay = meta_backend_x11_get_xdisplay (META_BACKEND_X11 (backend));
XDevice *xdevice; XDevice *xdevice;
guchar *tap_action, *buttons; guchar *buttons;
guint buttons_capacity = 16, n_buttons; guint buttons_capacity = 16, n_buttons;
xdevice = XOpenDevice(xdisplay, clutter_input_device_get_device_id (device)); xdevice = XOpenDevice(xdisplay, clutter_input_device_get_device_id (device));
if (!xdevice) if (!xdevice)
return; return;
tap_action = get_property (device, "Synaptics Tap Action",
XA_INTEGER, 8, 7);
if (!tap_action)
goto out;
tap_action[4] = tap_enabled ? (left_handed ? 3 : 1) : 0;
tap_action[5] = tap_enabled ? (left_handed ? 1 : 3) : 0;
tap_action[6] = tap_enabled ? 2 : 0;
change_property (device, "Synaptics Tap Action",
XA_INTEGER, 8, tap_action, 7);
meta_XFree (tap_action);
if (display) if (display)
meta_error_trap_push (display); meta_error_trap_push (display);
buttons = g_new (guchar, buttons_capacity); buttons = g_new (guchar, buttons_capacity);
@ -231,17 +231,39 @@ change_synaptics_tap_left_handed (ClutterInputDevice *device,
if (display && meta_error_trap_pop_with_return (display)) if (display && meta_error_trap_pop_with_return (display))
{ {
g_warning ("Could not set synaptics touchpad left-handed for %s", g_warning ("Could not set left-handed for %s",
clutter_input_device_get_device_name (device)); clutter_input_device_get_device_name (device));
} }
out:
XCloseDevice (xdisplay, xdevice); XCloseDevice (xdisplay, xdevice);
} }
static void static void
change_synaptics_speed (ClutterInputDevice *device, change_synaptics_tap_left_handed (ClutterInputDevice *device,
gdouble speed) gboolean tap_enabled,
gboolean left_handed)
{
guchar *tap_action;
tap_action = get_property (device, "Synaptics Tap Action",
XA_INTEGER, 8, 7);
if (!tap_action)
return;
tap_action[4] = tap_enabled ? (left_handed ? 3 : 1) : 0;
tap_action[5] = tap_enabled ? (left_handed ? 1 : 3) : 0;
tap_action[6] = tap_enabled ? 2 : 0;
change_property (device, "Synaptics Tap Action",
XA_INTEGER, 8, tap_action, 7);
meta_XFree (tap_action);
change_x_device_left_handed (device, left_handed);
}
static void
change_x_device_speed (ClutterInputDevice *device,
gdouble speed)
{ {
MetaDisplay *display = meta_get_display (); MetaDisplay *display = meta_get_display ();
MetaBackend *backend = meta_get_backend (); MetaBackend *backend = meta_get_backend ();
@ -337,6 +359,23 @@ change_synaptics_speed (ClutterInputDevice *device,
XCloseDevice (xdisplay, xdevice); XCloseDevice (xdisplay, xdevice);
} }
static void
change_x_device_scroll_button (ClutterInputDevice *device,
guint button)
{
guchar value;
value = button > 0 ? 1 : 0;
change_property (device, "Evdev Wheel Emulation",
XA_INTEGER, 8, &value, 1);
if (button > 0)
{
value = button;
change_property (device, "Evdev Wheel Emulation Button",
XA_INTEGER, 8, &value, 1);
}
}
/* Ensure that syndaemon dies together with us, to avoid running several of /* Ensure that syndaemon dies together with us, to avoid running several of
* them */ * them */
static void static void
@ -505,9 +544,10 @@ meta_input_settings_x11_set_speed (MetaInputSettings *settings,
Display *xdisplay = meta_backend_x11_get_xdisplay (META_BACKEND_X11 (backend)); Display *xdisplay = meta_backend_x11_get_xdisplay (META_BACKEND_X11 (backend));
gfloat value = speed; gfloat value = speed;
if (is_device_synaptics (device)) if (is_device_synaptics (device) ||
!is_device_libinput (device))
{ {
change_synaptics_speed (device, speed); change_x_device_speed (device, speed);
return; return;
} }
@ -549,6 +589,11 @@ meta_input_settings_x11_set_left_handed (MetaInputSettings *settings,
g_object_unref (settings); g_object_unref (settings);
return; return;
} }
else if (!is_device_libinput (device))
{
change_x_device_left_handed (device, enabled);
return;
}
change_property (device, "libinput Left Handed Enabled", change_property (device, "libinput Left Handed Enabled",
XA_INTEGER, 8, &value, 1); XA_INTEGER, 8, &value, 1);
@ -762,6 +807,12 @@ meta_input_settings_x11_set_scroll_button (MetaInputSettings *settings,
ClutterInputDevice *device, ClutterInputDevice *device,
guint button) guint button)
{ {
if (!is_device_libinput (device))
{
change_x_device_scroll_button (device, button);
return;
}
change_property (device, "libinput Button Scrolling Button", change_property (device, "libinput Button Scrolling Button",
XA_INTEGER, 32, &button, 1); XA_INTEGER, 32, &button, 1);
} }