backends: Make MetaInputMapper take over MetaInputSettings public API

Banish MetaInputSettings from MetaBackend "public" API, it's now meant to
spend the rest of its days in the backend dungeons, maybe hanging
off a thread.

MetaInputMapper replaces all external uses.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1403>
This commit is contained in:
Carlos Garnacho 2020-08-04 14:17:39 +02:00 committed by Marge Bot
parent 9a21482fef
commit 4013bed6e4
7 changed files with 93 additions and 94 deletions

View File

@ -34,6 +34,7 @@
#include "backends/meta-backend-types.h"
#include "backends/meta-cursor-renderer.h"
#include "backends/meta-egl.h"
#include "backends/meta-input-mapper-private.h"
#include "backends/meta-input-settings-private.h"
#include "backends/meta-monitor-manager-private.h"
#include "backends/meta-orientation-manager.h"
@ -175,6 +176,7 @@ gboolean meta_is_stage_views_enabled (void);
gboolean meta_is_stage_views_scaled (void);
MetaInputMapper *meta_backend_get_input_mapper (MetaBackend *backend);
MetaInputSettings *meta_backend_get_input_settings (MetaBackend *backend);
void meta_backend_notify_keymap_changed (MetaBackend *backend);

View File

@ -56,6 +56,7 @@
#include "backends/meta-cursor-renderer.h"
#include "backends/meta-cursor-tracker-private.h"
#include "backends/meta-idle-monitor-private.h"
#include "backends/meta-input-mapper-private.h"
#include "backends/meta-input-settings-private.h"
#include "backends/meta-logical-monitor.h"
#include "backends/meta-monitor-manager-dummy.h"
@ -122,6 +123,7 @@ struct _MetaBackendPrivate
MetaOrientationManager *orientation_manager;
MetaCursorTracker *cursor_tracker;
MetaInputSettings *input_settings;
MetaInputMapper *input_mapper;
MetaRenderer *renderer;
#ifdef HAVE_EGL
MetaEgl *egl;
@ -447,11 +449,22 @@ on_device_added (ClutterSeat *seat,
{
MetaBackend *backend = META_BACKEND (user_data);
MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
ClutterInputDeviceType device_type;
create_device_monitor (backend, device);
if (device_is_physical_touchscreen (device))
meta_cursor_tracker_set_pointer_visible (priv->cursor_tracker, FALSE);
device_type = clutter_input_device_get_device_type (device);
if (device_type == CLUTTER_TOUCHSCREEN_DEVICE ||
device_type == CLUTTER_TABLET_DEVICE ||
device_type == CLUTTER_PEN_DEVICE ||
device_type == CLUTTER_ERASER_DEVICE ||
device_type == CLUTTER_CURSOR_DEVICE ||
device_type == CLUTTER_PAD_DEVICE)
meta_input_mapper_add_device (priv->input_mapper, device);
}
static void
@ -464,6 +477,8 @@ on_device_removed (ClutterSeat *seat,
destroy_device_monitor (backend, device);
meta_input_mapper_remove_device (priv->input_mapper, device);
/* If the device the user last interacted goes away, check again pointer
* visibility.
*/
@ -523,6 +538,42 @@ meta_backend_create_input_settings (MetaBackend *backend)
return META_BACKEND_GET_CLASS (backend)->create_input_settings (backend);
}
static void
input_mapper_device_mapped_cb (MetaInputMapper *mapper,
ClutterInputDevice *device,
float matrix[6],
MetaBackend *backend)
{
MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
MetaInputSettings *input_settings = priv->input_settings;
meta_input_settings_set_device_matrix (input_settings, device, matrix);
}
static void
input_mapper_device_enabled_cb (MetaInputMapper *mapper,
ClutterInputDevice *device,
gboolean enabled,
MetaBackend *backend)
{
MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
MetaInputSettings *input_settings = priv->input_settings;
meta_input_settings_set_device_enabled (input_settings, device, enabled);
}
static void
input_mapper_device_aspect_ratio_cb (MetaInputMapper *mapper,
ClutterInputDevice *device,
double aspect_ratio,
MetaBackend *backend)
{
MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
MetaInputSettings *input_settings = priv->input_settings;
meta_input_settings_set_device_aspect_ratio (input_settings, device, aspect_ratio);
}
static void
meta_backend_real_post_init (MetaBackend *backend)
{
@ -560,6 +611,14 @@ meta_backend_real_post_init (MetaBackend *backend)
meta_input_settings_maybe_restore_numlock_state (priv->input_settings);
}
priv->input_mapper = meta_input_mapper_new ();
g_signal_connect (priv->input_mapper, "device-mapped",
G_CALLBACK (input_mapper_device_mapped_cb), backend);
g_signal_connect (priv->input_mapper, "device-enabled",
G_CALLBACK (input_mapper_device_enabled_cb), backend);
g_signal_connect (priv->input_mapper, "device-aspect-ratio",
G_CALLBACK (input_mapper_device_aspect_ratio_cb), backend);
#ifdef HAVE_REMOTE_DESKTOP
priv->dbus_session_watcher = g_object_new (META_TYPE_DBUS_SESSION_WATCHER, NULL);
priv->screen_cast = meta_screen_cast_new (backend,
@ -1464,6 +1523,14 @@ meta_is_stage_views_scaled (void)
return layout_mode == META_LOGICAL_MONITOR_LAYOUT_MODE_LOGICAL;
}
MetaInputMapper *
meta_backend_get_input_mapper (MetaBackend *backend)
{
MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
return priv->input_mapper;
}
MetaInputSettings *
meta_backend_get_input_settings (MetaBackend *backend)
{

View File

@ -23,7 +23,8 @@
#define META_INPUT_MAPPER_H
#include <clutter/clutter.h>
#include "meta-monitor-manager-private.h"
#include "backends/meta-backend-types.h"
#define META_TYPE_INPUT_MAPPER (meta_input_mapper_get_type ())

View File

@ -137,11 +137,6 @@ struct _MetaInputSettingsClass
ClutterInputDevice *device);
};
GSettings * meta_input_settings_get_tablet_settings (MetaInputSettings *settings,
ClutterInputDevice *device);
MetaLogicalMonitor * meta_input_settings_get_tablet_logical_monitor (MetaInputSettings *settings,
ClutterInputDevice *device);
void meta_input_settings_maybe_save_numlock_state (MetaInputSettings *input_settings);
void meta_input_settings_maybe_restore_numlock_state (MetaInputSettings *input_settings);

