backends: Make device tracking at MetaInputSettings ad-hoc API

Depending on the backend, we want to integrate this object at different
levels. It will sit close to the MetaBackendX11/MetaSeatX11 in X11, but
it will be put deep down with MetaSeatImpl in the native backend, in a
separate thread.

Since we can't depend on a single object type, nor are able to track
ClutterSeat signals neatly, make this API something to be called
explicitly by backends.

https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1403
This commit is contained in:
Carlos Garnacho 2020-08-11 16:27:35 +02:00
parent e324f0fad0
commit 5a1c7e4a54
5 changed files with 55 additions and 33 deletions

View File

@ -208,4 +208,15 @@ void meta_input_settings_set_device_aspect_ratio (MetaInputSettings *input_sett
void meta_input_settings_get_kbd_a11y_settings (MetaInputSettings *input_settings, void meta_input_settings_get_kbd_a11y_settings (MetaInputSettings *input_settings,
MetaKbdA11ySettings *a11y_settings); MetaKbdA11ySettings *a11y_settings);
void meta_input_settings_add_device (MetaInputSettings *input_settings,
ClutterInputDevice *device);
void meta_input_settings_remove_device (MetaInputSettings *input_settings,
ClutterInputDevice *device);
void meta_input_settings_notify_tool_change (MetaInputSettings *input_settings,
ClutterInputDevice *device,
ClutterInputDeviceTool *tool);
void meta_input_settings_notify_kbd_a11y_change (MetaInputSettings *input_settings,
MetaKeyboardA11yFlags new_flags,
MetaKeyboardA11yFlags what_changed);
#endif /* META_INPUT_SETTINGS_PRIVATE_H */ #endif /* META_INPUT_SETTINGS_PRIVATE_H */

View File

@ -1204,11 +1204,10 @@ load_keyboard_a11y_settings (MetaInputSettings *input_settings)
g_signal_emit (input_settings, signals[KBD_A11Y_CHANGED], 0, &priv->kbd_a11y_settings); g_signal_emit (input_settings, signals[KBD_A11Y_CHANGED], 0, &priv->kbd_a11y_settings);
} }
static void void
on_keyboard_a11y_settings_changed (ClutterSeat *seat, meta_input_settings_notify_kbd_a11y_change (MetaInputSettings *input_settings,
MetaKeyboardA11yFlags new_flags, MetaKeyboardA11yFlags new_flags,
MetaKeyboardA11yFlags what_changed, MetaKeyboardA11yFlags what_changed)
MetaInputSettings *input_settings)
{ {
MetaInputSettingsPrivate *priv = meta_input_settings_get_instance_private (input_settings); MetaInputSettingsPrivate *priv = meta_input_settings_get_instance_private (input_settings);
guint i; guint i;
@ -1580,10 +1579,9 @@ evaluate_two_finger_scrolling (MetaInputSettings *input_settings,
g_hash_table_add (priv->two_finger_devices, device); g_hash_table_add (priv->two_finger_devices, device);
} }
static void void
meta_input_settings_device_added (ClutterSeat *seat, meta_input_settings_add_device (MetaInputSettings *input_settings,
ClutterInputDevice *device, ClutterInputDevice *device)
MetaInputSettings *input_settings)
{ {
if (clutter_input_device_get_device_mode (device) == CLUTTER_INPUT_MODE_MASTER) if (clutter_input_device_get_device_mode (device) == CLUTTER_INPUT_MODE_MASTER)
return; return;
@ -1594,10 +1592,9 @@ meta_input_settings_device_added (ClutterSeat *seat,
check_add_mappable_device (input_settings, device); check_add_mappable_device (input_settings, device);
} }
static void void
meta_input_settings_device_removed (ClutterSeat *seat, meta_input_settings_remove_device (MetaInputSettings *input_settings,
ClutterInputDevice *device, ClutterInputDevice *device)
MetaInputSettings *input_settings)
{ {
MetaInputSettingsPrivate *priv; MetaInputSettingsPrivate *priv;
@ -1646,11 +1643,10 @@ current_tool_info_free (CurrentToolInfo *info)
g_free (info); g_free (info);
} }
static void void
meta_input_settings_tool_changed (ClutterSeat *seat, meta_input_settings_notify_tool_change (MetaInputSettings *input_settings,
ClutterInputDevice *device, ClutterInputDevice *device,
ClutterInputDeviceTool *tool, ClutterInputDeviceTool *tool)
MetaInputSettings *input_settings)
{ {
MetaInputSettingsPrivate *priv; MetaInputSettingsPrivate *priv;
@ -1739,12 +1735,6 @@ meta_input_settings_init (MetaInputSettings *settings)
priv = meta_input_settings_get_instance_private (settings); priv = meta_input_settings_get_instance_private (settings);
priv->seat = clutter_backend_get_default_seat (clutter_get_default_backend ()); priv->seat = clutter_backend_get_default_seat (clutter_get_default_backend ());
g_signal_connect (priv->seat, "device-added",
G_CALLBACK (meta_input_settings_device_added), settings);
g_signal_connect (priv->seat, "device-removed",
G_CALLBACK (meta_input_settings_device_removed), settings);
g_signal_connect (priv->seat, "tool-changed",
G_CALLBACK (meta_input_settings_tool_changed), settings);
priv->mouse_settings = g_settings_new ("org.gnome.desktop.peripherals.mouse"); priv->mouse_settings = g_settings_new ("org.gnome.desktop.peripherals.mouse");
g_signal_connect (priv->mouse_settings, "changed", g_signal_connect (priv->mouse_settings, "changed",
@ -1771,8 +1761,6 @@ meta_input_settings_init (MetaInputSettings *settings)
priv->keyboard_a11y_settings = g_settings_new ("org.gnome.desktop.a11y.keyboard"); priv->keyboard_a11y_settings = g_settings_new ("org.gnome.desktop.a11y.keyboard");
g_signal_connect (priv->keyboard_a11y_settings, "changed", g_signal_connect (priv->keyboard_a11y_settings, "changed",
G_CALLBACK (meta_input_keyboard_a11y_settings_changed), settings); G_CALLBACK (meta_input_keyboard_a11y_settings_changed), settings);
g_signal_connect (priv->seat, "kbd-a11y-flags-changed",
G_CALLBACK (on_keyboard_a11y_settings_changed), settings);
priv->mouse_a11y_settings = g_settings_new ("org.gnome.desktop.a11y.mouse"); priv->mouse_a11y_settings = g_settings_new ("org.gnome.desktop.a11y.mouse");
g_signal_connect (priv->mouse_a11y_settings, "changed", g_signal_connect (priv->mouse_a11y_settings, "changed",

View File

@ -1530,6 +1530,9 @@ process_base_event (MetaSeatImpl *seat,
ClutterInputDevice *device; ClutterInputDevice *device;
ClutterEvent *device_event; ClutterEvent *device_event;
struct libinput_device *libinput_device; struct libinput_device *libinput_device;
MetaInputSettings *input_settings;
input_settings = meta_backend_get_input_settings (meta_get_backend ());
switch (libinput_event_get_type (event)) switch (libinput_event_get_type (event))
{ {
@ -1539,6 +1542,7 @@ process_base_event (MetaSeatImpl *seat,
device = evdev_add_device (seat, libinput_device); device = evdev_add_device (seat, libinput_device);
device_event = clutter_event_new (CLUTTER_DEVICE_ADDED); device_event = clutter_event_new (CLUTTER_DEVICE_ADDED);
clutter_event_set_device (device_event, device); clutter_event_set_device (device_event, device);
meta_input_settings_add_device (input_settings, device);
break; break;
case LIBINPUT_EVENT_DEVICE_REMOVED: case LIBINPUT_EVENT_DEVICE_REMOVED:
@ -1549,6 +1553,7 @@ process_base_event (MetaSeatImpl *seat,
clutter_event_set_device (device_event, device); clutter_event_set_device (device_event, device);
evdev_remove_device (seat, evdev_remove_device (seat,
META_INPUT_DEVICE_NATIVE (device)); META_INPUT_DEVICE_NATIVE (device));
meta_input_settings_remove_device (input_settings, device);
break; break;
default: default:
@ -1613,9 +1618,9 @@ input_device_update_tool (ClutterInputDevice *input_device,
struct libinput_tablet_tool *libinput_tool) struct libinput_tablet_tool *libinput_tool)
{ {
MetaInputDeviceNative *evdev_device = META_INPUT_DEVICE_NATIVE (input_device); MetaInputDeviceNative *evdev_device = META_INPUT_DEVICE_NATIVE (input_device);
MetaSeatImpl *seat = seat_from_device (input_device);
ClutterInputDeviceTool *tool = NULL; ClutterInputDeviceTool *tool = NULL;
ClutterInputDeviceToolType tool_type; ClutterInputDeviceToolType tool_type;
MetaInputSettings *input_settings;
uint64_t tool_serial; uint64_t tool_serial;
if (libinput_tool) if (libinput_tool)
@ -1636,7 +1641,8 @@ input_device_update_tool (ClutterInputDevice *input_device,
if (evdev_device->last_tool != tool) if (evdev_device->last_tool != tool)
{ {
evdev_device->last_tool = tool; evdev_device->last_tool = tool;
g_signal_emit_by_name (seat->seat, "tool-changed", input_device, tool); input_settings = meta_backend_get_input_settings (meta_get_backend ());
meta_input_settings_notify_tool_change (input_settings, input_device, tool);
} }
} }
@ -3118,6 +3124,11 @@ meta_seat_impl_notify_kbd_a11y_flags_changed (MetaSeatImpl *impl,
MetaKeyboardA11yFlags new_flags, MetaKeyboardA11yFlags new_flags,
MetaKeyboardA11yFlags what_changed) MetaKeyboardA11yFlags what_changed)
{ {
MetaInputSettings *input_settings;
input_settings = meta_backend_get_input_settings (meta_get_backend ());
meta_input_settings_notify_kbd_a11y_change (input_settings,
new_flags, what_changed);
g_signal_emit (impl, signals[KBD_A11Y_FLAGS_CHANGED], 0, g_signal_emit (impl, signals[KBD_A11Y_FLAGS_CHANGED], 0,
new_flags, what_changed); new_flags, what_changed);
} }

View File

@ -20,6 +20,7 @@
#include <X11/extensions/XInput2.h> #include <X11/extensions/XInput2.h>
#include "backends/meta-input-settings-private.h"
#include "backends/x11/meta-backend-x11.h" #include "backends/x11/meta-backend-x11.h"
#include "backends/x11/meta-event-x11.h" #include "backends/x11/meta-event-x11.h"
#include "backends/x11/meta-input-device-tool-x11.h" #include "backends/x11/meta-input-device-tool-x11.h"
@ -724,19 +725,23 @@ meta_seat_x11_handle_event_post (ClutterSeat *seat,
{ {
MetaSeatX11 *seat_x11 = META_SEAT_X11 (seat); MetaSeatX11 *seat_x11 = META_SEAT_X11 (seat);
ClutterInputDevice *device = event->device.device; ClutterInputDevice *device = event->device.device;
MetaInputSettings *input_settings;
gboolean is_touch; gboolean is_touch;
is_touch = is_touch =
clutter_input_device_get_device_type (device) == CLUTTER_TOUCHSCREEN_DEVICE; clutter_input_device_get_device_type (device) == CLUTTER_TOUCHSCREEN_DEVICE;
input_settings = meta_backend_get_input_settings (meta_get_backend ());
switch (event->type) switch (event->type)
{ {
case CLUTTER_DEVICE_ADDED: case CLUTTER_DEVICE_ADDED:
meta_input_settings_add_device (input_settings, device);
seat_x11->has_touchscreens |= is_touch; seat_x11->has_touchscreens |= is_touch;
break; break;
case CLUTTER_DEVICE_REMOVED: case CLUTTER_DEVICE_REMOVED:
if (is_touch) if (is_touch)
seat_x11->has_touchscreens = has_touchscreens (seat_x11); seat_x11->has_touchscreens = has_touchscreens (seat_x11);
meta_input_settings_remove_device (input_settings, device);
break; break;
default: default:
break; break;
@ -933,6 +938,7 @@ translate_property_event (MetaSeatX11 *seat_x11,
{ {
ClutterInputDeviceTool *tool = NULL; ClutterInputDeviceTool *tool = NULL;
ClutterInputDeviceToolType type; ClutterInputDeviceToolType type;
MetaInputSettings *input_settings;
int serial_id; int serial_id;
serial_id = device_get_tool_serial (device); serial_id = device_get_tool_serial (device);
@ -953,7 +959,8 @@ translate_property_event (MetaSeatX11 *seat_x11,
} }
meta_input_device_x11_update_tool (device, tool); meta_input_device_x11_update_tool (device, tool);
g_signal_emit_by_name (seat_x11, "tool-changed", device, tool); input_settings = meta_backend_get_input_settings (meta_get_backend ());
meta_input_settings_notify_tool_change (input_settings, device, tool);
} }
} }

View File

@ -118,10 +118,15 @@ check_settings_changed (ClutterSeat *seat)
} }
if (what_changed) if (what_changed)
{
meta_input_settings_notify_kbd_a11y_change (input_settings,
kbd_a11y_settings.controls,
what_changed);
g_signal_emit_by_name (seat, g_signal_emit_by_name (seat,
"kbd-a11y-flags-changed", "kbd-a11y-flags-changed",
kbd_a11y_settings.controls, kbd_a11y_settings.controls,
what_changed); what_changed);
}
XkbFreeKeyboard (desc, XkbAllComponentsMask, TRUE); XkbFreeKeyboard (desc, XkbAllComponentsMask, TRUE);
} }