#include "command.h"
#include "completion.h"
+static void keybind_rebuild_modkeys(void);
static GSList* keybind_find(int mode, guint modkey, guint modmask, guint keyval);
static void keybind_str_to_keybind(gchar* str, Keybind* key);
static guint keybind_str_to_modmask(const gchar* str);
/* add the keybinding to the list */
vp.behave.keys = g_slist_prepend(vp.behave.keys, keybind);
- /* save the modkey also in the modkey string */
- if (keybind->modkey) {
+ /* save the modkey also in the modkey string if not exists already */
+ if (keybind->modkey && strchr(vp.behave.modkeys->str, keybind->modkey) == NULL) {
g_string_append_c(vp.behave.modkeys, keybind->modkey);
}
result = TRUE;
if (link) {
vp.behave.keys = g_slist_delete_link(vp.behave.keys, link);
}
- /* TODO remove eventually no more used modkeys */
+
+ if (keybind.modkey && strchr(vp.behave.modkeys->str, keybind.modkey) != NULL) {
+ /* remove eventually no more used modkeys */
+ keybind_rebuild_modkeys();
+ }
return TRUE;
}
+/**
+ * Discard all knows modkeys and walk through all keybindings to aggregate
+ * them new.
+ */
+static void keybind_rebuild_modkeys(void)
+{
+ GSList* link;
+ /* remove previous modkeys */
+ if (vp.behave.modkeys) {
+ g_string_free(vp.behave.modkeys, TRUE);
+ vp.behave.modkeys = g_string_new("");
+ }
+
+ /* regenerate the modekeys */
+ for (link = vp.behave.keys; link != NULL; link = link->next) {
+ Keybind* keybind = (Keybind*)link->data;
+ /* if not not exists - add it */
+ if (keybind->modkey && strchr(vp.behave.modkeys->str, keybind->modkey) == NULL) {
+ g_string_append_c(vp.behave.modkeys, keybind->modkey);
+ }
+ }
+}
+
static GSList* keybind_find(int mode, guint modkey, guint modmask, guint keyval)
{
GSList* link;
for (link = vp.behave.keys; link != NULL; link = link->next) {
Keybind* keybind = (Keybind*)link->data;
if (keybind->keyval == keyval
- && keybind->modmask == modmask
- && keybind->modkey == modkey
- && keybind->mode == mode) {
+ && keybind->modmask == modmask
+ && keybind->modkey == modkey
+ && keybind->mode == mode
+ ) {
return link;
}
}