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