Mercurial > pidgin
diff console/libgnt/gntstyle.c @ 15800:682022b8a129
Make sure unbound key-combinations are handled properly.
author | Sadrul Habib Chowdhury <imadil@gmail.com> |
---|---|
date | Fri, 16 Mar 2007 20:53:24 +0000 |
parents | 78ff267f50e3 |
children | 1c8f1dc50685 |
line wrap: on
line diff
--- a/console/libgnt/gntstyle.c Fri Mar 16 03:43:20 2007 +0000 +++ b/console/libgnt/gntstyle.c Fri Mar 16 20:53:24 2007 +0000 @@ -84,82 +84,7 @@ static char * parse_key(const char *key) { - char *ret = NULL; - int ctrl = 0, alt = 0; - char k; - - /* XXX: Need to do something about ctrl/alt+home, end etc. */ - -#define SPECIAL_KEY(k, code) do { \ - if (strcasecmp(key, k) == 0) \ - return g_strdup(code); \ - } while (0) - - SPECIAL_KEY("home", GNT_KEY_HOME); - SPECIAL_KEY("end", GNT_KEY_END); - SPECIAL_KEY("pageup", GNT_KEY_PGUP); - SPECIAL_KEY("pagedown", GNT_KEY_PGDOWN); - SPECIAL_KEY("insert", GNT_KEY_INS); - SPECIAL_KEY("delete", GNT_KEY_DEL); - - SPECIAL_KEY("left", GNT_KEY_LEFT); - SPECIAL_KEY("right", GNT_KEY_RIGHT); - SPECIAL_KEY("up", GNT_KEY_UP); - SPECIAL_KEY("down", GNT_KEY_DOWN); - - SPECIAL_KEY("tab", "\t"); - SPECIAL_KEY("menu", GNT_KEY_POPUP); - - SPECIAL_KEY("f1", GNT_KEY_F1); - SPECIAL_KEY("f2", GNT_KEY_F2); - SPECIAL_KEY("f3", GNT_KEY_F3); - SPECIAL_KEY("f4", GNT_KEY_F4); - SPECIAL_KEY("f5", GNT_KEY_F5); - SPECIAL_KEY("f6", GNT_KEY_F6); - SPECIAL_KEY("f7", GNT_KEY_F7); - SPECIAL_KEY("f8", GNT_KEY_F8); - SPECIAL_KEY("f9", GNT_KEY_F9); - SPECIAL_KEY("f10", GNT_KEY_F10); - SPECIAL_KEY("f11", GNT_KEY_F11); - SPECIAL_KEY("f12", GNT_KEY_F12); - -#undef SPECIAL_KEY - -#define MATCH(string, var) do { \ - if (strncasecmp(key, string, sizeof(string) - 1) == 0) { \ - key += sizeof(string) - 1; \ - var = 1; \ - } \ - }while (0) - - MATCH("c-", ctrl); - MATCH("ctl-", ctrl); - MATCH("ctr-", ctrl); - MATCH("ctrl-", ctrl); - - MATCH("alt-", alt); - MATCH("a-", alt); - MATCH("m-", alt); - MATCH("meta-", alt); - - if (strlen(key) != 1) /* We can only have stuff like "ctrl-alt-a" */ - return NULL; - - if (ctrl && !isalpha(*key)) { - /* These keys cannot be used with ctrl */ - return NULL; - } - - if (ctrl) - k = *key | 0x20; - else - k = *key; - - ret = g_strdup_printf("%s%c", alt ? "\033" : "", ctrl ? k - 0x60 : k); - -#undef MATCH - - return ret; + return gnt_key_translate(key); } void gnt_style_read_actions(GType type, GntBindableClass *klass) @@ -199,12 +124,11 @@ } else { - char *keycode = parse_key(key); + const char *keycode = parse_key(key); if (keycode == NULL) { g_printerr("GntStyle: Invalid key-binding %s\n", key); } else { gnt_bindable_register_binding(klass, action, keycode, NULL); - g_free(keycode); } } g_free(key);