View File

@ -82,9 +82,6 @@ struct _MetaInputSettingsPrivate
GHashTable *current_tools;
GHashTable *two_finger_devices;
/* For absolute devices with no mapping in settings */
MetaInputMapper *input_mapper;
};
typedef gboolean (* ConfigBoolMappingFunc) (MetaInputSettings *input_settings,
@ -143,7 +140,6 @@ meta_input_settings_dispose (GObject *object)
g_clear_object (&priv->gsd_settings);
g_clear_object (&priv->keyboard_a11y_settings);
g_clear_object (&priv->mouse_a11y_settings);
g_clear_object (&priv->input_mapper);
g_clear_pointer (&priv->mappable_devices, g_hash_table_unref);
g_clear_pointer (&priv->current_tools, g_hash_table_unref);
@ -1411,33 +1407,6 @@ lookup_tool_settings (ClutterInputDeviceTool *tool,
return tool_settings;
}
static void
input_mapper_device_mapped_cb (MetaInputMapper *mapper,
ClutterInputDevice *device,
float matrix[6],
MetaInputSettings *input_settings)
{
meta_input_settings_set_device_matrix (input_settings, device, matrix);
}
static void
input_mapper_device_enabled_cb (MetaInputMapper *mapper,
ClutterInputDevice *device,
gboolean enabled,
MetaInputSettings *input_settings)
{
meta_input_settings_set_device_enabled (input_settings, device, enabled);
}
static void
input_mapper_device_aspect_ratio_cb (MetaInputMapper *mapper,
ClutterInputDevice *device,
double aspect_ratio,
MetaInputSettings *input_settings)
{
meta_input_settings_set_device_aspect_ratio (input_settings, device, aspect_ratio);
}
static void
device_mapping_info_free (DeviceMappingInfo *info)
{
@ -1470,8 +1439,6 @@ check_add_mappable_device (MetaInputSettings *input_settings,
if (!settings)
return FALSE;
meta_input_mapper_add_device (priv->input_mapper, device);
priv = meta_input_settings_get_instance_private (input_settings);
info = g_slice_new0 (DeviceMappingInfo);
@ -1645,7 +1612,6 @@ meta_input_settings_device_removed (ClutterSeat *seat,
MetaInputSettingsPrivate *priv;
priv = meta_input_settings_get_instance_private (input_settings);
meta_input_mapper_remove_device (priv->input_mapper, device);
g_hash_table_remove (priv->mappable_devices, device);
g_hash_table_remove (priv->current_tools, device);
@ -1818,44 +1784,6 @@ meta_input_settings_init (MetaInputSettings *settings)
g_hash_table_new_full (NULL, NULL, NULL, (GDestroyNotify) current_tool_info_free);
priv->two_finger_devices = g_hash_table_new (NULL, NULL);
priv->input_mapper = meta_input_mapper_new ();
g_signal_connect (priv->input_mapper, "device-mapped",
G_CALLBACK (input_mapper_device_mapped_cb), settings);
g_signal_connect (priv->input_mapper, "device-enabled",
G_CALLBACK (input_mapper_device_enabled_cb), settings);
g_signal_connect (priv->input_mapper, "device-aspect-ratio",
G_CALLBACK (input_mapper_device_aspect_ratio_cb), settings);
}
GSettings *
meta_input_settings_get_tablet_settings (MetaInputSettings *settings,
ClutterInputDevice *device)
{
MetaInputSettingsPrivate *priv;
DeviceMappingInfo *info;
g_return_val_if_fail (META_IS_INPUT_SETTINGS (settings), NULL);
g_return_val_if_fail (CLUTTER_IS_INPUT_DEVICE (device), NULL);
priv = meta_input_settings_get_instance_private (settings);
info = g_hash_table_lookup (priv->mappable_devices, device);
return info ? g_object_ref (info->settings) : NULL;
}
MetaLogicalMonitor *
meta_input_settings_get_tablet_logical_monitor (MetaInputSettings *settings,
ClutterInputDevice *device)
{
MetaInputSettingsPrivate *priv;
g_return_val_if_fail (META_IS_INPUT_SETTINGS (settings), NULL);
g_return_val_if_fail (CLUTTER_IS_INPUT_DEVICE (device), NULL);
priv = meta_input_settings_get_instance_private (settings);
return meta_input_mapper_get_device_logical_monitor (priv->input_mapper, device);
}
void

View File

@ -73,6 +73,7 @@ struct _MetaBackendNative
MetaLauncher *launcher;
MetaUdev *udev;
MetaKms *kms;
MetaInputSettings *input_settings;
gulong udev_device_added_handler_id;
};
@ -100,6 +101,7 @@ meta_backend_native_finalize (GObject *object)
g_clear_object (&native->udev);
g_clear_object (&native->kms);
meta_launcher_free (native->launcher);
g_clear_object (&native->input_settings);
G_OBJECT_CLASS (meta_backend_native_parent_class)->finalize (object);
}
@ -235,7 +237,15 @@ meta_backend_native_create_renderer (MetaBackend *backend,
static MetaInputSettings *
meta_backend_native_create_input_settings (MetaBackend *backend)
{
return g_object_new (META_TYPE_INPUT_SETTINGS_NATIVE, NULL);
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);
}
return backend_native->input_settings;
}
static MetaLogicalMonitor *
@ -669,7 +679,6 @@ void meta_backend_native_resume (MetaBackendNative *native)
meta_backend_get_monitor_manager (backend);
MetaMonitorManagerKms *monitor_manager_kms =
META_MONITOR_MANAGER_KMS (monitor_manager);
MetaInputSettings *input_settings;
MetaIdleMonitor *idle_monitor;
ClutterBackend *clutter_backend = meta_backend_get_clutter_backend (backend);
MetaSeatNative *seat =
@ -691,8 +700,7 @@ void meta_backend_native_resume (MetaBackendNative *native)
idle_monitor = meta_idle_monitor_get_core ();
meta_idle_monitor_reset_idletime (idle_monitor);
input_settings = meta_backend_get_input_settings (backend);
meta_input_settings_maybe_restore_numlock_state (input_settings);
meta_input_settings_maybe_restore_numlock_state (native->input_settings);
clutter_seat_ensure_a11y_state (CLUTTER_SEAT (seat));
}

