Kernel/VTerm - Fixing meta-key handling
authorJohn Hodge <[email protected]>
Thu, 1 Mar 2012 11:37:47 +0000 (19:37 +0800)
committerJohn Hodge <[email protected]>
Thu, 1 Mar 2012 11:37:47 +0000 (19:37 +0800)
KernelLand/Kernel/drv/vterm.h
KernelLand/Kernel/drv/vterm_input.c
KernelLand/Modules/Input/Keyboard/layout_kbdus.h

index cd37ebd..00fbb7a 100644 (file)
@@ -72,6 +72,7 @@ struct sVTerm
         int    InputRead;      //!< Input buffer read position
         int    InputWrite;     //!< Input buffer write position
        char    InputBuffer[MAX_INPUT_CHARS8];
+       Uint32  RawScancode;    //!< last raw scancode recieved
 //     tSemaphore      InputSemaphore;
        
        Uint32          *Buffer;
index d83cede..a037b34 100644 (file)
@@ -45,64 +45,66 @@ void VT_KBCallBack(Uint32 Codepoint)
        // Catch VT binds
        switch( Codepoint & KEY_ACTION_MASK )
        {
+       case KEY_ACTION_RAWSYM:
+               term->RawScancode = Codepoint & KEY_CODEPOINT_MASK;
+               break;
        case KEY_ACTION_RELEASE:
-               switch(Codepoint & KEY_CODEPOINT_MASK)
+               switch(term->RawScancode)
                {
-               case KEY_LALT:  gbVT_AltDown &= ~1;     break;
-               case KEY_RALT:  gbVT_AltDown &= ~2;     break;
-               case KEY_LCTRL: gbVT_CtrlDown &= ~1;    break;
-               case KEY_RCTRL: gbVT_CtrlDown &= ~2;    break;
+               case KEYSYM_LEFTALT:    gbVT_AltDown &= ~1;     break;
+               case KEYSYM_RIGHTALT:   gbVT_AltDown &= ~2;     break;
+               case KEYSYM_LEFTCTRL:   gbVT_CtrlDown &= ~1;    break;
+               case KEYSYM_RIGHTCTRL:  gbVT_CtrlDown &= ~2;    break;
                }
                break;
        
        case KEY_ACTION_PRESS:
-               switch(Codepoint & KEY_CODEPOINT_MASK)
+               switch(term->RawScancode)
                {
-               case KEY_LALT:  gbVT_AltDown |= 1;      break;
-               case KEY_RALT:  gbVT_AltDown |= 2;      break;
-               case KEY_LCTRL: gbVT_CtrlDown |= 1;     break;
-               case KEY_RCTRL: gbVT_CtrlDown |= 2;     break;
+               case KEYSYM_LEFTALT:    gbVT_AltDown |= 1;      break;
+               case KEYSYM_RIGHTALT:   gbVT_AltDown |= 2;      break;
+               case KEYSYM_LEFTCTRL:   gbVT_CtrlDown |= 1;     break;
+               case KEYSYM_RIGHTCTRL:  gbVT_CtrlDown |= 2;     break;
                }
                
+               // Check if the magic keys are held
                if(!gbVT_AltDown || !gbVT_CtrlDown)
                        break;
-               switch(Codepoint & KEY_CODEPOINT_MASK)
+               
+               switch(term->RawScancode)
                {
-               case KEY_F1:    VT_SetTerminal(0);      return;
-               case KEY_F2:    VT_SetTerminal(1);      return;
-               case KEY_F3:    VT_SetTerminal(2);      return;
-               case KEY_F4:    VT_SetTerminal(3);      return;
-               case KEY_F5:    VT_SetTerminal(4);      return;
-               case KEY_F6:    VT_SetTerminal(5);      return;
-               case KEY_F7:    VT_SetTerminal(6);      return;
-               case KEY_F8:    VT_SetTerminal(7);      return;
-               case KEY_F9:    VT_SetTerminal(8);      return;
-               case KEY_F10:   VT_SetTerminal(9);      return;
-               case KEY_F11:   VT_SetTerminal(10);     return;
-               case KEY_F12:   VT_SetTerminal(11);     return;
+               case KEYSYM_F1 :        VT_SetTerminal(0);      return;
+               case KEYSYM_F2 :        VT_SetTerminal(1);      return;
+               case KEYSYM_F3 :        VT_SetTerminal(2);      return;
+               case KEYSYM_F4 :        VT_SetTerminal(3);      return;
+               case KEYSYM_F5 :        VT_SetTerminal(4);      return;
+               case KEYSYM_F6 :        VT_SetTerminal(5);      return;
+               case KEYSYM_F7 :        VT_SetTerminal(6);      return;
+               case KEYSYM_F8 :        VT_SetTerminal(7);      return;
+               case KEYSYM_F9 :        VT_SetTerminal(8);      return;
+               case KEYSYM_F10:        VT_SetTerminal(9);      return;
+               case KEYSYM_F11:        VT_SetTerminal(10);     return;
+               case KEYSYM_F12:        VT_SetTerminal(11);     return;
                }
                
                // Scrolling is only valid in text mode
-               if(gpVT_CurTerm->Mode != TERM_MODE_TEXT)
+               if(term->Mode != TERM_MODE_TEXT)
                        break;
                
-               switch(Codepoint & KEY_CODEPOINT_MASK)
+               switch(term->RawScancode)
                {
                // Scrolling
-               case KEY_PGUP:
-                       if( gpVT_CurTerm->Flags & VT_FLAG_ALTBUF )
+               case KEYSYM_PGUP:
+                       if( term->Flags & VT_FLAG_ALTBUF )
                                return ;
-                       gpVT_CurTerm->ViewPos = MAX(
-                               0,
-                               gpVT_CurTerm->ViewPos - gpVT_CurTerm->Width
-                               );
+                       term->ViewPos = MAX( 0, term->ViewPos - term->Width );
                        return;
-               case KEY_PGDOWN:
-                       if( gpVT_CurTerm->Flags & VT_FLAG_ALTBUF )
+               case KEYSYM_PGDN:
+                       if( term->Flags & VT_FLAG_ALTBUF )
                                return ;
-                       gpVT_CurTerm->ViewPos = MIN(
-                               gpVT_CurTerm->ViewPos + gpVT_CurTerm->Width,
-                               gpVT_CurTerm->Width * gpVT_CurTerm->Height*giVT_Scrollback
+                       term->ViewPos = MIN(
+                               term->ViewPos + term->Width,
+                               term->Width * term->Height * giVT_Scrollback
                                );
                        return;
                }
@@ -129,43 +131,73 @@ void VT_KBCallBack(Uint32 Codepoint)
                if(Codepoint > KEY_MODIFIERS)   return;
                
                // Get UTF-8/ANSI Encoding
-               switch(Codepoint)
+               if( Codepoint == 0 )
                {
-               // 0: No translation, don't send to user
-               case 0: break;
-               case KEY_LEFT:
-                       buf[0] = '\x1B'; buf[1] = '['; buf[2] = 'D';
-                       len = 3;
-                       break;
-               case KEY_RIGHT:
-                       buf[0] = '\x1B'; buf[1] = '['; buf[2] = 'C';
-                       len = 3;
-                       break;
-               case KEY_UP:
-                       buf[0] = '\x1B'; buf[1] = '['; buf[2] = 'A';
-                       len = 3;
-                       break;
-               case KEY_DOWN:
-                       buf[0] = '\x1B'; buf[1] = '['; buf[2] = 'B';
-                       len = 3;
-                       break;
-               
-               case KEY_PGUP:
-                       buf[0] = '\x1B'; buf[1] = '['; buf[2] = '5'; buf[3] = '~';
-                       len = 4;
-                       break;
-               case KEY_PGDOWN:
-                       buf[0] = '\x1B'; buf[1] = '['; buf[2] = '6'; buf[3] = '~';
-                       len = 4;
-                       break;
-               
-               // Attempt to encode in UTF-8
-               default:
+                       // Non-printable keys
+                       switch(term->RawScancode)
+                       {
+                       case KEYSYM_LEFTARROW:
+                       case KEYSYM_KP4:
+                               buf[0] = '\x1B'; buf[1] = '['; buf[2] = 'D';
+                               len = 3;
+                               break;
+                       case KEYSYM_RIGHTARROW:
+                       case KEYSYM_KP6:
+                               buf[0] = '\x1B'; buf[1] = '['; buf[2] = 'C';
+                               len = 3;
+                               break;
+                       case KEYSYM_UPARROW:
+                       case KEYSYM_KP8:
+                               buf[0] = '\x1B'; buf[1] = '['; buf[2] = 'A';
+                               len = 3;
+                               break;
+                       case KEYSYM_DOWNARROW:
+                       case KEYSYM_KP2:
+                               buf[0] = '\x1B'; buf[1] = '['; buf[2] = 'B';
+                               len = 3;
+                               break;
+                       
+                       case KEYSYM_PGUP:
+                       case KEYSYM_KP9:        // If Codepoint=0, It's page up
+                               buf[0] = '\x1B'; buf[1] = '['; buf[2] = '5'; buf[3] = '~';
+                               len = 4;
+                               break;
+                       case KEYSYM_PGDN:
+                       case KEYSYM_KP3:        // If Codepoint=0, It's page down
+                               buf[0] = '\x1B'; buf[1] = '['; buf[2] = '6'; buf[3] = '~';
+                               len = 4;
+                               break;
+                       
+                       case KEYSYM_HOME:
+                       case KEYSYM_KP7:
+                               buf[0] = '\x1B'; buf[1] = 'O'; buf[2] = 'H';
+                               len = 3;
+                               break;
+                       case KEYSYM_END:
+                       case KEYSYM_KP1:
+                               buf[0] = '\x1B'; buf[1] = 'O'; buf[2] = 'F';
+                               len = 3;
+                               break;
+                       
+                       case KEYSYM_INSERT:
+                       case KEYSYM_KP0:
+                               buf[0] = '\x1B'; buf[1] = '['; buf[2] = '2'; buf[3] = '~';
+                               len = 4;
+                               break;
+                       case KEYSYM_DELETE:
+                       case KEYSYM_KPPERIOD:
+                               buf[0] = '\x1B'; buf[1] = '['; buf[2] = '3'; buf[3] = '~';
+                               len = 4;
+                               break;
+                       }
+               }
+               else
+               {
+                       // Attempt to encode in UTF-8
                        len = WriteUTF8( buf, Codepoint );
                        if(len == 0) {
                                Warning("Codepoint (%x) is unrepresentable in UTF-8", Codepoint);
                        }
-                       break;
                }
                
                if(len == 0) {
@@ -173,6 +205,7 @@ void VT_KBCallBack(Uint32 Codepoint)
                        return;
                }
 
+               // TODO: Implement Ctrl-C etc
 #if 0
                // Handle meta characters
                if( !(term->Flags & VT_FLAG_RAWIN) )
index 0809407..f84b0ce 100644 (file)
@@ -1,4 +1,12 @@
-\r
+/*\r
+ * Acess2 Keyboard Driver\r
+ * - By John Hodge (thePowersGang)\r
+ *\r
+ * layout_kbdus.h\r
+ * - US Keyboard Layout\r
+ *\r
+ * TODO: Support Num-Lock\r
+ */\r
 #ifndef _KEYMAP__LAYOUT_KBDUS_H_\r
 #define _KEYMAP__LAYOUT_KBDUS_H_\r
 \r
@@ -14,14 +22,15 @@ tKeymapLayer        gpKBDUS1 = {
        '1', '2', '3', '4', '5', '6', '7', '8', '9', '0',\r
        '\n', '\x1b', '\b', '\t', ' ', '-', '=', '[', ']', '\\', '#', ';',\r
        '\'', '`', ',', '.', '/',\r
-//     KEY_CAPSLOCK,\r
-//     KEY_F1, KEY_F2, KEY_F3, KEY_F4, KEY_F5, KEY_F6,\r
-//     KEY_F7, KEY_F8, KEY_F9, KEY_F10, KEY_F11, KEY_F12,\r
-//     0, KEY_SCROLLLOCK, KEY_PAUSE, KEY_INS, KEY_HOME, KEY_PGUP, KEY_PGDOWN,\r
-//     KEY_RIGHT, KEY_LEFT, KEY_UP, KEY_DOWN,\r
-//     KEY_NUMLOCK, KEY_KPSLASH, KEY_KPSTAR, KEY_KPMINUS,\r
-//     KEY_KPPLUS, KEY_KPENTER,\r
-//     KEY_KPEND, KEY_KPDOWN, KEY_KPLEFT,\r
+       0,      // Capslock\r
+       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,     // F1 -> F12\r
+       0, 0, 0, 0, 0, 0, 0,    // ?, ScrollLock, Pause, Insert, Home, PgUp, PgDn\r
+       0, 0, 0, 0,     // Right, Left, Up, Down\r
+       0, '/', '*', '-', '+', '\n',    // NumLock, Keypad /, *, -, +, Enter\r
+//     KEYSYM_KPEND, KEYSYM_KPDOWN, KEYSYM_KPPGDN,\r
+//     KEYSYM_KPLEFT, KEYSYM_KP5, KEY_KPRIGHT,\r
+//     KEYSYM_KPHOME, KEYSYM_KPUP, KEYSYM_KPPGUP,\r
+//     KEYSYM_PKINS, KEYSYM_KPDEL\r
        }\r
 };\r
 tKeymapLayer   gpKBDUS1s = {\r
@@ -38,8 +47,7 @@ tKeymapLayer  gpKBDUS1s = {
 \r
 tKeymap        gKeymap_KBDUS = {\r
        "en-us",\r
-       2,\r
-       {&gpKBDUS1, &gpKBDUS1s}\r
+       2, {&gpKBDUS1, &gpKBDUS1s}\r
 };\r
 \r
 #endif\r

UCC git Repository :: git.ucc.asn.au