# HG changeset patch # User Mikael Berthe # Date 1142780440 -3600 # Node ID 4e15322d315e6f14cb358de3cdf63dbd7cc346d9 # Parent 6866ee749225755f91ae4e2aea84ad29535958e3 Allow binding of meta keys diff -r 6866ee749225 -r 4e15322d315e mcabber/src/screen.c --- a/mcabber/src/screen.c Sun Mar 19 15:59:14 2006 +0100 +++ b/mcabber/src/screen.c Sun Mar 19 16:00:40 2006 +0100 @@ -2020,6 +2020,34 @@ return; } +static int bindcommand(keycode kcode) { + gchar asciikey[16]; + const gchar *boundcmd; + + if (!kcode.mcode || kcode.mcode == MKEY_EQUIV) + g_snprintf(asciikey, 15, "%d", kcode.value); + else if (kcode.mcode == MKEY_META) + g_snprintf(asciikey, 15, "M%d", kcode.value); + else + g_snprintf(asciikey, 15, "MK%d", kcode.mcode); + + boundcmd = settings_get(SETTINGS_TYPE_BINDING, asciikey); + + if (boundcmd) { + gchar *cmd = g_strdup_printf("/%s", boundcmd); + scr_CheckAutoAway(TRUE); + if (process_command(cmd)) + return 255; // Quit + g_free(cmd); + return 0; + } + + scr_LogPrint(LPRINT_NORMAL, "Unknown key=%s", asciikey); + if (utf8_mode) + scr_LogPrint(LPRINT_NORMAL, "WARNING: UTF-8 not yet supported!"); + return -1; +} + // process_key(key) // Handle the pressed key, in the command line (bottom). int process_key(keycode kcode) @@ -2039,12 +2067,14 @@ key = 27; break; default: - scr_LogPrint(LPRINT_NORMAL, "Unknown key=M%d", kcode.value); + if (bindcommand(kcode) == 255) + return 255; } break; default: - scr_LogPrint(LPRINT_NORMAL, "Unknown mkeycode! (%d)", kcode.mcode); - key = ERR; + if (bindcommand(kcode) == 255) + return 255; + key = ERR; // Do not process any further } switch (key) { @@ -2211,19 +2241,9 @@ strcpy(ptr_inputline, tmpLine); check_offset(1); } else { - const gchar *boundcmd = isbound(key); - if (boundcmd) { - gchar *cmd = g_strdup_printf("/%s", boundcmd); - scr_CheckAutoAway(TRUE); - if (process_command(cmd)) - return 255; - g_free(cmd); - } else { - scr_LogPrint(LPRINT_NORMAL, "Unknown key=%d", key); - if (utf8_mode) - scr_LogPrint(LPRINT_NORMAL, - "WARNING: UTF-8 not yet supported!"); - } + // Look for a key binding. + if (bindcommand(kcode) == 255) + return 255; } } diff -r 6866ee749225 -r 4e15322d315e mcabber/src/settings.c --- a/mcabber/src/settings.c Sun Mar 19 15:59:14 2006 +0100 +++ b/mcabber/src/settings.c Sun Mar 19 16:00:40 2006 +0100 @@ -284,14 +284,6 @@ return 0; } -// Return the command the key is bound to, or NULL. -const gchar *isbound(int key) -{ - gchar asciikey[16]; - g_snprintf(asciikey, 15, "%d", key); - return settings_get(SETTINGS_TYPE_BINDING, asciikey); -} - // settings_get_status_msg(status) // Return a string with the current status message: // - if there is a user-defined message ("message" option),