View File

@ -45,7 +45,7 @@
#include "backends/meta-cursor-tracker-private.h"
#include "backends/meta-idle-monitor-dbus.h"
#include "backends/meta-input-device-private.h"
#include "backends/meta-input-settings-private.h"
#include "backends/meta-input-mapper-private.h"
#include "backends/meta-stage-private.h"
#include "backends/x11/meta-backend-x11.h"
#include "backends/x11/meta-event-x11.h"
@ -2909,7 +2909,7 @@ meta_display_request_pad_osd (MetaDisplay *display,
gboolean edition_mode)
{
MetaBackend *backend = meta_get_backend ();
MetaInputSettings *input_settings;
MetaInputMapper *input_mapper;
const gchar *layout_path = NULL;
ClutterActor *osd;
MetaLogicalMonitor *logical_monitor;
@ -2925,13 +2925,13 @@ meta_display_request_pad_osd (MetaDisplay *display,
if (display->current_pad_osd)
return;
input_settings = meta_backend_get_input_settings (meta_get_backend ());
input_mapper = meta_backend_get_input_mapper (meta_get_backend ());
if (input_settings)
if (input_mapper)
{
settings = meta_input_settings_get_tablet_settings (input_settings, pad);
settings = meta_input_mapper_get_tablet_settings (input_mapper, pad);
logical_monitor =
meta_input_settings_get_tablet_logical_monitor (input_settings, pad);
meta_input_mapper_get_device_logical_monitor (input_mapper, pad);
#ifdef HAVE_LIBWACOM
wacom_device = meta_input_device_get_wacom_device (META_INPUT_DEVICE (pad));
layout_path = libwacom_get_layout_filename (wacom_device);
@ -2954,8 +2954,6 @@ meta_display_request_pad_osd (MetaDisplay *display,
g_object_add_weak_pointer (G_OBJECT (display->current_pad_osd),
(gpointer *) &display->current_pad_osd);
}
g_object_unref (settings);
}
gchar *
@ -3015,15 +3013,15 @@ static gint
lookup_tablet_monitor (MetaDisplay *display,
ClutterInputDevice *device)
{
MetaInputSettings *input_settings;
MetaInputMapper *input_mapper;
MetaLogicalMonitor *monitor;
gint monitor_idx = -1;
input_settings = meta_backend_get_input_settings (meta_get_backend ());
if (!input_settings)
input_mapper = meta_backend_get_input_mapper (meta_get_backend ());
if (!input_mapper)
return -1;
monitor = meta_input_settings_get_tablet_logical_monitor (input_settings, device);
monitor = meta_input_mapper_get_device_logical_monitor (input_mapper, device);
if (monitor)
{