[gnome-flashback] common: add support for shift_caps_switch
- From: Alberts Muktupāvels <muktupavels src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-flashback] common: add support for shift_caps_switch
- Date: Sat, 30 Nov 2019 22:59:32 +0000 (UTC)
commit 0e92128ca70b3c069552b4689a73633fc3762e12
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date: Sun Dec 1 00:52:00 2019 +0200
common: add support for shift_caps_switch
https://gitlab.gnome.org/GNOME/gnome-flashback/issues/24
gnome-flashback/libcommon/gf-keybindings.c | 143 +++++++++++++++++++++++++----
gnome-flashback/libcommon/gf-keybindings.h | 5 +-
2 files changed, 127 insertions(+), 21 deletions(-)
---
diff --git a/gnome-flashback/libcommon/gf-keybindings.c b/gnome-flashback/libcommon/gf-keybindings.c
index 911fc9a..5c173dc 100644
--- a/gnome-flashback/libcommon/gf-keybindings.c
+++ b/gnome-flashback/libcommon/gf-keybindings.c
@@ -53,15 +53,17 @@ struct _GfKeybindings
typedef struct
{
- gchar *name;
+ GfKeybindingType type;
- guint keyval;
- GdkModifierType modifiers;
+ gchar *name;
- guint keycode;
- guint mask;
+ guint keyval;
+ GdkModifierType modifiers;
- guint action;
+ guint keycode;
+ guint mask;
+
+ guint action;
} Keybinding;
enum
@@ -208,6 +210,7 @@ keybinding_new (const gchar *name,
Keybinding *keybinding;
keybinding = g_new0 (Keybinding, 1);
+ keybinding->type = GF_KEYBINDING_NONE;
keybinding->name = g_strdup (name);
@@ -222,6 +225,51 @@ keybinding_new (const gchar *name,
return keybinding;
}
+static Keybinding *
+iso_next_group_keybinding_new (guint keycode,
+ guint mask)
+{
+ Keybinding *keybinding;
+
+ keybinding = g_new0 (Keybinding, 1);
+ keybinding->type = GF_KEYBINDING_ISO_NEXT_GROUP;
+
+ keybinding->keycode = keycode;
+ keybinding->mask = mask;
+
+ return keybinding;
+}
+
+static Keybinding *
+iso_first_group_keybinding_new (guint keycode,
+ guint mask)
+{
+ Keybinding *keybinding;
+
+ keybinding = g_new0 (Keybinding, 1);
+ keybinding->type = GF_KEYBINDING_ISO_FIRST_GROUP;
+
+ keybinding->keycode = keycode;
+ keybinding->mask = mask;
+
+ return keybinding;
+}
+
+static Keybinding *
+iso_last_group_keybinding_new (guint keycode,
+ guint mask)
+{
+ Keybinding *keybinding;
+
+ keybinding = g_new0 (Keybinding, 1);
+ keybinding->type = GF_KEYBINDING_ISO_LAST_GROUP;
+
+ keybinding->keycode = keycode;
+ keybinding->mask = mask;
+
+ return keybinding;
+}
+
static void
keybinding_free (gpointer data)
{
@@ -310,9 +358,6 @@ reload_iso_group_keybindings (GfKeybindings *keybindings)
if (keybindings->iso_group == NULL)
return;
- n_keycodes = get_keycodes_for_keysym (keybindings, XK_ISO_Next_Group,
- &keycodes);
-
if (g_strcmp0 (keybindings->iso_group, "toggle") == 0 ||
g_strcmp0 (keybindings->iso_group, "lalt_toggle") == 0 ||
g_strcmp0 (keybindings->iso_group, "lwin_toggle") == 0 ||
@@ -325,89 +370,147 @@ reload_iso_group_keybindings (GfKeybindings *keybindings)
g_strcmp0 (keybindings->iso_group, "menu_toggle") == 0 ||
g_strcmp0 (keybindings->iso_group, "caps_toggle") == 0)
{
+ n_keycodes = get_keycodes_for_keysym (keybindings, XK_ISO_Next_Group,
+ &keycodes);
+
for (i = 0; i < n_keycodes; i++)
{
Keybinding *keybinding;
- keybinding = keybinding_new (NULL, 0, 0, keycodes[i], 0, 0);
+ keybinding = iso_next_group_keybinding_new (keycodes[i], 0);
g_hash_table_insert (keybindings->iso_group_keybindings,
GINT_TO_POINTER (i), keybinding);
}
+
+ g_free (keycodes);
}
else if (g_strcmp0 (keybindings->iso_group, "shift_caps_toggle") == 0 ||
g_strcmp0 (keybindings->iso_group, "shifts_toggle") == 0)
{
+ n_keycodes = get_keycodes_for_keysym (keybindings, XK_ISO_Next_Group,
+ &keycodes);
+
for (i = 0; i < n_keycodes; i++)
{
Keybinding *keybinding;
- keybinding = keybinding_new (NULL, 0, 0, keycodes[i], ShiftMask, 0);
+ keybinding = iso_next_group_keybinding_new (keycodes[i], ShiftMask);
g_hash_table_insert (keybindings->iso_group_keybindings,
GINT_TO_POINTER (i), keybinding);
}
+
+ g_free (keycodes);
}
else if (g_strcmp0 (keybindings->iso_group, "alt_caps_toggle") == 0 ||
g_strcmp0 (keybindings->iso_group, "alt_space_toggle") == 0)
{
+ n_keycodes = get_keycodes_for_keysym (keybindings, XK_ISO_Next_Group,
+ &keycodes);
+
for (i = 0; i < n_keycodes; i++)
{
Keybinding *keybinding;
- keybinding = keybinding_new (NULL, 0, 0, keycodes[i], Mod1Mask, 0);
+ keybinding = iso_next_group_keybinding_new (keycodes[i], Mod1Mask);
g_hash_table_insert (keybindings->iso_group_keybindings,
GINT_TO_POINTER (i), keybinding);
}
+
+ g_free (keycodes);
}
else if (g_strcmp0 (keybindings->iso_group, "ctrl_shift_toggle") == 0 ||
g_strcmp0 (keybindings->iso_group, "lctrl_lshift_toggle") == 0 ||
g_strcmp0 (keybindings->iso_group, "rctrl_rshift_toggle") == 0)
{
+ n_keycodes = get_keycodes_for_keysym (keybindings, XK_ISO_Next_Group,
+ &keycodes);
+
for (i = 0; i < n_keycodes; i++)
{
Keybinding *keybinding;
- keybinding = keybinding_new (NULL, 0, 0, keycodes[i], ShiftMask, 0);
+ keybinding = iso_next_group_keybinding_new (keycodes[i], ShiftMask);
g_hash_table_insert (keybindings->iso_group_keybindings,
GINT_TO_POINTER (i), keybinding);
- keybinding = keybinding_new (NULL, 0, 0, keycodes[i], ControlMask, 0);
+ keybinding = iso_next_group_keybinding_new (keycodes[i], ControlMask);
g_hash_table_insert (keybindings->iso_group_keybindings,
GINT_TO_POINTER (i + n_keycodes), keybinding);
}
+
+ g_free (keycodes);
}
else if (g_strcmp0 (keybindings->iso_group, "ctrl_alt_toggle") == 0)
{
+ n_keycodes = get_keycodes_for_keysym (keybindings, XK_ISO_Next_Group,
+ &keycodes);
+
for (i = 0; i < n_keycodes; i++)
{
Keybinding *keybinding;
- keybinding = keybinding_new (NULL, 0, 0, keycodes[i], Mod1Mask, 0);
+ keybinding = iso_next_group_keybinding_new (keycodes[i], Mod1Mask);
g_hash_table_insert (keybindings->iso_group_keybindings,
GINT_TO_POINTER (i), keybinding);
- keybinding = keybinding_new (NULL, 0, 0, keycodes[i], ControlMask, 0);
+ keybinding = iso_next_group_keybinding_new (keycodes[i], ControlMask);
g_hash_table_insert (keybindings->iso_group_keybindings,
GINT_TO_POINTER (i + n_keycodes), keybinding);
}
+
+ g_free (keycodes);
}
else if (g_strcmp0 (keybindings->iso_group, "alt_shift_toggle") == 0 ||
g_strcmp0 (keybindings->iso_group, "lalt_lshift_toggle") == 0)
{
+ n_keycodes = get_keycodes_for_keysym (keybindings, XK_ISO_Next_Group,
+ &keycodes);
+
for (i = 0; i < n_keycodes; i++)
{
Keybinding *keybinding;
- keybinding = keybinding_new (NULL, 0, 0, keycodes[i], Mod1Mask, 0);
+ keybinding = iso_next_group_keybinding_new (keycodes[i], Mod1Mask);
g_hash_table_insert (keybindings->iso_group_keybindings,
GINT_TO_POINTER (i), keybinding);
- keybinding = keybinding_new (NULL, 0, 0, keycodes[i], ShiftMask, 0);
+ keybinding = iso_next_group_keybinding_new (keycodes[i], ShiftMask);
g_hash_table_insert (keybindings->iso_group_keybindings,
GINT_TO_POINTER (i + n_keycodes), keybinding);
}
+
+ g_free (keycodes);
}
+ /* Caps Lock to first layout; Shift+Caps Lock to last layout */
+ else if (g_strcmp0 (keybindings->iso_group, "shift_caps_switch") == 0)
+ {
+ n_keycodes = get_keycodes_for_keysym (keybindings, XK_ISO_First_Group,
+ &keycodes);
+
+ for (i = 0; i < n_keycodes; i++)
+ {
+ Keybinding *keybinding;
- g_free (keycodes);
+ keybinding = iso_first_group_keybinding_new (keycodes[i], 0);
+ g_hash_table_insert (keybindings->iso_group_keybindings,
+ GINT_TO_POINTER (i), keybinding);
+ }
+
+ g_free (keycodes);
+ n_keycodes = get_keycodes_for_keysym (keybindings, XK_ISO_Last_Group,
+ &keycodes);
+
+ for (i = 0; i < n_keycodes; i++)
+ {
+ Keybinding *keybinding;
+
+ keybinding = iso_last_group_keybinding_new (keycodes[i], ShiftMask);
+ g_hash_table_insert (keybindings->iso_group_keybindings,
+ GINT_TO_POINTER (i + n_keycodes), keybinding);
+ }
+
+ g_free (keycodes);
+ }
}
static void
@@ -568,7 +671,7 @@ process_iso_group (GfKeybindings *keybindings,
g_signal_emit (keybindings,
signals[SIGNAL_MODIFIERS_ACCELERATOR_ACTIVATED],
0,
- GF_KEYBINDING_ISO_NEXT_GROUP,
+ keybinding->type,
&freeze);
if (!freeze)
diff --git a/gnome-flashback/libcommon/gf-keybindings.h b/gnome-flashback/libcommon/gf-keybindings.h
index 836b77d..916e26a 100644
--- a/gnome-flashback/libcommon/gf-keybindings.h
+++ b/gnome-flashback/libcommon/gf-keybindings.h
@@ -25,7 +25,10 @@ G_BEGIN_DECLS
typedef enum
{
- GF_KEYBINDING_ISO_NEXT_GROUP
+ GF_KEYBINDING_NONE,
+ GF_KEYBINDING_ISO_NEXT_GROUP,
+ GF_KEYBINDING_ISO_FIRST_GROUP,
+ GF_KEYBINDING_ISO_LAST_GROUP
} GfKeybindingType;
#define GF_TYPE_KEYBINDINGS gf_keybindings_get_type ()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]