X-Git-Url: https://git.xonotic.org/?a=blobdiff_plain;f=keys.c;h=9ff4853311313e4104819f30b990c603370b3f18;hb=ee008a1082f2579e1c758e83e845fba174f71b95;hp=3038eba6498bfa4c963b1018baa96bc28038939c;hpb=fa3eb39232d4615d785d738df81a9fa5905c9358;p=xonotic%2Fdarkplaces.git diff --git a/keys.c b/keys.c index 3038eba6..9ff48533 100644 --- a/keys.c +++ b/keys.c @@ -694,7 +694,7 @@ Interactive line editing and console scrollback ==================== */ -int chat_mode; // 0 for say, 1 for say_team, -1 for command +signed char chat_mode; // 0 for say, 1 for say_team, -1 for command char chat_buffer[MAX_INPUTLINE]; int chat_bufferpos = 0; @@ -782,7 +782,8 @@ int Key_Parse_CommonKeys(cmd_state_t *cmd, qbool is_console, int key, int unicod } else if (*p == '\n' || *p == '\r' || *p == '\b') *p++ = ';'; - p++; + else + p++; } #else strtok(cbd, "\n\r\b"); @@ -1350,6 +1351,7 @@ the K_* names are matched up. int Key_StringToKeynum (const char *str) { + Uchar ch; const keyname_t *kn; if (!str || !str[0]) @@ -1361,7 +1363,11 @@ Key_StringToKeynum (const char *str) if (!strcasecmp (str, kn->name)) return kn->keynum; } - return -1; + + // non-ascii keys are Unicode codepoints, so give the character if it's valid; + // error message have more than one character, don't allow it + ch = u8_getnchar(str, &str, 3); + return (ch == 0 || *str != 0) ? -1 : (int)ch; } /* @@ -1386,13 +1392,9 @@ Key_KeynumToString (int keynum, char *tinystr, size_t tinystrlength) return kn->name; // if it is printable, output it as a single character - if (keynum > 32 && keynum < 256) + if (keynum > 32) { - if (tinystrlength >= 2) - { - tinystr[0] = keynum; - tinystr[1] = 0; - } + u8_fromchar(keynum, tinystr, tinystrlength); return tinystr; } @@ -1585,7 +1587,7 @@ static void Key_PrintBindList(int j) { char bindbuf[MAX_INPUTLINE]; - char tinystr[2]; + char tinystr[TINYSTR_LEN]; const char *p; int i; @@ -1596,9 +1598,9 @@ Key_PrintBindList(int j) { Cmd_QuoteString(bindbuf, sizeof(bindbuf), p, "\"\\", false); if (j == 0) - Con_Printf("^2%s ^7= \"%s\"\n", Key_KeynumToString (i, tinystr, sizeof(tinystr)), bindbuf); + Con_Printf("^2%s ^7= \"%s\"\n", Key_KeynumToString (i, tinystr, TINYSTR_LEN), bindbuf); else - Con_Printf("^3bindmap %d: ^2%s ^7= \"%s\"\n", j, Key_KeynumToString (i, tinystr, sizeof(tinystr)), bindbuf); + Con_Printf("^3bindmap %d: ^2%s ^7= \"%s\"\n", j, Key_KeynumToString (i, tinystr, TINYSTR_LEN), bindbuf); } } } @@ -1678,7 +1680,7 @@ Key_WriteBindings (qfile_t *f) { int i, j; char bindbuf[MAX_INPUTLINE]; - char tinystr[2]; + char tinystr[TINYSTR_LEN]; const char *p; // Override default binds @@ -1693,9 +1695,9 @@ Key_WriteBindings (qfile_t *f) { Cmd_QuoteString(bindbuf, sizeof(bindbuf), p, "\"\\", false); // don't need to escape $ because cvars are not expanded inside bind if (j == 0) - FS_Printf(f, "bind %s \"%s\"\n", Key_KeynumToString (i, tinystr, sizeof(tinystr)), bindbuf); + FS_Printf(f, "bind %s \"%s\"\n", Key_KeynumToString (i, tinystr, TINYSTR_LEN), bindbuf); else - FS_Printf(f, "in_bind %d %s \"%s\"\n", j, Key_KeynumToString (i, tinystr, sizeof(tinystr)), bindbuf); + FS_Printf(f, "in_bind %d %s \"%s\"\n", j, Key_KeynumToString (i, tinystr, TINYSTR_LEN), bindbuf); } } } @@ -1831,7 +1833,7 @@ void Key_EventQueue_Unblock(void) void Key_Event (int key, int ascii, qbool down) { - cmd_state_t *cmd = &cmd_client; + cmd_state_t *cmd = cmd_local; const char *bind; qbool q; keydest_t keydest = key_dest; @@ -1909,7 +1911,7 @@ Key_Event (int key, int ascii, qbool down) { if(down) { - Con_ToggleConsole_f(&cmd_client); + Con_ToggleConsole_f(cmd_local); tbl_keydest[key] = key_void; // esc release should go nowhere (especially not to key_menu or key_game) } return; @@ -1928,7 +1930,7 @@ Key_Event (int key, int ascii, qbool down) #endif } else - Con_ToggleConsole_f(&cmd_client); + Con_ToggleConsole_f(cmd_local); } break; @@ -1970,14 +1972,12 @@ Key_Event (int key, int ascii, qbool down) { // button commands add keynum as a parm if (bind[0] == '+') - Cbuf_AddText (cmd, va(vabuf, sizeof(vabuf), "%s %i\n", bind, key)); + Cbuf_InsertText(cmd, va(vabuf, sizeof(vabuf), "%s %i\n", bind, key)); else - { - Cbuf_AddText (cmd, bind); - Cbuf_AddText (cmd, "\n"); - } - } else if(bind[0] == '+' && !down && keydown[key] == 0) - Cbuf_AddText(cmd, va(vabuf, sizeof(vabuf), "-%s %i\n", bind + 1, key)); + Cbuf_InsertText(cmd, bind); + } + else if(bind[0] == '+' && !down && keydown[key] == 0) + Cbuf_InsertText(cmd, va(vabuf, sizeof(vabuf), "-%s %i\n", bind + 1, key)); } return; } @@ -1992,7 +1992,7 @@ Key_Event (int key, int ascii, qbool down) // (special exemption for german keyboard layouts) if (con_closeontoggleconsole.integer && bind && !strncmp(bind, "toggleconsole", strlen("toggleconsole")) && (key_consoleactive & KEY_CONSOLEACTIVE_USER) && (con_closeontoggleconsole.integer >= ((ascii != STRING_COLOR_TAG) ? 2 : 3) || key_linepos == 1)) { - Con_ToggleConsole_f(&cmd_client); + Con_ToggleConsole_f(cmd_local); return; } @@ -2008,7 +2008,7 @@ Key_Event (int key, int ascii, qbool down) { if (down && con_closeontoggleconsole.integer && bind && !strncmp(bind, "toggleconsole", strlen("toggleconsole")) && ascii != STRING_COLOR_TAG) { - Cbuf_AddText(cmd, "toggleconsole\n"); // Deferred to next frame so we're not sending the text event to the console. + Cbuf_InsertText(cmd, "toggleconsole\n"); // Deferred to next frame so we're not sending the text event to the console. tbl_keydest[key] = key_void; // key release should go nowhere (especially not to key_menu or key_game) return; } @@ -2051,14 +2051,12 @@ Key_Event (int key, int ascii, qbool down) { // button commands add keynum as a parm if (bind[0] == '+') - Cbuf_AddText (cmd, va(vabuf, sizeof(vabuf), "%s %i\n", bind, key)); + Cbuf_InsertText(cmd, va(vabuf, sizeof(vabuf), "%s %i\n", bind, key)); else - { - Cbuf_AddText (cmd, bind); - Cbuf_AddText (cmd, "\n"); - } - } else if(bind[0] == '+' && !down && keydown[key] == 0) - Cbuf_AddText(cmd, va(vabuf, sizeof(vabuf), "-%s %i\n", bind + 1, key)); + Cbuf_InsertText(cmd, bind); + } + else if(bind[0] == '+' && !down && keydown[key] == 0) + Cbuf_InsertText(cmd, va(vabuf, sizeof(vabuf), "-%s %i\n", bind + 1, key)); } break; default: