[mutter/wip/carlosg/clutter-seat: 58/68] backends: Move native keymap manipulation functions to MetaSeatNative
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [mutter/wip/carlosg/clutter-seat: 58/68] backends: Move native keymap manipulation functions to MetaSeatNative
- Date: Fri, 10 Jan 2020 13:48:15 +0000 (UTC)
commit 9ab36655e4d43da62369cd3703f470d1266c0d8c
Author: Carlos Garnacho <carlosg gnome org>
Date: Fri Oct 4 15:44:27 2019 +0200
backends: Move native keymap manipulation functions to MetaSeatNative
Since the ClutterKeymap is obtained through the ClutterSeat, it makes
sense to have these manipulation functions in the ClutterSeat impl.
https://gitlab.gnome.org/GNOME/mutter/merge_requests/852
src/backends/native/meta-backend-native.c | 28 ++--
src/backends/native/meta-device-manager-native.c | 197 -----------------------
src/backends/native/meta-device-manager-native.h | 20 ---
src/backends/native/meta-input-settings-native.c | 6 +-
src/backends/native/meta-keymap-native.c | 14 +-
src/backends/native/meta-seat-native.c | 170 +++++++++++++++++++
src/backends/native/meta-seat-native.h | 20 +++
7 files changed, 218 insertions(+), 237 deletions(-)
---
diff --git a/src/backends/native/meta-backend-native.c b/src/backends/native/meta-backend-native.c
index dbe282a7a..f24f440ef 100644
--- a/src/backends/native/meta-backend-native.c
+++ b/src/backends/native/meta-backend-native.c
@@ -441,10 +441,10 @@ meta_backend_native_set_keymap (MetaBackend *backend,
const char *variants,
const char *options)
{
- ClutterDeviceManager *manager = clutter_device_manager_get_default ();
struct xkb_rule_names names;
struct xkb_keymap *keymap;
struct xkb_context *context;
+ ClutterSeat *seat;
names.rules = DEFAULT_XKB_RULES_FILE;
names.model = DEFAULT_XKB_MODEL;
@@ -456,7 +456,8 @@ meta_backend_native_set_keymap (MetaBackend *backend,
keymap = xkb_keymap_new_from_names (context, &names, XKB_KEYMAP_COMPILE_NO_FLAGS);
xkb_context_unref (context);
- meta_device_manager_native_set_keyboard_map (manager, keymap);
+ seat = clutter_backend_get_default_seat (clutter_get_default_backend ());
+ meta_seat_native_set_keyboard_map (META_SEAT_NATIVE (seat), keymap);
meta_backend_notify_keymap_changed (backend);
@@ -466,30 +467,34 @@ meta_backend_native_set_keymap (MetaBackend *backend,
static struct xkb_keymap *
meta_backend_native_get_keymap (MetaBackend *backend)
{
- ClutterDeviceManager *manager = clutter_device_manager_get_default ();
- return meta_device_manager_native_get_keyboard_map (manager);
+ ClutterSeat *seat;
+
+ seat = clutter_backend_get_default_seat (clutter_get_default_backend ());
+ return meta_seat_native_get_keyboard_map (META_SEAT_NATIVE (seat));
}
static xkb_layout_index_t
meta_backend_native_get_keymap_layout_group (MetaBackend *backend)
{
- ClutterDeviceManager *manager = clutter_device_manager_get_default ();
+ ClutterSeat *seat;
- return meta_device_manager_native_get_keyboard_layout_index (manager);
+ seat = clutter_backend_get_default_seat (clutter_get_default_backend ());
+ return meta_seat_native_get_keyboard_layout_index (META_SEAT_NATIVE (seat));
}
static void
meta_backend_native_lock_layout_group (MetaBackend *backend,
guint idx)
{
- ClutterDeviceManager *manager = clutter_device_manager_get_default ();
xkb_layout_index_t old_idx;
+ ClutterSeat *seat;
old_idx = meta_backend_native_get_keymap_layout_group (backend);
if (old_idx == idx)
return;
- meta_device_manager_native_set_keyboard_layout_index (manager, idx);
+ seat = clutter_backend_get_default_seat (clutter_get_default_backend ());
+ meta_seat_native_set_keyboard_layout_index (META_SEAT_NATIVE (seat), idx);
meta_backend_notify_keymap_layout_group_changed (backend, idx);
}
@@ -497,8 +502,11 @@ static void
meta_backend_native_set_numlock (MetaBackend *backend,
gboolean numlock_state)
{
- ClutterDeviceManager *manager = clutter_device_manager_get_default ();
- meta_device_manager_native_set_keyboard_numlock (manager, numlock_state);
+ ClutterSeat *seat;
+
+ seat = clutter_backend_get_default_seat (clutter_get_default_backend ());
+ meta_seat_native_set_keyboard_numlock (META_SEAT_NATIVE (seat),
+ numlock_state);
}
static gboolean
diff --git a/src/backends/native/meta-device-manager-native.c
b/src/backends/native/meta-device-manager-native.c
index 15d291ea1..a219153d5 100644
--- a/src/backends/native/meta-device-manager-native.c
+++ b/src/backends/native/meta-device-manager-native.c
@@ -208,200 +208,3 @@ meta_device_manager_native_new (ClutterBackend *backend,
return manager_native;
}
-
-/**
- * meta_device_manager_native_set_keyboard_map: (skip)
- * @evdev: the #ClutterDeviceManager created by the evdev backend
- * @keymap: the new keymap
- *
- * Instructs @evdev to use the speficied keyboard map. This will cause
- * the backend to drop the state and create a new one with the new
- * map. To avoid state being lost, callers should ensure that no key
- * is pressed when calling this function.
- *
- * Since: 1.16
- * Stability: unstable
- */
-void
-meta_device_manager_native_set_keyboard_map (ClutterDeviceManager *evdev,
- struct xkb_keymap *xkb_keymap)
-{
- MetaDeviceManagerNative *manager_evdev;
- ClutterKeymap *keymap;
-
- g_return_if_fail (META_IS_DEVICE_MANAGER_NATIVE (evdev));
-
- manager_evdev = META_DEVICE_MANAGER_NATIVE (evdev);
- keymap = clutter_seat_get_keymap (CLUTTER_SEAT (manager_evdev->priv->main_seat));
- meta_keymap_native_set_keyboard_map (META_KEYMAP_NATIVE (keymap),
- xkb_keymap);
-
- meta_seat_native_update_xkb_state (manager_evdev->priv->main_seat);
-}
-
-/**
- * meta_device_manager_native_get_keyboard_map: (skip)
- * @evdev: the #ClutterDeviceManager created by the evdev backend
- *
- * Retrieves the #xkb_keymap in use by the evdev backend.
- *
- * Return value: the #xkb_keymap.
- *
- * Since: 1.18
- * Stability: unstable
- */
-struct xkb_keymap *
-meta_device_manager_native_get_keyboard_map (ClutterDeviceManager *evdev)
-{
- MetaDeviceManagerNative *manager_evdev;
-
- g_return_val_if_fail (META_IS_DEVICE_MANAGER_NATIVE (evdev), NULL);
-
- manager_evdev = META_DEVICE_MANAGER_NATIVE (evdev);
-
- return xkb_state_get_keymap (manager_evdev->priv->main_seat->xkb);
-}
-
-/**
- * meta_device_manager_set_keyboard_layout_index: (skip)
- * @evdev: the #ClutterDeviceManager created by the evdev backend
- * @idx: the xkb layout index to set
- *
- * Sets the xkb layout index on the backend's #xkb_state .
- *
- * Since: 1.20
- * Stability: unstable
- */
-void
-meta_device_manager_native_set_keyboard_layout_index (ClutterDeviceManager *evdev,
- xkb_layout_index_t idx)
-{
- MetaDeviceManagerNative *manager_evdev;
- MetaSeatNative *seat;
- xkb_mod_mask_t depressed_mods;
- xkb_mod_mask_t latched_mods;
- xkb_mod_mask_t locked_mods;
- struct xkb_state *state;
-
- g_return_if_fail (META_IS_DEVICE_MANAGER_NATIVE (evdev));
-
- manager_evdev = META_DEVICE_MANAGER_NATIVE (evdev);
- state = manager_evdev->priv->main_seat->xkb;
-
- depressed_mods = xkb_state_serialize_mods (state, XKB_STATE_MODS_DEPRESSED);
- latched_mods = xkb_state_serialize_mods (state, XKB_STATE_MODS_LATCHED);
- locked_mods = xkb_state_serialize_mods (state, XKB_STATE_MODS_LOCKED);
-
- xkb_state_update_mask (state, depressed_mods, latched_mods, locked_mods, 0, 0, idx);
-
- seat = manager_evdev->priv->main_seat;
- seat->layout_idx = idx;
-}
-
-/**
- * clutter_evdev_get_keyboard_layout_index: (skip)
- */
-xkb_layout_index_t
-meta_device_manager_native_get_keyboard_layout_index (ClutterDeviceManager *evdev)
-{
- MetaDeviceManagerNative *manager_evdev;
-
- manager_evdev = META_DEVICE_MANAGER_NATIVE (evdev);
- return manager_evdev->priv->main_seat->layout_idx;
-}
-
-/**
- * meta_device_manager_native_set_keyboard_numlock: (skip)
- * @evdev: the #ClutterDeviceManager created by the evdev backend
- * @numlock_set: TRUE to set NumLock ON, FALSE otherwise.
- *
- * Sets the NumLock state on the backend's #xkb_state .
- *
- * Stability: unstable
- */
-void
-meta_device_manager_native_set_keyboard_numlock (ClutterDeviceManager *evdev,
- gboolean numlock_state)
-{
- MetaDeviceManagerNative *manager_evdev;
- MetaDeviceManagerNativePrivate *priv;
- MetaSeatNative *seat;
- xkb_mod_mask_t depressed_mods;
- xkb_mod_mask_t latched_mods;
- xkb_mod_mask_t locked_mods;
- xkb_mod_mask_t group_mods;
- xkb_mod_mask_t numlock;
- struct xkb_keymap *xkb_keymap;
- ClutterKeymap *keymap;
-
- g_return_if_fail (META_IS_DEVICE_MANAGER_NATIVE (evdev));
-
- manager_evdev = META_DEVICE_MANAGER_NATIVE (evdev);
- priv = manager_evdev->priv;
-
- keymap = clutter_seat_get_keymap (CLUTTER_SEAT (priv->main_seat));
- xkb_keymap = meta_keymap_native_get_keyboard_map (META_KEYMAP_NATIVE (keymap));
-
- numlock = (1 << xkb_keymap_mod_get_index (xkb_keymap, "Mod2"));
-
- seat = priv->main_seat;
-
- depressed_mods = xkb_state_serialize_mods (seat->xkb, XKB_STATE_MODS_DEPRESSED);
- latched_mods = xkb_state_serialize_mods (seat->xkb, XKB_STATE_MODS_LATCHED);
- locked_mods = xkb_state_serialize_mods (seat->xkb, XKB_STATE_MODS_LOCKED);
- group_mods = xkb_state_serialize_layout (seat->xkb, XKB_STATE_LAYOUT_EFFECTIVE);
-
- if (numlock_state)
- locked_mods |= numlock;
- else
- locked_mods &= ~numlock;
-
- xkb_state_update_mask (seat->xkb,
- depressed_mods,
- latched_mods,
- locked_mods,
- 0, 0,
- group_mods);
-
- meta_seat_native_sync_leds (seat);
-}
-
-/**
- * meta_device_manager_native_set_keyboard_repeat:
- * @evdev: the #ClutterDeviceManager created by the evdev backend
- * @repeat: whether to enable or disable keyboard repeat events
- * @delay: the delay in ms between the hardware key press event and
- * the first synthetic event
- * @interval: the period in ms between consecutive synthetic key
- * press events
- *
- * Enables or disables sythetic key press events, allowing for initial
- * delay and interval period to be specified.
- *
- * Since: 1.18
- * Stability: unstable
- */
-void
-meta_device_manager_native_set_keyboard_repeat (ClutterDeviceManager *evdev,
- gboolean repeat,
- uint32_t delay,
- uint32_t interval)
-{
- MetaDeviceManagerNative *manager_evdev;
- MetaSeatNative *seat;
-
- g_return_if_fail (META_IS_DEVICE_MANAGER_NATIVE (evdev));
-
- manager_evdev = META_DEVICE_MANAGER_NATIVE (evdev);
- seat = manager_evdev->priv->main_seat;
-
- seat->repeat = repeat;
- seat->repeat_delay = delay;
- seat->repeat_interval = interval;
-}
-
-struct xkb_state *
-meta_device_manager_native_get_xkb_state (MetaDeviceManagerNative *manager_evdev)
-{
- return manager_evdev->priv->main_seat->xkb;
-}
diff --git a/src/backends/native/meta-device-manager-native.h
b/src/backends/native/meta-device-manager-native.h
index feb5f7965..76d356548 100644
--- a/src/backends/native/meta-device-manager-native.h
+++ b/src/backends/native/meta-device-manager-native.h
@@ -54,24 +54,4 @@ GType meta_device_manager_native_get_type (void) G_GNUC_CONST;
MetaDeviceManagerNative * meta_device_manager_native_new (ClutterBackend *backend,
MetaSeatNative *seat);
-struct xkb_state * meta_device_manager_native_get_xkb_state (MetaDeviceManagerNative *manager_evdev);
-
-void meta_device_manager_native_set_keyboard_map (ClutterDeviceManager *evdev,
- struct xkb_keymap *keymap);
-
-struct xkb_keymap * meta_device_manager_native_get_keyboard_map (ClutterDeviceManager *evdev);
-
-void meta_device_manager_native_set_keyboard_layout_index (ClutterDeviceManager *evdev,
- xkb_layout_index_t idx);
-
-xkb_layout_index_t meta_device_manager_native_get_keyboard_layout_index (ClutterDeviceManager *evdev);
-
-void meta_device_manager_native_set_keyboard_numlock (ClutterDeviceManager *evdev,
- gboolean numlock_state);
-
-void meta_device_manager_native_set_keyboard_repeat (ClutterDeviceManager *evdev,
- gboolean repeat,
- uint32_t delay,
- uint32_t interval);
-
#endif /* META_DEVICE_MANAGER_NATIVE_H */
diff --git a/src/backends/native/meta-input-settings-native.c
b/src/backends/native/meta-input-settings-native.c
index a202012e3..fe5073bd8 100644
--- a/src/backends/native/meta-input-settings-native.c
+++ b/src/backends/native/meta-input-settings-native.c
@@ -316,9 +316,11 @@ meta_input_settings_native_set_keyboard_repeat (MetaInputSettings *settings,
guint delay,
guint interval)
{
- ClutterDeviceManager *manager = clutter_device_manager_get_default ();
+ ClutterSeat *seat;
- meta_device_manager_native_set_keyboard_repeat (manager, enabled, delay, interval);
+ seat = clutter_backend_get_default_seat (clutter_get_default_backend ());
+ meta_seat_native_set_keyboard_repeat (META_SEAT_NATIVE (seat),
+ enabled, delay, interval);
}
static void
diff --git a/src/backends/native/meta-keymap-native.c b/src/backends/native/meta-keymap-native.c
index 77777b6d4..be2a9f5ab 100644
--- a/src/backends/native/meta-keymap-native.c
+++ b/src/backends/native/meta-keymap-native.c
@@ -53,12 +53,11 @@ meta_keymap_native_finalize (GObject *object)
static gboolean
meta_keymap_native_get_num_lock_state (ClutterKeymap *keymap)
{
- MetaDeviceManagerNative *device_manager;
struct xkb_state *xkb_state;
+ ClutterSeat *seat;
- device_manager =
- META_DEVICE_MANAGER_NATIVE (clutter_device_manager_get_default ());
- xkb_state = meta_device_manager_native_get_xkb_state (device_manager);
+ seat = clutter_backend_get_default_seat (clutter_get_default_backend ());
+ xkb_state = meta_seat_native_get_xkb_state (META_SEAT_NATIVE (seat));
return xkb_state_mod_name_is_active (xkb_state,
XKB_MOD_NAME_NUM,
@@ -69,12 +68,11 @@ meta_keymap_native_get_num_lock_state (ClutterKeymap *keymap)
static gboolean
meta_keymap_native_get_caps_lock_state (ClutterKeymap *keymap)
{
- MetaDeviceManagerNative *device_manager;
struct xkb_state *xkb_state;
+ ClutterSeat *seat;
- device_manager =
- META_DEVICE_MANAGER_NATIVE (clutter_device_manager_get_default ());
- xkb_state = meta_device_manager_native_get_xkb_state (device_manager);
+ seat = clutter_backend_get_default_seat (clutter_get_default_backend ());
+ xkb_state = meta_seat_native_get_xkb_state (META_SEAT_NATIVE (seat));
return xkb_state_mod_name_is_active (xkb_state,
XKB_MOD_NAME_CAPS,
diff --git a/src/backends/native/meta-seat-native.c b/src/backends/native/meta-seat-native.c
index 7f135df9d..5978a4922 100644
--- a/src/backends/native/meta-seat-native.c
+++ b/src/backends/native/meta-seat-native.c
@@ -3050,3 +3050,173 @@ meta_seat_native_reclaim_devices (MetaSeatNative *seat)
seat->released = FALSE;
}
+
+/**
+ * meta_seat_native_set_keyboard_map: (skip)
+ * @seat: the #ClutterSeat created by the evdev backend
+ * @keymap: the new keymap
+ *
+ * Instructs @evdev to use the speficied keyboard map. This will cause
+ * the backend to drop the state and create a new one with the new
+ * map. To avoid state being lost, callers should ensure that no key
+ * is pressed when calling this function.
+ *
+ * Since: 1.16
+ * Stability: unstable
+ */
+void
+meta_seat_native_set_keyboard_map (MetaSeatNative *seat,
+ struct xkb_keymap *xkb_keymap)
+{
+ ClutterKeymap *keymap;
+
+ g_return_if_fail (META_IS_SEAT_NATIVE (seat));
+
+ keymap = clutter_seat_get_keymap (CLUTTER_SEAT (seat));
+ meta_keymap_native_set_keyboard_map (META_KEYMAP_NATIVE (keymap),
+ xkb_keymap);
+
+ meta_seat_native_update_xkb_state (seat);
+}
+
+/**
+ * meta_seat_native_get_keyboard_map: (skip)
+ * @seat: the #ClutterSeat created by the evdev backend
+ *
+ * Retrieves the #xkb_keymap in use by the evdev backend.
+ *
+ * Return value: the #xkb_keymap.
+ *
+ * Since: 1.18
+ * Stability: unstable
+ */
+struct xkb_keymap *
+meta_seat_native_get_keyboard_map (MetaSeatNative *seat)
+{
+ g_return_val_if_fail (META_IS_SEAT_NATIVE (seat), NULL);
+
+ return xkb_state_get_keymap (seat->xkb);
+}
+
+/**
+ * meta_seat_set_keyboard_layout_index: (skip)
+ * @seat: the #ClutterSeat created by the evdev backend
+ * @idx: the xkb layout index to set
+ *
+ * Sets the xkb layout index on the backend's #xkb_state .
+ *
+ * Since: 1.20
+ * Stability: unstable
+ */
+void
+meta_seat_native_set_keyboard_layout_index (MetaSeatNative *seat,
+ xkb_layout_index_t idx)
+{
+ xkb_mod_mask_t depressed_mods;
+ xkb_mod_mask_t latched_mods;
+ xkb_mod_mask_t locked_mods;
+ struct xkb_state *state;
+
+ g_return_if_fail (META_IS_SEAT_NATIVE (seat));
+
+ state = seat->xkb;
+
+ depressed_mods = xkb_state_serialize_mods (state, XKB_STATE_MODS_DEPRESSED);
+ latched_mods = xkb_state_serialize_mods (state, XKB_STATE_MODS_LATCHED);
+ locked_mods = xkb_state_serialize_mods (state, XKB_STATE_MODS_LOCKED);
+
+ xkb_state_update_mask (state, depressed_mods, latched_mods, locked_mods, 0, 0, idx);
+
+ seat->layout_idx = idx;
+}
+
+/**
+ * clutter_evdev_get_keyboard_layout_index: (skip)
+ */
+xkb_layout_index_t
+meta_seat_native_get_keyboard_layout_index (MetaSeatNative *seat)
+{
+ return seat->layout_idx;
+}
+
+/**
+ * meta_seat_native_set_keyboard_numlock: (skip)
+ * @seat: the #ClutterSeat created by the evdev backend
+ * @numlock_set: TRUE to set NumLock ON, FALSE otherwise.
+ *
+ * Sets the NumLock state on the backend's #xkb_state .
+ *
+ * Stability: unstable
+ */
+void
+meta_seat_native_set_keyboard_numlock (MetaSeatNative *seat,
+ gboolean numlock_state)
+{
+ xkb_mod_mask_t depressed_mods;
+ xkb_mod_mask_t latched_mods;
+ xkb_mod_mask_t locked_mods;
+ xkb_mod_mask_t group_mods;
+ xkb_mod_mask_t numlock;
+ struct xkb_keymap *xkb_keymap;
+ ClutterKeymap *keymap;
+
+ g_return_if_fail (META_IS_SEAT_NATIVE (seat));
+
+ keymap = clutter_seat_get_keymap (CLUTTER_SEAT (seat));
+ xkb_keymap = meta_keymap_native_get_keyboard_map (META_KEYMAP_NATIVE (keymap));
+
+ numlock = (1 << xkb_keymap_mod_get_index (xkb_keymap, "Mod2"));
+
+ depressed_mods = xkb_state_serialize_mods (seat->xkb, XKB_STATE_MODS_DEPRESSED);
+ latched_mods = xkb_state_serialize_mods (seat->xkb, XKB_STATE_MODS_LATCHED);
+ locked_mods = xkb_state_serialize_mods (seat->xkb, XKB_STATE_MODS_LOCKED);
+ group_mods = xkb_state_serialize_layout (seat->xkb, XKB_STATE_LAYOUT_EFFECTIVE);
+
+ if (numlock_state)
+ locked_mods |= numlock;
+ else
+ locked_mods &= ~numlock;
+
+ xkb_state_update_mask (seat->xkb,
+ depressed_mods,
+ latched_mods,
+ locked_mods,
+ 0, 0,
+ group_mods);
+
+ meta_seat_native_sync_leds (seat);
+}
+
+/**
+ * meta_seat_native_set_keyboard_repeat:
+ * @seat: the #ClutterSeat created by the evdev backend
+ * @repeat: whether to enable or disable keyboard repeat events
+ * @delay: the delay in ms between the hardware key press event and
+ * the first synthetic event
+ * @interval: the period in ms between consecutive synthetic key
+ * press events
+ *
+ * Enables or disables sythetic key press events, allowing for initial
+ * delay and interval period to be specified.
+ *
+ * Since: 1.18
+ * Stability: unstable
+ */
+void
+meta_seat_native_set_keyboard_repeat (MetaSeatNative *seat,
+ gboolean repeat,
+ uint32_t delay,
+ uint32_t interval)
+{
+ g_return_if_fail (META_IS_SEAT_NATIVE (seat));
+
+ seat->repeat = repeat;
+ seat->repeat_delay = delay;
+ seat->repeat_interval = interval;
+}
+
+struct xkb_state *
+meta_seat_native_get_xkb_state (MetaSeatNative *seat)
+{
+ return seat->xkb;
+}
diff --git a/src/backends/native/meta-seat-native.h b/src/backends/native/meta-seat-native.h
index 41895523e..af8af1f36 100644
--- a/src/backends/native/meta-seat-native.h
+++ b/src/backends/native/meta-seat-native.h
@@ -300,4 +300,24 @@ void meta_seat_native_warp_pointer (ClutterInputDevice *pointer_device,
int x,
int y);
+struct xkb_state * meta_seat_native_get_xkb_state (MetaSeatNative *seat);
+
+void meta_seat_native_set_keyboard_map (MetaSeatNative *seat,
+ struct xkb_keymap *keymap);
+
+struct xkb_keymap * meta_seat_native_get_keyboard_map (MetaSeatNative *seat);
+
+void meta_seat_native_set_keyboard_layout_index (MetaSeatNative *seat,
+ xkb_layout_index_t idx);
+
+xkb_layout_index_t meta_seat_native_get_keyboard_layout_index (MetaSeatNative *seat);
+
+void meta_seat_native_set_keyboard_numlock (MetaSeatNative *seat,
+ gboolean numlock_state);
+
+void meta_seat_native_set_keyboard_repeat (MetaSeatNative *seat,
+ gboolean repeat,
+ uint32_t delay,
+ uint32_t interval);
+
#endif /* META_SEAT_NATIVE_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]