ENIGMA Forums

Outsourcing saves money => Issues Help Desk => Topic started by: ssss on June 10, 2013, 12:09:42 AM

Title: X11 keyboard numpad and function keys corrupted by lookup in usermap with fix
Post by: ssss on June 10, 2013, 12:09:42 AM
The value for special vk_ keys is looked up from X keysym in enigma::keymap. The array enigma::usermap is set in ENIGMAsystem/SHELL/Platforms/xlib/XLIBwindow.cpp line 367:

Code: [Select]
for (int i = 'a'; i <= 'z'; i++) // 'a' to 'z' wrap to 'A' to 'Z'
      usermap[i] = i + 'A' - 'a';

In ENIGMAsystem/SHELL/Platforms/xlib/XLIBmain.cpp line 70 the result keycode should not be looked up through enigma::usermap because it changes lowercase to uppercase, corrupting the meaning of vk_ codes for numpad and function keys between vk_numpad1 = 97 and vk_f11 = 122. Diff fixes the problem:

Code: [Select]
--- a/ENIGMAsystem/SHELL/Platforms/xlib/XLIBmain.cpp
+++ b/ENIGMAsystem/SHELL/Platforms/xlib/XLIBmain.cpp
@@ -69,7 +69,8 @@ namespace enigma
                 return 0;
 
               if (!(gk & 0xFF00)) actualKey = enigma::usermap[gk];
-              else actualKey = enigma::usermap[(int)enigma::keymap[gk & 0xFF]];
+              else actualKey = (int)enigma::keymap[gk & 0xFF];
+              //else actualKey = enigma::usermap[(int)enigma::keymap[gk & 0xFF]];
               { // Set keyboard_lastchar. Seems to work without
                   char str[1];
                   int len = XLookupString(&e.xkey, str, 1, NULL, NULL);
@@ -91,7 +92,8 @@ namespace enigma
               return 0;
 
             if (!(gk & 0xFF00)) actualKey = enigma::usermap[gk];
-            else actualKey = enigma::usermap[(int)enigma::keymap[gk & 0xFF]];
+            else actualKey = (int)enigma::keymap[gk & 0xFF];
 
             enigma::last_keybdstatus[actualKey]=enigma::keybdstatus[actualKey];
             enigma::keybdstatus[actualKey]=0;

Keys affected were:

vk_numpad1 = 97,
  vk_numpad2 = 98,
  vk_numpad3 = 99,
  vk_numpad4 = 100,
  vk_numpad5 = 101,
  vk_numpad6 = 102,
  vk_numpad7 = 103,
  vk_numpad8 = 104,
  vk_numpad9 = 105,
  vk_multiply = 106,
  vk_add      = 107,
  vk_subtract = 109,
  vk_decimal  = 110,
  vk_divide   = 111,
  vk_f1  = 112,
  vk_f2  = 113,
  vk_f3  = 114,
  vk_f4  = 115,
  vk_f5  = 116,
  vk_f6  = 117,
  vk_f7  = 118,
  vk_f8  = 119,
  vk_f9  = 120,
  vk_f10 = 121,
  vk_f11 = 122,

Tracker screwed up my text but the issue is here http://enigma-dev.org/issues/index.php?id=194
Title: Re: X11 keyboard numpad and function keys corrupted by lookup in usermap with fix
Post by: TheExDeus on June 10, 2013, 03:51:26 AM
1) I think you should try GIT tracker (https://github.com/enigma-dev/enigma-dev/issues) instead of the one in this site.
2) The correct forum seems to be here: http://enigma-dev.org/forums/index.php?board=46.0
3) Good catch. Linux dev's should look at this. I fixed a similar problem (not differencing between small and large case) on Windows not long ago.
Title: Re: X11 keyboard numpad and function keys corrupted by lookup in usermap with fix
Post by: Goombert on June 10, 2013, 08:06:40 AM
I told him to post on the tracker ;_;

Edit: Nevermind, Deus, he did post it on the tracker, the text screwed up so he posted here, its all good  (Y)
Title: Re: X11 keyboard numpad and function keys corrupted by lookup in usermap with fix
Post by: ssss on June 10, 2013, 12:50:27 PM
New diff fix change lowercase to uppercase in keymap instead of usermap

