You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

116 lines
3.5 KiB

7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /* Linux keyboard handler routines header.
  2. Copyright by Salvador E. Tropea (SET) (2001-2002)
  3. Covered by the GPL license. */
  4. #if defined(TVOSf_Linux) && !defined(LINUXKEY_HEADER_INCLUDED)
  5. #define LINUXKEY_HEADER_INCLUDED
  6. struct TEvent;
  7. const int MaxLenEscapeSequence=16;
  8. // A class to encapsulate the globals, all is static!
  9. class TGKeyLinux : public TGKey
  10. {
  11. public:
  12. TGKeyLinux() {};
  13. // Function replacements
  14. static void Suspend();
  15. static void Resume();
  16. static int KbHit();
  17. static void Clear();
  18. static ushort GKey();
  19. static unsigned GetShiftState();
  20. static void FillTEvent(TEvent &e);
  21. static void SetKbdMapping(int version);
  22. static int GetKbdMapping(int version);
  23. enum { Default, KOI8 };
  24. // Setup the pointers to point our members
  25. static void Init(int map);
  26. friend class TScreenLinux;
  27. friend class TDisplayLinux;
  28. protected:
  29. // Specific for this driver
  30. static int InitOnce();
  31. // Low level code to get a key and process it
  32. static int GetRaw();
  33. // A low level helper
  34. static int GetKeyParsed();
  35. // Get a key from the buffer
  36. static int GetKeyFromBuffer();
  37. // Escape sequences parser
  38. static int ProcessEscape();
  39. // Low level function to find the key modifiers
  40. static unsigned GetLinuxShiftState();
  41. // Trap the console switching signals
  42. static void hookVTSignals();
  43. // Stop traping the console switching signals
  44. static void unHookVTSignals();
  45. // Change the keyboard map
  46. static void patchKeyMap();
  47. // Restore keymap
  48. static void unPatchKeyMap();
  49. // Initializes the patching tables
  50. static void keyMapInit();
  51. // Signal handler called when we lose the VT
  52. static void releaseVTHandler(int);
  53. // Signal handler called when we get back the VT
  54. static void acquireVTHandler(int);
  55. // Small helpers to do both operations and check
  56. static void doHookAndPatch();
  57. static void doUnHookAndUnPatch();
  58. // File handle for the input
  59. static int hIn;
  60. // Stream for the input
  61. static FILE *fIn;
  62. // Old mode of the input file handle
  63. static int oldInFlags;
  64. // New mode of the input file handle
  65. static int newInFlags;
  66. // Termios data of the console before starting
  67. static struct termios inTermiosOrig;
  68. // Our termios settings
  69. static struct termios inTermiosNew;
  70. // Description of the last error
  71. static const char *error;
  72. // Buffer to store a key escape sequence while we analize it.
  73. // If a sequence failed the keys must be returned from here.
  74. static int bufferKeys[MaxLenEscapeSequence];
  75. // How many keys we have in the buffer
  76. static int keysInBuffer;
  77. // The next key to return. It avoids using things like ungetc
  78. static int nextKey;
  79. // Last key code we decoded
  80. static int lastKeyCode;
  81. // Last set of modifiers
  82. static int lastModifiers;
  83. // Modifiers in the TV format
  84. static int translatedModifiers;
  85. // ASCII of the key
  86. static char ascii;
  87. // Keyboard translation tables
  88. static unsigned char kbToName[128];
  89. static unsigned char kbExtraFlags[128];
  90. // Flag to disable keyboard patching. Use SetKbdMapping(linuxDisableKeyPatch).
  91. static char dontPatchKeyboard;
  92. // Our Virtual Terminal number
  93. static int ourVT;
  94. // The mode of our VT before we started
  95. static struct vt_mode oldVTMode;
  96. // The mode of our VT used by TV
  97. static struct vt_mode newVTMode;
  98. // Indicates if we hooked thed signals and patched the keyboard
  99. static char vtHooked;
  100. // Indicates if the ioctl to patch the keyboard is usable
  101. static char canPatchKeyboard;
  102. // Indicates if we patched the keyboard
  103. static char keyPatched;
  104. // Generic keyboard entry structure used in various places
  105. static struct kbentry entry;
  106. };
  107. #endif // LINUXKEY_HEADER_INCLUDED