[gnome-control-center] keyboard: Split out function to normalize keyval and modifier mask
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center] keyboard: Split out function to normalize keyval and modifier mask
- Date: Mon, 22 Aug 2022 12:54:09 +0000 (UTC)
commit 986a37ff6c8c52e51831314e14138b70567cfcb1
Author: Sebastian Keller <skeller gnome org>
Date: Thu Dec 16 22:47:24 2021 +0100
keyboard: Split out function to normalize keyval and modifier mask
This will allow it to be tested in a unit test in an upcoming commit.
panels/keyboard/cc-keyboard-shortcut-editor.c | 21 +++--------------
panels/keyboard/keyboard-shortcuts.c | 33 +++++++++++++++++++++++++++
panels/keyboard/keyboard-shortcuts.h | 6 +++++
3 files changed, 42 insertions(+), 18 deletions(-)
---
diff --git a/panels/keyboard/cc-keyboard-shortcut-editor.c b/panels/keyboard/cc-keyboard-shortcut-editor.c
index 25441f194..95fa3aa65 100644
--- a/panels/keyboard/cc-keyboard-shortcut-editor.c
+++ b/panels/keyboard/cc-keyboard-shortcut-editor.c
@@ -687,24 +687,9 @@ on_key_pressed_cb (GtkEventControllerKey *key_controller,
if (!editing)
return GDK_EVENT_PROPAGATE;
- real_mask = state & gtk_accelerator_get_default_mod_mask ();
-
- keyval_lower = gdk_keyval_to_lower (keyval);
-
- /* Normalise <Tab> */
- if (keyval_lower == GDK_KEY_ISO_Left_Tab)
- keyval_lower = GDK_KEY_Tab;
-
- /* Put shift back if it changed the case of the key, not otherwise. */
- if (keyval_lower != keyval)
- real_mask |= GDK_SHIFT_MASK;
-
- if (keyval_lower == GDK_KEY_Sys_Req && (real_mask & GDK_ALT_MASK) != 0)
- {
- /* HACK: we don't want to use SysRq as a keybinding (but we do
- * want Alt+Print), so we avoid translation from Alt+Print to SysRq */
- keyval_lower = GDK_KEY_Print;
- }
+ normalize_keyval_and_mask (keyval, state,
+ gtk_event_controller_key_get_group (key_controller),
+ &keyval_lower, &real_mask);
event = gtk_event_controller_get_current_event (GTK_EVENT_CONTROLLER (key_controller));
is_modifier = gdk_key_event_is_modifier (event);
diff --git a/panels/keyboard/keyboard-shortcuts.c b/panels/keyboard/keyboard-shortcuts.c
index 903774385..c40794d80 100644
--- a/panels/keyboard/keyboard-shortcuts.c
+++ b/panels/keyboard/keyboard-shortcuts.c
@@ -376,3 +376,36 @@ convert_keysym_state_to_string (const CcKeyCombo *combo)
return name;
}
+
+void
+normalize_keyval_and_mask (guint keyval,
+ GdkModifierType mask,
+ guint group,
+ guint *out_keyval,
+ GdkModifierType *out_mask)
+{
+ guint keyval_lower;
+ GdkModifierType real_mask;
+
+ real_mask = mask & gtk_accelerator_get_default_mod_mask ();
+
+ keyval_lower = gdk_keyval_to_lower (keyval);
+
+ /* Normalise <Tab> */
+ if (keyval_lower == GDK_KEY_ISO_Left_Tab)
+ keyval_lower = GDK_KEY_Tab;
+
+ /* Put shift back if it changed the case of the key, not otherwise. */
+ if (keyval_lower != keyval)
+ real_mask |= GDK_SHIFT_MASK;
+
+ if (keyval_lower == GDK_KEY_Sys_Req && (real_mask & GDK_ALT_MASK) != 0)
+ {
+ /* HACK: we don't want to use SysRq as a keybinding (but we do
+ * want Alt+Print), so we avoid translation from Alt+Print to SysRq */
+ keyval_lower = GDK_KEY_Print;
+ }
+
+ *out_keyval = keyval_lower;
+ *out_mask = real_mask;
+}
diff --git a/panels/keyboard/keyboard-shortcuts.h b/panels/keyboard/keyboard-shortcuts.h
index e8e98cb32..7c9b978a4 100644
--- a/panels/keyboard/keyboard-shortcuts.h
+++ b/panels/keyboard/keyboard-shortcuts.h
@@ -76,3 +76,9 @@ gboolean is_valid_accel (const CcKeyCombo *combo);
KeyList* parse_keylist_from_file (const gchar *path);
gchar* convert_keysym_state_to_string (const CcKeyCombo *combo);
+
+void normalize_keyval_and_mask (guint keyval,
+ GdkModifierType mask,
+ guint group,
+ guint *out_keyval,
+ GdkModifierType *out_mask);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]