]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - keys.c
Add an in_releaseall command for debugging/working around stuck keys.
[xonotic/darkplaces.git] / keys.c
diff --git a/keys.c b/keys.c
index 62db167516af5338caa42a311852266af01c0a71..e93f83ac95504136e3605ce7a1ba0a15ae0faf67 100644 (file)
--- a/keys.c
+++ b/keys.c
@@ -753,21 +753,6 @@ Key_Console (int key, int unicode)
                                i= MAX_INPUTLINE - key_linepos - 1;
                        if (i > 0)
                        {
-                               // terencehill: insert the clipboard text between the characters of the line
-                               /*
-                               char *temp = (char *) Z_Malloc(MAX_INPUTLINE);
-                               cbd[i]=0;
-                               temp[0]=0;
-                               if ( key_linepos < (int)strlen(key_line) )
-                                       strlcpy(temp, key_line + key_linepos, (int)strlen(key_line) - key_linepos +1);
-                               key_line[key_linepos] = 0;
-                               strlcat(key_line, cbd, sizeof(key_line));
-                               if (temp[0])
-                                       strlcat(key_line, temp, sizeof(key_line));
-                               Z_Free(temp);
-                               key_linepos += i;
-                               */
-                               // blub: I'm changing this to use memmove() like the rest of the code does.
                                cbd[i] = 0;
                                memmove(key_line + key_linepos + i, key_line + key_linepos, sizeof(key_line) - key_linepos - i);
                                memcpy(key_line + key_linepos, cbd, i);
@@ -1050,7 +1035,6 @@ Key_Console (int key, int unicode)
                Key_History_Down();
                return;
        }
-       // ~1.0795 = 82/76  using con_textsize 64 76 is height of the char, 6 is the distance between 2 lines
 
        if (keydown[K_CTRL])
        {
@@ -1186,24 +1170,21 @@ Key_Console (int key, int unicode)
                // check insert mode, or always insert if at end of line
                if (key_insert || len == 0)
                {
+                       if (key_linepos + len + blen >= MAX_INPUTLINE)
+                               return;
                        // can't use strcpy to move string to right
                        len++;
-                       //memmove(&key_line[key_linepos + u8_bytelen(key_line + key_linepos, 1)], &key_line[key_linepos], len);
                        if (key_linepos + blen + len >= MAX_INPUTLINE)
                                return;
                        memmove(&key_line[key_linepos + blen], &key_line[key_linepos], len);
                }
-               // FIXME: This is not proper overwriting with utf8.
-               if (key_linepos + blen >= MAX_INPUTLINE)
+               else if (key_linepos + len + blen - u8_bytelen(key_line + key_linepos, 1) >= MAX_INPUTLINE)
                        return;
                memcpy(key_line + key_linepos, buf, blen);
                if (blen > len)
                        key_line[key_linepos + blen] = 0;
                // END OF FIXME
                key_linepos += blen;
-               //key_linepos += u8_fromchar(unicode, key_line + key_linepos, sizeof(key_line) - key_linepos - 1);
-               //key_line[key_linepos] = ascii;
-               //key_linepos++;
        }
 }
 
@@ -1217,7 +1198,7 @@ static void
 Key_Message (int key, int ascii)
 {
        char vabuf[1024];
-       if (key == K_ENTER || ascii == 10 || ascii == 13)
+       if (key == K_ENTER || key == K_KP_ENTER || ascii == 10 || ascii == 13)
        {
                if(chat_mode < 0)
                        Cmd_ExecuteString(chat_buffer, src_command, true); // not Cbuf_AddText to allow semiclons in args; however, this allows no variables then. Use aliases!
@@ -1645,6 +1626,7 @@ Key_Init (void)
        Cmd_AddCommand ("in_unbind", Key_In_Unbind_f, "removes command on the specified key in the selected bindmap");
        Cmd_AddCommand ("in_bindlist", Key_In_BindList_f, "bindlist: displays bound keys for all bindmaps, or the given bindmap");
        Cmd_AddCommand ("in_bindmap", Key_In_Bindmap_f, "selects active foreground and background (used only if a key is not bound in the foreground) bindmaps for typing");
+       Cmd_AddCommand ("in_releaseall", Key_ReleaseAll, "releases all currently pressed keys (debug command)");
 
        Cmd_AddCommand ("bind", Key_Bind_f, "binds a command to the specified key in bindmap 0");
        Cmd_AddCommand ("unbind", Key_Unbind_f, "removes a command on the specified key in bindmap 0");
@@ -1936,7 +1918,7 @@ Key_Event (int key, int ascii, qboolean down)
        {
                if (down && con_closeontoggleconsole.integer && bind && !strncmp(bind, "toggleconsole", strlen("toggleconsole")) && ascii != STRING_COLOR_TAG)
                {
-                       Con_ToggleConsole_f ();
+                       Cbuf_AddText("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;
                }
@@ -2008,14 +1990,3 @@ Key_ReleaseAll (void)
        // now all keys are guaranteed down (once the event queue is unblocked)
        // and only future events count
 }
-
-/*
-===================
-Key_ClearStates
-===================
-*/
-void
-Key_ClearStates (void)
-{
-       memset(keydown, 0, sizeof(keydown));
-}