backends/native: Move MetaInputSettings ownership to MetaSeatImpl

Together with keymaps and devices, MetaInputSettings will live in the
ninth circle of hell with MetaSeatImpl, forever tied to it.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1403>
This commit is contained in:
Carlos Garnacho 2020-08-11 18:33:07 +02:00 committed by Marge Bot
parent 4e56352bcc
commit 1609d1459e
7 changed files with 188 additions and 35 deletions

View File

@ -111,6 +111,15 @@ enum
static guint signals[N_SIGNALS] = { 0 };
enum
{
PROP_0,
PROP_SEAT,
N_PROPS,
};
static GParamSpec *props[N_PROPS] = { 0 };
static GSList *
meta_input_settings_get_devices (MetaInputSettings *settings,
ClutterInputDeviceType type)
@ -152,10 +161,53 @@ meta_input_settings_dispose (GObject *object)
g_clear_pointer (&priv->current_tools, g_hash_table_unref);
g_clear_pointer (&priv->two_finger_devices, g_hash_table_destroy);
g_clear_object (&priv->seat);
G_OBJECT_CLASS (meta_input_settings_parent_class)->dispose (object);
}
static void
meta_input_settings_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
MetaInputSettings *input_settings = META_INPUT_SETTINGS (object);
MetaInputSettingsPrivate *priv =
meta_input_settings_get_instance_private (input_settings);
switch (prop_id)
{
case PROP_SEAT:
priv->seat = g_value_get_object (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
meta_input_settings_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
MetaInputSettings *input_settings = META_INPUT_SETTINGS (object);
MetaInputSettingsPrivate *priv =
meta_input_settings_get_instance_private (input_settings);
switch (prop_id)
{
case PROP_SEAT:
g_value_set_object (value, priv->seat);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
settings_device_set_bool_setting (MetaInputSettings *input_settings,
ClutterInputDevice *device,
@ -1714,6 +1766,8 @@ meta_input_settings_class_init (MetaInputSettingsClass *klass)
object_class->dispose = meta_input_settings_dispose;
object_class->constructed = meta_input_settings_constructed;
object_class->set_property = meta_input_settings_set_property;
object_class->get_property = meta_input_settings_get_property;
quark_tool_settings =
g_quark_from_static_string ("meta-input-settings-tool-settings");
@ -1725,6 +1779,16 @@ meta_input_settings_class_init (MetaInputSettingsClass *klass)
0, NULL, NULL, NULL,
G_TYPE_NONE, 1,
G_TYPE_POINTER);
props[PROP_SEAT] =
g_param_spec_object ("seat",
"Seat",
"Seat",
CLUTTER_TYPE_SEAT,
CLUTTER_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY);
g_object_class_install_properties (object_class, N_PROPS, props);
}
static void
@ -1733,7 +1797,6 @@ meta_input_settings_init (MetaInputSettings *settings)
MetaInputSettingsPrivate *priv;
priv = meta_input_settings_get_instance_private (settings);
priv->seat = clutter_backend_get_default_seat (clutter_get_default_backend ());
priv->mouse_settings = g_settings_new ("org.gnome.desktop.peripherals.mouse");
g_signal_connect (priv->mouse_settings, "changed",

View File

@ -163,13 +163,36 @@ update_viewports (MetaBackend *backend)
g_object_unref (viewports);
}
static void
kbd_a11y_changed_cb (MetaInputSettings *input_settings,
MetaKbdA11ySettings *a11y_settings,
MetaBackend *backend)
{
ClutterBackend *clutter_backend = meta_backend_get_clutter_backend (backend);
ClutterSeat *seat = clutter_backend_get_default_seat (clutter_backend);
ClutterInputDevice *device;
device = clutter_seat_get_keyboard (seat);
if (device)
meta_input_device_native_apply_kbd_a11y_settings (META_INPUT_DEVICE_NATIVE (device),
a11y_settings);
}
static void
meta_backend_native_post_init (MetaBackend *backend)
{
MetaBackendNative *backend_native = META_BACKEND_NATIVE (backend);
MetaSettings *settings = meta_backend_get_settings (backend);
ClutterBackend *clutter_backend = meta_backend_get_clutter_backend (backend);
MetaSeatNative *seat =
META_SEAT_NATIVE (clutter_backend_get_default_seat (clutter_backend));
META_BACKEND_CLASS (meta_backend_native_parent_class)->post_init (backend);
backend_native->input_settings = meta_seat_impl_get_input_settings (seat->impl);
g_signal_connect_object (backend_native->input_settings, "kbd-a11y-changed",
G_CALLBACK (kbd_a11y_changed_cb), backend, 0);
if (meta_settings_is_experimental_feature_enabled (settings,
META_EXPERIMENTAL_FEATURE_RT_SCHEDULER))
{
@ -235,34 +258,11 @@ meta_backend_native_create_renderer (MetaBackend *backend,
return META_RENDERER (renderer_native);
}
static void
kbd_a11y_changed_cb (MetaInputSettings *input_settings,
MetaKbdA11ySettings *a11y_settings,
MetaBackend *backend)
{
ClutterBackend *clutter_backend = meta_backend_get_clutter_backend (backend);
ClutterSeat *seat = clutter_backend_get_default_seat (clutter_backend);
ClutterInputDevice *device;
device = clutter_seat_get_keyboard (seat);
if (device)
meta_input_device_native_apply_kbd_a11y_settings (META_INPUT_DEVICE_NATIVE (device),
a11y_settings);
}
static MetaInputSettings *
meta_backend_native_create_input_settings (MetaBackend *backend)
{
MetaBackendNative *backend_native = META_BACKEND_NATIVE (backend);
if (!backend_native->input_settings)
{
backend_native->input_settings =
g_object_new (META_TYPE_INPUT_SETTINGS_NATIVE, NULL);
g_signal_connect_object (backend_native->input_settings, "kbd-a11y-changed",
G_CALLBACK (kbd_a11y_changed_cb), backend, 0);
}
return backend_native->input_settings;
}

View File

@ -239,10 +239,11 @@ clear_slow_keys (MetaInputDeviceNative *device)
static guint
get_slow_keys_delay (ClutterInputDevice *device)
{
MetaInputDeviceNative *device_native = META_INPUT_DEVICE_NATIVE (device);
MetaKbdA11ySettings a11y_settings;
MetaInputSettings *input_settings;
input_settings = meta_backend_get_input_settings (meta_get_backend ());
input_settings = meta_seat_impl_get_input_settings (device_native->seat_impl);
meta_input_settings_get_kbd_a11y_settings (input_settings, &a11y_settings);
/* Settings use int, we use uint, make sure we dont go negative */
return MAX (0, a11y_settings.slowkeys_delay);
@ -335,10 +336,11 @@ stop_slow_keys (ClutterEvent *event,
static guint
get_debounce_delay (ClutterInputDevice *device)
{
MetaInputDeviceNative *device_native = META_INPUT_DEVICE_NATIVE (device);
MetaKbdA11ySettings a11y_settings;
MetaInputSettings *input_settings;
input_settings = meta_backend_get_input_settings (meta_get_backend ());
input_settings = meta_seat_impl_get_input_settings (device_native->seat_impl);
meta_input_settings_get_kbd_a11y_settings (input_settings, &a11y_settings);
/* Settings use int, we use uint, make sure we dont go negative */
return MAX (0, a11y_settings.debounce_delay);

View File

@ -33,6 +33,55 @@
G_DEFINE_TYPE (MetaInputSettingsNative, meta_input_settings_native, META_TYPE_INPUT_SETTINGS)
enum
{
PROP_0,
PROP_SEAT_IMPL,
N_PROPS,
};
static GParamSpec *props[N_PROPS] = { 0 };
static void
meta_input_settings_native_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
MetaInputSettingsNative *input_settings_native =
META_INPUT_SETTINGS_NATIVE (object);
switch (prop_id)
{
case PROP_SEAT_IMPL:
input_settings_native->seat_impl = g_value_get_object (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
meta_input_settings_native_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
MetaInputSettingsNative *input_settings_native =
META_INPUT_SETTINGS_NATIVE (object);
switch (prop_id)
{
case PROP_SEAT_IMPL:
g_value_set_object (value, input_settings_native->seat_impl);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
meta_input_settings_native_set_send_events (MetaInputSettings *settings,
ClutterInputDevice *device,
@ -409,10 +458,10 @@ meta_input_settings_native_set_keyboard_repeat (MetaInputSettings *settings,
guint delay,
guint interval)
{
ClutterSeat *seat;
MetaInputSettingsNative *input_settings_native;
seat = clutter_backend_get_default_seat (clutter_get_default_backend ());
meta_seat_impl_set_keyboard_repeat (META_SEAT_NATIVE (seat)->impl,
input_settings_native = META_INPUT_SETTINGS_NATIVE (settings);
meta_seat_impl_set_keyboard_repeat (input_settings_native->seat_impl,
enabled, delay, interval);
}
@ -698,6 +747,10 @@ static void
meta_input_settings_native_class_init (MetaInputSettingsNativeClass *klass)
{
MetaInputSettingsClass *input_settings_class = META_INPUT_SETTINGS_CLASS (klass);
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->set_property = meta_input_settings_native_set_property;
object_class->get_property = meta_input_settings_native_get_property;
input_settings_class->set_send_events = meta_input_settings_native_set_send_events;
input_settings_class->set_matrix = meta_input_settings_native_set_matrix;
@ -732,9 +785,28 @@ meta_input_settings_native_class_init (MetaInputSettingsNativeClass *klass)
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;
props[PROP_SEAT_IMPL] =
g_param_spec_object ("seat-impl",
"Seat Impl",
"Seat Impl",
META_TYPE_SEAT_IMPL,
CLUTTER_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY);
g_object_class_install_properties (object_class, N_PROPS, props);
}
static void
meta_input_settings_native_init (MetaInputSettingsNative *settings)
{
}
MetaInputSettings *
meta_input_settings_native_new (MetaSeatImpl *seat_impl)
{
return g_object_new (META_TYPE_INPUT_SETTINGS_NATIVE,
"seat-impl", seat_impl,
"seat", seat_impl->seat_native,
NULL);
}

View File

@ -37,6 +37,7 @@ typedef struct _MetaInputSettingsNativeClass MetaInputSettingsNativeClass;
struct _MetaInputSettingsNative
{
MetaInputSettings parent_instance;
MetaSeatImpl *seat_impl;
};
struct _MetaInputSettingsNativeClass
@ -46,4 +47,6 @@ struct _MetaInputSettingsNativeClass
GType meta_input_settings_native_get_type (void) G_GNUC_CONST;
MetaInputSettings * meta_input_settings_native_new (MetaSeatImpl *seat_impl);
#endif /* META_INPUT_SETTINGS_NATIVE_H */

View File

@ -40,6 +40,7 @@
#include "backends/native/meta-event-native.h"
#include "backends/native/meta-input-device-native.h"
#include "backends/native/meta-input-device-tool-native.h"
#include "backends/native/meta-input-settings-native.h"
#include "backends/native/meta-keymap-native.h"
#include "backends/native/meta-virtual-input-device-native.h"
#include "clutter/clutter-mutter.h"
@ -1553,7 +1554,7 @@ process_base_event (MetaSeatImpl *seat_impl,
struct libinput_device *libinput_device;
MetaInputSettings *input_settings;
input_settings = meta_backend_get_input_settings (meta_get_backend ());
input_settings = seat_impl->input_settings;
switch (libinput_event_get_type (event))
{
@ -1635,7 +1636,8 @@ translate_tool_type (struct libinput_tablet_tool *libinput_tool)
}
static void
input_device_update_tool (ClutterInputDevice *input_device,
input_device_update_tool (MetaSeatImpl *seat_impl,
ClutterInputDevice *input_device,
struct libinput_tablet_tool *libinput_tool)
{
MetaInputDeviceNative *evdev_device = META_INPUT_DEVICE_NATIVE (input_device);
@ -1665,7 +1667,7 @@ input_device_update_tool (ClutterInputDevice *input_device,
clutter_input_device_update_from_tool (input_device, tool);
evdev_device->last_tool = tool;
input_settings = meta_backend_get_input_settings (meta_get_backend ());
input_settings = seat_impl->input_settings;
meta_input_settings_notify_tool_change (input_settings, input_device, tool);
}
}
@ -2239,10 +2241,10 @@ process_device_event (MetaSeatImpl *seat_impl,
libinput_tool = libinput_event_tablet_tool_get_tool (tablet_event);
if (in)
input_device_update_tool (device, libinput_tool);
input_device_update_tool (seat_impl, device, libinput_tool);
notify_proximity (device, time, in);
if (!in)
input_device_update_tool (device, NULL);
input_device_update_tool (seat_impl, device, NULL);
break;
}
@ -2496,6 +2498,8 @@ meta_seat_impl_constructed (GObject *object)
udev_unref (udev);
seat_impl->input_settings = meta_input_settings_native_new (seat_impl);
seat_impl->udev_client = g_udev_client_new ((const char *[]) { "input", NULL });
source = meta_event_source_new (seat_impl);
@ -3082,7 +3086,7 @@ meta_seat_impl_notify_kbd_a11y_flags_changed (MetaSeatImpl *seat_impl,
{
MetaInputSettings *input_settings;
input_settings = meta_backend_get_input_settings (meta_get_backend ());
input_settings = seat_impl->input_settings;
meta_input_settings_notify_kbd_a11y_change (input_settings,
new_flags, what_changed);
g_signal_emit (seat_impl, signals[KBD_A11Y_FLAGS_CHANGED], 0,
@ -3103,3 +3107,9 @@ meta_seat_impl_notify_bell (MetaSeatImpl *seat_impl)
{
g_signal_emit (seat_impl, signals[BELL], 0);
}
MetaInputSettings *
meta_seat_impl_get_input_settings (MetaSeatImpl *seat_impl)
{
return seat_impl->input_settings;
}

View File

@ -79,6 +79,7 @@ struct _MetaSeatImpl
MetaPointerConstraintImpl *pointer_constraint;
MetaKeymapNative *keymap;
MetaInputSettings *input_settings;
MetaViewportInfo *viewports;
@ -248,4 +249,6 @@ void meta_seat_impl_notify_kbd_a11y_mods_state_changed (MetaSeatImpl *seat_imp
xkb_mod_mask_t new_locked_mods);
void meta_seat_impl_notify_bell (MetaSeatImpl *seat_impl);
MetaInputSettings * meta_seat_impl_get_input_settings (MetaSeatImpl *seat_impl);
#endif /* META_SEAT_IMPL_H */