From babde54b9962aad735a990c648ae3aae0ae928b4 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Thu, 1 Mar 2012 19:37:47 +0800 Subject: [PATCH] Kernel/VTerm - Fixing meta-key handling --- KernelLand/Kernel/drv/vterm.h | 1 + KernelLand/Kernel/drv/vterm_input.c | 169 +++++++++++------- .../Modules/Input/Keyboard/layout_kbdus.h | 30 ++-- 3 files changed, 121 insertions(+), 79 deletions(-) diff --git a/KernelLand/Kernel/drv/vterm.h b/KernelLand/Kernel/drv/vterm.h index cd37ebd9..00fbb7a6 100644 --- a/KernelLand/Kernel/drv/vterm.h +++ b/KernelLand/Kernel/drv/vterm.h @@ -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; diff --git a/KernelLand/Kernel/drv/vterm_input.c b/KernelLand/Kernel/drv/vterm_input.c index d83cedee..a037b34c 100644 --- a/KernelLand/Kernel/drv/vterm_input.c +++ b/KernelLand/Kernel/drv/vterm_input.c @@ -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) ) diff --git a/KernelLand/Modules/Input/Keyboard/layout_kbdus.h b/KernelLand/Modules/Input/Keyboard/layout_kbdus.h index 0809407e..f84b0ce8 100644 --- a/KernelLand/Modules/Input/Keyboard/layout_kbdus.h +++ b/KernelLand/Modules/Input/Keyboard/layout_kbdus.h @@ -1,4 +1,12 @@ - +/* + * Acess2 Keyboard Driver + * - By John Hodge (thePowersGang) + * + * layout_kbdus.h + * - US Keyboard Layout + * + * TODO: Support Num-Lock + */ #ifndef _KEYMAP__LAYOUT_KBDUS_H_ #define _KEYMAP__LAYOUT_KBDUS_H_ @@ -14,14 +22,15 @@ tKeymapLayer gpKBDUS1 = { '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '\n', '\x1b', '\b', '\t', ' ', '-', '=', '[', ']', '\\', '#', ';', '\'', '`', ',', '.', '/', -// KEY_CAPSLOCK, -// KEY_F1, KEY_F2, KEY_F3, KEY_F4, KEY_F5, KEY_F6, -// KEY_F7, KEY_F8, KEY_F9, KEY_F10, KEY_F11, KEY_F12, -// 0, KEY_SCROLLLOCK, KEY_PAUSE, KEY_INS, KEY_HOME, KEY_PGUP, KEY_PGDOWN, -// KEY_RIGHT, KEY_LEFT, KEY_UP, KEY_DOWN, -// KEY_NUMLOCK, KEY_KPSLASH, KEY_KPSTAR, KEY_KPMINUS, -// KEY_KPPLUS, KEY_KPENTER, -// KEY_KPEND, KEY_KPDOWN, KEY_KPLEFT, + 0, // Capslock + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // F1 -> F12 + 0, 0, 0, 0, 0, 0, 0, // ?, ScrollLock, Pause, Insert, Home, PgUp, PgDn + 0, 0, 0, 0, // Right, Left, Up, Down + 0, '/', '*', '-', '+', '\n', // NumLock, Keypad /, *, -, +, Enter +// KEYSYM_KPEND, KEYSYM_KPDOWN, KEYSYM_KPPGDN, +// KEYSYM_KPLEFT, KEYSYM_KP5, KEY_KPRIGHT, +// KEYSYM_KPHOME, KEYSYM_KPUP, KEYSYM_KPPGUP, +// KEYSYM_PKINS, KEYSYM_KPDEL } }; tKeymapLayer gpKBDUS1s = { @@ -38,8 +47,7 @@ tKeymapLayer gpKBDUS1s = { tKeymap gKeymap_KBDUS = { "en-us", - 2, - {&gpKBDUS1, &gpKBDUS1s} + 2, {&gpKBDUS1, &gpKBDUS1s} }; #endif -- 2.20.1