Code: [Select]
--- a/ENIGMAsystem/SHELL/Platforms/xlib/XLIBmain.cpp
+++ b/ENIGMAsystem/SHELL/Platforms/xlib/XLIBmain.cpp
@@ -45,7 +45,7 @@ namespace enigma_user {
 
 namespace enigma
 {
-  extern char keymap[256];
+  extern char keymap[512];
   extern char usermap[256];
   void ENIGMA_events(void); //TODO: Synchronize this with Windows by putting these two in a single header.
 
@@ -65,11 +65,12 @@ namespace enigma
       {
         case KeyPress: {
               gk=XLookupKeysym(&e.xkey,0);
               if (gk==NoSymbol)
                 return 0;
 
-              if (!(gk & 0xFF00)) actualKey = enigma::usermap[gk];
-              else actualKey = enigma::usermap[(int)enigma::keymap[gk & 0xFF]];
+              if (!(gk & 0xFF00)) actualKey = enigma::usermap[(int)enigma::keymap[gk & 0xFF]];
+              else actualKey = enigma::usermap[(int)enigma::keymap[gk & 0x1FF]];
               { // Set keyboard_lastchar. Seems to work without
                   char str[1];
                   int len = XLookupString(&e.xkey, str, 1, NULL, NULL);
@@ -90,8 +91,8 @@ namespace enigma
             if (gk == NoSymbol)
               return 0;
 
-            if (!(gk & 0xFF00)) actualKey = enigma::usermap[gk];
-            else actualKey = enigma::usermap[(int)enigma::keymap[gk & 0xFF]];
+            if (!(gk & 0xFF00)) actualKey = enigma::usermap[(int)enigma::keymap[gk & 0xFF]];
+            else actualKey = enigma::usermap[(int)enigma::keymap[gk & 0x1FF]];
 
             enigma::last_keybdstatus[actualKey]=enigma::keybdstatus[actualKey];
             enigma::keybdstatus[actualKey]=0;
diff --git a/ENIGMAsystem/SHELL/Platforms/xlib/XLIBwindow.cpp b/ENIGMAsystem/SHELL/Platforms/xlib/XLIBwindow.cpp
index b7a95da..ce98bb5 100644
--- a/ENIGMAsystem/SHELL/Platforms/xlib/XLIBwindow.cpp
+++ b/ENIGMAsystem/SHELL/Platforms/xlib/XLIBwindow.cpp
@@ -302,72 +302,75 @@ void screen_refresh() {
 
 namespace enigma
 {
-  char keymap[256];
+  char keymap[512];
   char usermap[256];
   void initkeymap()
   {
     using namespace enigma_user;
     // Pretend this part doesn't exist
-    keymap[0x51] = vk_left;
-    keymap[0x53] = vk_right;
-    keymap[0x52] = vk_up;
-    keymap[0x54] = vk_down;
-    keymap[0xE3] = vk_control;
-    keymap[0xE4] = vk_control;
-    keymap[0xE9] = vk_alt;
-    keymap[0xEA] = vk_alt;
-    keymap[0xE1] = vk_shift;
-    keymap[0xE2] = vk_shift;
-    keymap[0x0D] = vk_enter;
-    keymap[0x85] = vk_lsuper;
-    keymap[0x86] = vk_rsuper;
-    keymap[0x17] = vk_tab;
-    keymap[0x42] = vk_caps;
-    keymap[0x4E] = vk_scroll;
-    keymap[0x7F] = vk_pause;
-    keymap[0x9E] = vk_numpad0;
-    keymap[0x9C] = vk_numpad1;
-    keymap[0x99] = vk_numpad2;
-    keymap[0x9B] = vk_numpad3;
-    keymap[0x96] = vk_numpad4;
-    keymap[0x9D] = vk_numpad5;
-    keymap[0x98] = vk_numpad6;
-    keymap[0x95] = vk_numpad7;
-    keymap[0x97] = vk_numpad8;
-    keymap[0x9A] = vk_numpad9;
-    keymap[0xAF] = vk_divide;
-    keymap[0xAA] = vk_multiply;
-    keymap[0xAD] = vk_subtract;
-    keymap[0xAB] = vk_add;
-    keymap[0x9F] = vk_decimal;
-    keymap[0xBE] = vk_f1;
-    keymap[0xBF] = vk_f2;
-    keymap[0xC0] = vk_f3;
-    keymap[0xC1] = vk_f4;
-    keymap[0xC2] = vk_f5;
-    keymap[0xC3] = vk_f6;
-    keymap[0xC4] = vk_f7;
-    keymap[0xC5] = vk_f8;
-    keymap[0xC6] = vk_f9;
-    keymap[0xC7] = vk_f10;
-    keymap[0xC8] = vk_f11;
-    keymap[0xC9] = vk_f12;
-    keymap[0x08] = vk_backspace;
-    keymap[0x1B] = vk_escape;
-    keymap[0x50] = vk_home;
-    keymap[0x57] = vk_end;
-    keymap[0x55] = vk_pageup;
-    keymap[0x56] = vk_pagedown;
-    keymap[0xFF] = vk_delete;
-    keymap[0x63] = vk_insert;
+    keymap[0x151] = vk_left;
+    keymap[0x153] = vk_right;
+    keymap[0x152] = vk_up;
+    keymap[0x154] = vk_down;
+    keymap[0x1E3] = vk_control;
+    keymap[0x1E4] = vk_control;
+    keymap[0x1E9] = vk_alt;
+    keymap[0x1EA] = vk_alt;
+    keymap[0x1E1] = vk_shift;
+    keymap[0x1E2] = vk_shift;
+    keymap[0x10D] = vk_enter;
+    keymap[0x185] = vk_lsuper;
+    keymap[0x186] = vk_rsuper;
+    keymap[0x117] = vk_tab;
+    keymap[0x142] = vk_caps;
+    keymap[0x14E] = vk_scroll;
+    keymap[0x17F] = vk_pause;
+    keymap[0x19E] = vk_numpad0;
+    keymap[0x19C] = vk_numpad1;
+    keymap[0x199] = vk_numpad2;
+    keymap[0x19B] = vk_numpad3;
+    keymap[0x196] = vk_numpad4;
+    keymap[0x19D] = vk_numpad5;
+    keymap[0x198] = vk_numpad6;
+    keymap[0x195] = vk_numpad7;
+    keymap[0x197] = vk_numpad8;
+    keymap[0x19A] = vk_numpad9;
+    keymap[0x1AF] = vk_divide;
+    keymap[0x1AA] = vk_multiply;
+    keymap[0x1AD] = vk_subtract;
+    keymap[0x1AB] = vk_add;
+    keymap[0x19F] = vk_decimal;
+    keymap[0x1BE] = vk_f1;
+    keymap[0x1BF] = vk_f2;
+    keymap[0x1C0] = vk_f3;
+    keymap[0x1C1] = vk_f4;
+    keymap[0x1C2] = vk_f5;
+    keymap[0x1C3] = vk_f6;
+    keymap[0x1C4] = vk_f7;
+    keymap[0x1C5] = vk_f8;
+    keymap[0x1C6] = vk_f9;
+    keymap[0x1C7] = vk_f10;
+    keymap[0x1C8] = vk_f11;
+    keymap[0x1C9] = vk_f12;
+    keymap[0x108] = vk_backspace;
+    keymap[0x11B] = vk_escape;
+    keymap[0x150] = vk_home;
+    keymap[0x157] = vk_end;
+    keymap[0x155] = vk_pageup;
+    keymap[0x156] = vk_pagedown;
+    keymap[0x1FF] = vk_delete;
+    keymap[0x163] = vk_insert;
 
     // Set up identity map...
-    for (int i = 0; i < 'a'; i++)
+    for (int i = 0; i < 255; i++)
       usermap[i] = i;
+
+    for (int i = 0; i < 255; i++)
+      keymap[i] = i;
     for (int i = 'a'; i <= 'z'; i++) // 'a' to 'z' wrap to 'A' to 'Z'
-      usermap[i] = i + 'A' - 'a';
+      keymap[i] = i + 'A' - 'a';
     for (int i = 'z'+1; i < 255; i++)
-      usermap[i] = i;
+      keymap[i] = i;
    }
 }
Title: Re: X11 keyboard numpad and function keys corrupted by lookup in usermap with fix
Post by: Goombert on June 10, 2013, 01:09:01 PM
I attempted to apply the fixed file, but now 'S' makes the Window fullscreen :/
Title: Re: X11 keyboard numpad and function keys corrupted by lookup in usermap with fix
Post by: Josh @ Dreamland on June 16, 2013, 12:33:11 PM
For the record, this has been fixed. It was discussed and fixed over IRC.