tkkey.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /* Midnight Commander Tk initialization.
  2. Copyright (C) 1995 Miguel de Icaza
  3. Copyright (C) 1995 Jakub Jelinek
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
  15. #include <config.h>
  16. #include "tkmain.h"
  17. #include "tty.h" /* If you wonder why, read the comment below */
  18. #include "key.h"
  19. /* The tty.h file is included since we try to use as much object code
  20. * from the curses distribution as possible so we need to send back
  21. * the same constants that the code expects on the non-X version
  22. * of the code. The constants may be the ones from curses/ncurses
  23. * or our macro definitions for slang
  24. */
  25. /* Describes the key code and the keysym name returned by X
  26. * In case we found many keyboard problems with the Fnn keys
  27. * we can allways remove them and put them on the mc.tcl file
  28. * as local bindings
  29. */
  30. static key_code_name_t x_keys [] = {
  31. { KEY_LEFT, "Left" },
  32. { KEY_RIGHT, "Right" },
  33. { KEY_UP, "Up" },
  34. { KEY_DOWN, "Down" },
  35. { KEY_END, "End" },
  36. { KEY_END, "R13" },
  37. { KEY_HOME, "Home" },
  38. { KEY_HOME, "F27" },
  39. { KEY_PPAGE, "F29" },
  40. { KEY_PPAGE, "Prior" },
  41. { KEY_NPAGE, "Next" },
  42. { KEY_NPAGE, "F35" },
  43. { '\n', "Return" },
  44. { '\n', "KP_Enter" },
  45. #if 0
  46. { KEY_DC, "Delete" },
  47. #else
  48. { KEY_BACKSPACE, "Delete" },
  49. #endif
  50. { KEY_IC, "Insert" },
  51. { KEY_BACKSPACE, "BackSpace" },
  52. { KEY_F(1), "F1" },
  53. { KEY_F(2), "F2" },
  54. { KEY_F(3), "F3" },
  55. { KEY_F(4), "F4" },
  56. { KEY_F(5), "F5" },
  57. { KEY_F(6), "F6" },
  58. { KEY_F(7), "F7" },
  59. { KEY_F(8), "F8" },
  60. { KEY_F(9), "F9" },
  61. { KEY_F(10), "F10" },
  62. { 0, 0} /* terminator */
  63. };
  64. int lookup_keysym (char *s)
  65. {
  66. int i;
  67. for (i = 0; x_keys [i].name; i++){
  68. if (!strcmp (s, x_keys [i].name))
  69. return (x_keys [i].code);
  70. }
  71. return 0;
  72. }
  73. #if TCL_MAJOR_VERSION > 7
  74. /* Tcl 8.xx support */
  75. void add_select_channel (int fd, select_fn callback, void *info)
  76. {
  77. Tcl_CreateFileHandler (fd, TCL_READABLE, (Tcl_FileProc *) callback, 0);
  78. }
  79. void delete_select_channel (int fd)
  80. {
  81. Tcl_DeleteFileHandler (fd);
  82. }
  83. #else
  84. /* Tcl 7.xx support */
  85. void add_select_channel (int fd, select_fn callback, void *info)
  86. {
  87. Tcl_File handle;
  88. handle = Tcl_GetFile ((ClientData) fd, TCL_UNIX_FD);
  89. Tcl_CreateFileHandler (handle, TCL_READABLE, (Tcl_FileProc *) callback, 0);
  90. }
  91. void delete_select_channel (int fd)
  92. {
  93. Tcl_File handle;
  94. handle = Tcl_GetFile ((ClientData) fd, TCL_UNIX_FD);
  95. Tcl_DeleteFileHandler (handle);
  96. Tcl_FreeFile (handle);
  97. }
  98. #endif
  99. int
  100. mi_getch ()
  101. {
  102. return tk_getch();
  103. }