1998-02-27 07:54:42 +03:00
|
|
|
/* Keyboard support routines.
|
|
|
|
|
2007-09-25 19:33:35 +04:00
|
|
|
Copyright (C) 1994, 1995, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
|
|
|
|
2005, 2006, 2007 Free Software Foundation, Inc.
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
Written by: 1994, 1995 Miguel de Icaza.
|
2006-01-07 15:49:08 +03:00
|
|
|
1994, 1995 Janne Kukonlehto.
|
1998-02-27 07:54:42 +03:00
|
|
|
1995 Jakub Jelinek.
|
|
|
|
1997 Norbert Warmuth
|
2006-01-07 15:49:08 +03:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
2006-01-07 15:49:08 +03:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
2005-05-27 07:35:10 +04:00
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
#include <config.h>
|
2005-02-08 12:04:03 +03:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
#include <ctype.h>
|
|
|
|
#include <errno.h>
|
2005-02-08 12:04:03 +03:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <unistd.h>
|
2001-09-07 21:52:19 +04:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
#include "global.h"
|
2001-09-03 09:07:40 +04:00
|
|
|
#include "tty.h"
|
1998-02-27 07:54:42 +03:00
|
|
|
#include "mouse.h"
|
|
|
|
#include "key.h"
|
2006-11-08 16:37:24 +03:00
|
|
|
#include "layout.h" /* winch_flag */
|
1998-02-27 07:54:42 +03:00
|
|
|
#include "main.h"
|
1998-04-01 02:36:24 +04:00
|
|
|
#include "win.h"
|
|
|
|
#include "cons.saver.h"
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2003-11-08 02:50:18 +03:00
|
|
|
#ifdef USE_VFS
|
|
|
|
#include "../vfs/gc.h"
|
|
|
|
#endif
|
|
|
|
|
2001-06-05 20:41:44 +04:00
|
|
|
#ifdef HAVE_TEXTMODE_X11_SUPPORT
|
2005-03-10 12:44:36 +03:00
|
|
|
# include "x11conn.h"
|
1999-04-21 23:18:31 +04:00
|
|
|
#endif
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
#ifdef __linux__
|
|
|
|
# if defined(__GLIBC__) && (__GLIBC__ < 2)
|
2003-02-27 08:09:35 +03:00
|
|
|
# include <linux/termios.h> /* TIOCLINUX */
|
1998-02-27 07:54:42 +03:00
|
|
|
# else
|
|
|
|
# include <termios.h>
|
|
|
|
# endif
|
|
|
|
# include <sys/ioctl.h>
|
2003-02-27 08:09:35 +03:00
|
|
|
#endif /* __linux__ */
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2004-09-14 21:18:25 +04:00
|
|
|
#ifdef __CYGWIN__
|
|
|
|
# include <termios.h>
|
|
|
|
# include <sys/ioctl.h>
|
|
|
|
#endif /* __CYGWIN__ */
|
|
|
|
|
2003-02-23 08:36:49 +03:00
|
|
|
#ifdef __QNXNTO__
|
2003-03-10 11:47:37 +03:00
|
|
|
# include <dlfcn.h>
|
|
|
|
# include <Ph.h>
|
2003-02-23 08:36:49 +03:00
|
|
|
# include <sys/dcmd_chr.h>
|
|
|
|
#endif
|
|
|
|
|
1998-12-02 09:51:40 +03:00
|
|
|
#define GET_TIME(tv) (gettimeofday(&tv, (struct timezone *)NULL))
|
1998-02-27 07:54:42 +03:00
|
|
|
#define DIF_TIME(t1,t2) ((t2.tv_sec -t1.tv_sec) *1000+ \
|
|
|
|
(t2.tv_usec-t1.tv_usec)/1000)
|
2006-01-07 15:49:08 +03:00
|
|
|
|
2002-12-21 11:43:15 +03:00
|
|
|
/* Linux console keyboard modifiers */
|
2006-01-07 15:49:08 +03:00
|
|
|
#define SHIFT_PRESSED (1 << 0)
|
|
|
|
#define ALTR_PRESSED (1 << 1)
|
|
|
|
#define CONTROL_PRESSED (1 << 2)
|
|
|
|
#define ALTL_PRESSED (1 << 3)
|
2002-12-21 11:43:15 +03:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
int mou_auto_repeat = 100;
|
|
|
|
int double_click_speed = 250;
|
|
|
|
int old_esc_mode = 0;
|
2006-08-10 01:19:18 +04:00
|
|
|
/* timeout for old_esc_mode in usec */
|
|
|
|
int keyboard_key_timeout = 1000000; /* settable via env */
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2004-11-07 15:37:24 +03:00
|
|
|
int use_8th_bit_as_meta = 0;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
typedef struct key_def {
|
|
|
|
char ch; /* Holds the matching char code */
|
|
|
|
int code; /* The code returned, valid if child == NULL */
|
|
|
|
struct key_def *next;
|
|
|
|
struct key_def *child; /* sequence continuation */
|
|
|
|
int action; /* optional action to be done. Now used only
|
2006-01-07 15:49:08 +03:00
|
|
|
to mark that we are just after the first
|
|
|
|
Escape */
|
1998-02-27 07:54:42 +03:00
|
|
|
} key_def;
|
|
|
|
|
|
|
|
/* This holds all the key definitions */
|
2006-01-07 15:49:08 +03:00
|
|
|
static key_def *keys = NULL;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
static int input_fd;
|
|
|
|
static int disabled_channels = 0; /* Disable channels checking */
|
2001-07-20 20:19:28 +04:00
|
|
|
static int xgetch_second (void);
|
2002-12-21 11:43:15 +03:00
|
|
|
static int get_modifier (void);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
/* File descriptor monitoring add/remove routines */
|
|
|
|
typedef struct SelectList {
|
|
|
|
int fd;
|
|
|
|
select_fn callback;
|
|
|
|
void *info;
|
|
|
|
struct SelectList *next;
|
|
|
|
} SelectList;
|
|
|
|
|
2003-03-10 11:47:37 +03:00
|
|
|
#ifdef __QNXNTO__
|
|
|
|
typedef int (*ph_dv_f) (void *, void *);
|
|
|
|
typedef int (*ph_ov_f) (void *);
|
|
|
|
typedef int (*ph_pqc_f) (unsigned short, PhCursorInfo_t *);
|
|
|
|
ph_dv_f ph_attach;
|
|
|
|
ph_ov_f ph_input_group;
|
|
|
|
ph_pqc_f ph_query_cursor;
|
|
|
|
#endif
|
|
|
|
|
2006-01-07 15:49:08 +03:00
|
|
|
static SelectList *select_list = NULL;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
void add_select_channel (int fd, select_fn callback, void *info)
|
|
|
|
{
|
|
|
|
SelectList *new;
|
|
|
|
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 04:08:30 +03:00
|
|
|
new = g_new (SelectList, 1);
|
1998-02-27 07:54:42 +03:00
|
|
|
new->fd = fd;
|
|
|
|
new->callback = callback;
|
|
|
|
new->info = info;
|
|
|
|
new->next = select_list;
|
|
|
|
select_list = new;
|
|
|
|
}
|
|
|
|
|
|
|
|
void delete_select_channel (int fd)
|
|
|
|
{
|
|
|
|
SelectList *p = select_list;
|
2006-01-07 15:49:08 +03:00
|
|
|
SelectList *p_prev = NULL;
|
2002-08-10 08:37:13 +04:00
|
|
|
SelectList *p_next;
|
|
|
|
|
|
|
|
while (p) {
|
|
|
|
if (p->fd == fd) {
|
|
|
|
p_next = p->next;
|
|
|
|
|
|
|
|
if (p_prev)
|
|
|
|
p_prev->next = p_next;
|
1998-02-27 07:54:42 +03:00
|
|
|
else
|
2002-08-10 08:37:13 +04:00
|
|
|
select_list = p_next;
|
|
|
|
|
2009-02-06 01:27:37 +03:00
|
|
|
g_free (p);
|
2002-08-10 08:37:13 +04:00
|
|
|
p = p_next;
|
|
|
|
continue;
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
2002-08-10 08:37:13 +04:00
|
|
|
|
|
|
|
p_prev = p;
|
1998-02-27 07:54:42 +03:00
|
|
|
p = p->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
inline static int add_selects (fd_set *select_set)
|
|
|
|
{
|
|
|
|
SelectList *p;
|
|
|
|
int top_fd = 0;
|
|
|
|
|
|
|
|
if (disabled_channels)
|
|
|
|
return 0;
|
2006-01-07 15:49:08 +03:00
|
|
|
|
|
|
|
for (p = select_list; p; p = p->next) {
|
1998-02-27 07:54:42 +03:00
|
|
|
FD_SET (p->fd, select_set);
|
|
|
|
if (p->fd > top_fd)
|
|
|
|
top_fd = p->fd;
|
|
|
|
}
|
|
|
|
return top_fd;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void check_selects (fd_set *select_set)
|
|
|
|
{
|
|
|
|
SelectList *p;
|
2009-02-06 01:46:07 +03:00
|
|
|
gboolean retry;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
if (disabled_channels)
|
|
|
|
return;
|
2006-01-07 15:49:08 +03:00
|
|
|
|
2006-08-12 14:06:22 +04:00
|
|
|
do {
|
|
|
|
retry = FALSE;
|
2006-08-12 02:57:09 +04:00
|
|
|
for (p = select_list; p; p = p->next)
|
|
|
|
if (FD_ISSET (p->fd, select_set)) {
|
|
|
|
FD_CLR (p->fd, select_set);
|
|
|
|
(*p->callback)(p->fd, p->info);
|
|
|
|
retry = TRUE;
|
|
|
|
break;
|
2006-08-12 22:22:44 +04:00
|
|
|
}
|
2006-08-12 14:06:22 +04:00
|
|
|
} while (retry);
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void channels_down (void)
|
|
|
|
{
|
2006-01-07 15:49:08 +03:00
|
|
|
disabled_channels++;
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void channels_up (void)
|
|
|
|
{
|
|
|
|
if (!disabled_channels)
|
2003-03-11 15:23:08 +03:00
|
|
|
fputs ("Error: channels_up called with disabled_channels = 0\n",
|
|
|
|
stderr);
|
1998-02-27 07:54:42 +03:00
|
|
|
disabled_channels--;
|
|
|
|
}
|
|
|
|
|
2001-10-26 14:21:25 +04:00
|
|
|
typedef const struct {
|
1998-02-27 07:54:42 +03:00
|
|
|
int code;
|
2004-08-30 03:27:40 +04:00
|
|
|
const char *seq;
|
1998-02-27 07:54:42 +03:00
|
|
|
int action;
|
|
|
|
} key_define_t;
|
|
|
|
|
|
|
|
/* Broken terminfo and termcap databases on xterminals */
|
2001-06-05 20:41:44 +04:00
|
|
|
static key_define_t xterm_key_defines [] = {
|
1998-02-27 07:54:42 +03:00
|
|
|
{ KEY_F(1), ESC_STR "OP", MCKEY_NOACTION },
|
|
|
|
{ KEY_F(2), ESC_STR "OQ", MCKEY_NOACTION },
|
|
|
|
{ KEY_F(3), ESC_STR "OR", MCKEY_NOACTION },
|
|
|
|
{ KEY_F(4), ESC_STR "OS", MCKEY_NOACTION },
|
|
|
|
{ KEY_F(1), ESC_STR "[11~", MCKEY_NOACTION },
|
|
|
|
{ KEY_F(2), ESC_STR "[12~", MCKEY_NOACTION },
|
|
|
|
{ KEY_F(3), ESC_STR "[13~", MCKEY_NOACTION },
|
|
|
|
{ KEY_F(4), ESC_STR "[14~", MCKEY_NOACTION },
|
|
|
|
{ KEY_F(5), ESC_STR "[15~", MCKEY_NOACTION },
|
|
|
|
{ KEY_F(6), ESC_STR "[17~", MCKEY_NOACTION },
|
|
|
|
{ KEY_F(7), ESC_STR "[18~", MCKEY_NOACTION },
|
|
|
|
{ KEY_F(8), ESC_STR "[19~", MCKEY_NOACTION },
|
|
|
|
{ KEY_F(9), ESC_STR "[20~", MCKEY_NOACTION },
|
|
|
|
{ KEY_F(10), ESC_STR "[21~", MCKEY_NOACTION },
|
2002-12-21 10:34:49 +03:00
|
|
|
|
2003-09-23 10:58:34 +04:00
|
|
|
/* old xterm Shift-arrows */
|
2002-12-21 10:34:49 +03:00
|
|
|
{ KEY_M_SHIFT | KEY_UP, ESC_STR "O2A", MCKEY_NOACTION },
|
|
|
|
{ KEY_M_SHIFT | KEY_DOWN, ESC_STR "O2B", MCKEY_NOACTION },
|
|
|
|
{ KEY_M_SHIFT | KEY_RIGHT, ESC_STR "O2C", MCKEY_NOACTION },
|
|
|
|
{ KEY_M_SHIFT | KEY_LEFT, ESC_STR "O2D", MCKEY_NOACTION },
|
2003-07-23 09:44:25 +04:00
|
|
|
|
2003-09-23 10:58:34 +04:00
|
|
|
/* new xterm Shift-arrows */
|
2003-07-23 09:44:25 +04:00
|
|
|
{ KEY_M_SHIFT | KEY_UP, ESC_STR "[1;2A", MCKEY_NOACTION },
|
|
|
|
{ KEY_M_SHIFT | KEY_DOWN, ESC_STR "[1;2B", MCKEY_NOACTION },
|
|
|
|
{ KEY_M_SHIFT | KEY_RIGHT, ESC_STR "[1;2C", MCKEY_NOACTION },
|
|
|
|
{ KEY_M_SHIFT | KEY_LEFT, ESC_STR "[1;2D", MCKEY_NOACTION },
|
2003-09-23 10:58:34 +04:00
|
|
|
|
|
|
|
/* more xterm keys with modifiers */
|
|
|
|
{ KEY_M_CTRL | KEY_PPAGE, ESC_STR "[5;5~", MCKEY_NOACTION },
|
|
|
|
{ KEY_M_CTRL | KEY_NPAGE, ESC_STR "[6;5~", MCKEY_NOACTION },
|
|
|
|
{ KEY_M_CTRL | KEY_IC, ESC_STR "[2;5~", MCKEY_NOACTION },
|
|
|
|
{ KEY_M_CTRL | KEY_DC, ESC_STR "[3;5~", MCKEY_NOACTION },
|
2003-07-23 09:44:25 +04:00
|
|
|
{ KEY_M_CTRL | KEY_HOME, ESC_STR "[1;5H", MCKEY_NOACTION },
|
|
|
|
{ KEY_M_CTRL | KEY_END, ESC_STR "[1;5F", MCKEY_NOACTION },
|
|
|
|
{ KEY_M_SHIFT | KEY_HOME, ESC_STR "[1;2H", MCKEY_NOACTION },
|
|
|
|
{ KEY_M_SHIFT | KEY_END, ESC_STR "[1;2F", MCKEY_NOACTION },
|
2003-09-23 10:58:34 +04:00
|
|
|
{ KEY_M_CTRL | KEY_UP, ESC_STR "[1;5A", MCKEY_NOACTION },
|
|
|
|
{ KEY_M_CTRL | KEY_DOWN, ESC_STR "[1;5B", MCKEY_NOACTION },
|
|
|
|
{ KEY_M_CTRL | KEY_RIGHT, ESC_STR "[1;5C", MCKEY_NOACTION },
|
|
|
|
{ KEY_M_CTRL | KEY_LEFT, ESC_STR "[1;5D", MCKEY_NOACTION },
|
2003-09-23 11:01:57 +04:00
|
|
|
{ KEY_M_SHIFT | KEY_IC, ESC_STR "[2;2~", MCKEY_NOACTION },
|
|
|
|
{ KEY_M_SHIFT | KEY_DC, ESC_STR "[3;2~", MCKEY_NOACTION },
|
2003-09-23 10:58:34 +04:00
|
|
|
{ KEY_M_SHIFT | KEY_M_CTRL | KEY_UP, ESC_STR "[1;6A", MCKEY_NOACTION },
|
|
|
|
{ KEY_M_SHIFT | KEY_M_CTRL | KEY_DOWN, ESC_STR "[1;6B", MCKEY_NOACTION },
|
|
|
|
{ KEY_M_SHIFT | KEY_M_CTRL | KEY_RIGHT, ESC_STR "[1;6C", MCKEY_NOACTION },
|
|
|
|
{ KEY_M_SHIFT | KEY_M_CTRL | KEY_LEFT, ESC_STR "[1;6D", MCKEY_NOACTION },
|
2002-12-21 10:34:49 +03:00
|
|
|
|
|
|
|
/* rxvt keys with modifiers */
|
|
|
|
{ KEY_M_SHIFT | KEY_UP, ESC_STR "[a", MCKEY_NOACTION },
|
|
|
|
{ KEY_M_SHIFT | KEY_DOWN, ESC_STR "[b", MCKEY_NOACTION },
|
|
|
|
{ KEY_M_SHIFT | KEY_RIGHT, ESC_STR "[c", MCKEY_NOACTION },
|
|
|
|
{ KEY_M_SHIFT | KEY_LEFT, ESC_STR "[d", MCKEY_NOACTION },
|
2003-09-23 10:58:34 +04:00
|
|
|
{ KEY_M_CTRL | KEY_UP, ESC_STR "Oa", MCKEY_NOACTION },
|
|
|
|
{ KEY_M_CTRL | KEY_DOWN, ESC_STR "Ob", MCKEY_NOACTION },
|
|
|
|
{ KEY_M_CTRL | KEY_RIGHT, ESC_STR "Oc", MCKEY_NOACTION },
|
|
|
|
{ KEY_M_CTRL | KEY_LEFT, ESC_STR "Od", MCKEY_NOACTION },
|
2002-12-21 10:34:49 +03:00
|
|
|
{ KEY_M_CTRL | KEY_PPAGE, ESC_STR "[5^", MCKEY_NOACTION },
|
|
|
|
{ KEY_M_CTRL | KEY_NPAGE, ESC_STR "[6^", MCKEY_NOACTION },
|
|
|
|
{ KEY_M_CTRL | KEY_HOME, ESC_STR "[7^", MCKEY_NOACTION },
|
|
|
|
{ KEY_M_CTRL | KEY_END, ESC_STR "[8^", MCKEY_NOACTION },
|
|
|
|
{ KEY_M_SHIFT | KEY_HOME, ESC_STR "[7$", MCKEY_NOACTION },
|
|
|
|
{ KEY_M_SHIFT | KEY_END, ESC_STR "[8$", MCKEY_NOACTION },
|
2003-03-14 19:52:33 +03:00
|
|
|
{ KEY_M_CTRL | KEY_IC, ESC_STR "[2^", MCKEY_NOACTION },
|
|
|
|
{ KEY_M_CTRL | KEY_DC, ESC_STR "[3^", MCKEY_NOACTION },
|
|
|
|
{ KEY_M_SHIFT | KEY_DC, ESC_STR "[3$", MCKEY_NOACTION },
|
|
|
|
|
|
|
|
/* konsole keys with modifiers */
|
|
|
|
{ KEY_M_SHIFT | KEY_HOME, ESC_STR "O2H", MCKEY_NOACTION },
|
|
|
|
{ KEY_M_SHIFT | KEY_END, ESC_STR "O2F", MCKEY_NOACTION },
|
2002-12-21 10:34:49 +03:00
|
|
|
|
2003-09-23 10:58:34 +04:00
|
|
|
/* gnome-terminal */
|
|
|
|
{ KEY_M_SHIFT | KEY_UP, ESC_STR "[2A", MCKEY_NOACTION },
|
|
|
|
{ KEY_M_SHIFT | KEY_DOWN, ESC_STR "[2B", MCKEY_NOACTION },
|
|
|
|
{ KEY_M_SHIFT | KEY_RIGHT, ESC_STR "[2C", MCKEY_NOACTION },
|
|
|
|
{ KEY_M_SHIFT | KEY_LEFT, ESC_STR "[2D", MCKEY_NOACTION },
|
|
|
|
{ KEY_M_CTRL | KEY_UP, ESC_STR "[5A", MCKEY_NOACTION },
|
|
|
|
{ KEY_M_CTRL | KEY_DOWN, ESC_STR "[5B", MCKEY_NOACTION },
|
|
|
|
{ KEY_M_CTRL | KEY_RIGHT, ESC_STR "[5C", MCKEY_NOACTION },
|
|
|
|
{ KEY_M_CTRL | KEY_LEFT, ESC_STR "[5D", MCKEY_NOACTION },
|
2003-09-24 11:06:08 +04:00
|
|
|
{ KEY_M_SHIFT | KEY_M_CTRL | KEY_UP, ESC_STR "[6A", MCKEY_NOACTION },
|
|
|
|
{ KEY_M_SHIFT | KEY_M_CTRL | KEY_DOWN, ESC_STR "[6B", MCKEY_NOACTION },
|
|
|
|
{ KEY_M_SHIFT | KEY_M_CTRL | KEY_RIGHT, ESC_STR "[6C", MCKEY_NOACTION },
|
|
|
|
{ KEY_M_SHIFT | KEY_M_CTRL | KEY_LEFT, ESC_STR "[6D", MCKEY_NOACTION },
|
2003-09-23 10:58:34 +04:00
|
|
|
|
2003-09-24 11:06:08 +04:00
|
|
|
/* gnome-terminal - application mode */
|
2003-09-24 07:32:23 +04:00
|
|
|
{ KEY_M_CTRL | KEY_UP, ESC_STR "O5A", MCKEY_NOACTION },
|
|
|
|
{ KEY_M_CTRL | KEY_DOWN, ESC_STR "O5B", MCKEY_NOACTION },
|
|
|
|
{ KEY_M_CTRL | KEY_RIGHT, ESC_STR "O5C", MCKEY_NOACTION },
|
|
|
|
{ KEY_M_CTRL | KEY_LEFT, ESC_STR "O5D", MCKEY_NOACTION },
|
|
|
|
{ KEY_M_SHIFT | KEY_M_CTRL | KEY_UP, ESC_STR "O6A", MCKEY_NOACTION },
|
|
|
|
{ KEY_M_SHIFT | KEY_M_CTRL | KEY_DOWN, ESC_STR "O6B", MCKEY_NOACTION },
|
|
|
|
{ KEY_M_SHIFT | KEY_M_CTRL | KEY_RIGHT, ESC_STR "O6C", MCKEY_NOACTION },
|
|
|
|
{ KEY_M_SHIFT | KEY_M_CTRL | KEY_LEFT, ESC_STR "O6D", MCKEY_NOACTION },
|
|
|
|
|
2006-02-05 18:27:49 +03:00
|
|
|
/* iTerm */
|
|
|
|
{ KEY_M_SHIFT | KEY_PPAGE, ESC_STR "[5;2~", MCKEY_NOACTION },
|
|
|
|
{ KEY_M_SHIFT | KEY_NPAGE, ESC_STR "[6;2~", MCKEY_NOACTION },
|
|
|
|
|
2003-09-09 20:30:14 +04:00
|
|
|
/* keypad keys */
|
|
|
|
{ KEY_IC, ESC_STR "Op", MCKEY_NOACTION },
|
|
|
|
{ KEY_DC, ESC_STR "On", MCKEY_NOACTION },
|
|
|
|
{ '/', ESC_STR "Oo", MCKEY_NOACTION },
|
|
|
|
{ '\n', ESC_STR "OM", MCKEY_NOACTION },
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
{ 0, 0, MCKEY_NOACTION },
|
|
|
|
};
|
|
|
|
|
2006-01-07 15:49:08 +03:00
|
|
|
/* qansi-m terminals have a much more key combinatios,
|
2004-09-26 04:58:47 +04:00
|
|
|
which are undefined in termcap/terminfo */
|
|
|
|
static key_define_t qansi_key_defines[] =
|
|
|
|
{
|
|
|
|
/* qansi-m terminal */
|
|
|
|
{KEY_M_CTRL | KEY_NPAGE, ESC_STR "[u", MCKEY_NOACTION}, /* Ctrl-PgDown */
|
|
|
|
{KEY_M_CTRL | KEY_PPAGE, ESC_STR "[v", MCKEY_NOACTION}, /* Ctrl-PgUp */
|
|
|
|
{KEY_M_CTRL | KEY_HOME, ESC_STR "[h", MCKEY_NOACTION}, /* Ctrl-Home */
|
|
|
|
{KEY_M_CTRL | KEY_END, ESC_STR "[y", MCKEY_NOACTION}, /* Ctrl-End */
|
|
|
|
{KEY_M_CTRL | KEY_IC, ESC_STR "[`", MCKEY_NOACTION}, /* Ctrl-Insert */
|
|
|
|
{KEY_M_CTRL | KEY_DC, ESC_STR "[p", MCKEY_NOACTION}, /* Ctrl-Delete */
|
|
|
|
{KEY_M_CTRL | KEY_LEFT, ESC_STR "[d", MCKEY_NOACTION}, /* Ctrl-Left */
|
|
|
|
{KEY_M_CTRL | KEY_RIGHT, ESC_STR "[c", MCKEY_NOACTION}, /* Ctrl-Right */
|
|
|
|
{KEY_M_CTRL | KEY_DOWN, ESC_STR "[b", MCKEY_NOACTION}, /* Ctrl-Down */
|
|
|
|
{KEY_M_CTRL | KEY_UP, ESC_STR "[a", MCKEY_NOACTION}, /* Ctrl-Up */
|
|
|
|
{KEY_M_CTRL | KEY_KP_ADD, ESC_STR "[s", MCKEY_NOACTION}, /* Ctrl-Gr-Plus */
|
|
|
|
{KEY_M_CTRL | KEY_KP_SUBTRACT, ESC_STR "[t", MCKEY_NOACTION}, /* Ctrl-Gr-Minus */
|
|
|
|
{KEY_M_CTRL | '\t', ESC_STR "[z", MCKEY_NOACTION}, /* Ctrl-Tab */
|
|
|
|
{KEY_M_SHIFT | '\t', ESC_STR "[Z", MCKEY_NOACTION}, /* Shift-Tab */
|
|
|
|
{KEY_M_CTRL | KEY_F(1), ESC_STR "[1~", MCKEY_NOACTION}, /* Ctrl-F1 */
|
|
|
|
{KEY_M_CTRL | KEY_F(2), ESC_STR "[2~", MCKEY_NOACTION}, /* Ctrl-F2 */
|
|
|
|
{KEY_M_CTRL | KEY_F(3), ESC_STR "[3~", MCKEY_NOACTION}, /* Ctrl-F3 */
|
|
|
|
{KEY_M_CTRL | KEY_F(4), ESC_STR "[4~", MCKEY_NOACTION}, /* Ctrl-F4 */
|
|
|
|
{KEY_M_CTRL | KEY_F(5), ESC_STR "[5~", MCKEY_NOACTION}, /* Ctrl-F5 */
|
|
|
|
{KEY_M_CTRL | KEY_F(6), ESC_STR "[6~", MCKEY_NOACTION}, /* Ctrl-F6 */
|
|
|
|
{KEY_M_CTRL | KEY_F(7), ESC_STR "[7~", MCKEY_NOACTION}, /* Ctrl-F7 */
|
|
|
|
{KEY_M_CTRL | KEY_F(8), ESC_STR "[8~", MCKEY_NOACTION}, /* Ctrl-F8 */
|
|
|
|
{KEY_M_CTRL | KEY_F(9), ESC_STR "[9~", MCKEY_NOACTION}, /* Ctrl-F9 */
|
|
|
|
{KEY_M_CTRL | KEY_F(10), ESC_STR "[10~", MCKEY_NOACTION}, /* Ctrl-F10 */
|
|
|
|
{KEY_M_CTRL | KEY_F(11), ESC_STR "[11~", MCKEY_NOACTION}, /* Ctrl-F11 */
|
|
|
|
{KEY_M_CTRL | KEY_F(12), ESC_STR "[12~", MCKEY_NOACTION}, /* Ctrl-F12 */
|
|
|
|
{KEY_M_ALT | KEY_F(1), ESC_STR "[17~", MCKEY_NOACTION}, /* Alt-F1 */
|
|
|
|
{KEY_M_ALT | KEY_F(2), ESC_STR "[18~", MCKEY_NOACTION}, /* Alt-F2 */
|
|
|
|
{KEY_M_ALT | KEY_F(3), ESC_STR "[19~", MCKEY_NOACTION}, /* Alt-F3 */
|
|
|
|
{KEY_M_ALT | KEY_F(4), ESC_STR "[20~", MCKEY_NOACTION}, /* Alt-F4 */
|
|
|
|
{KEY_M_ALT | KEY_F(5), ESC_STR "[21~", MCKEY_NOACTION}, /* Alt-F5 */
|
|
|
|
{KEY_M_ALT | KEY_F(6), ESC_STR "[22~", MCKEY_NOACTION}, /* Alt-F6 */
|
|
|
|
{KEY_M_ALT | KEY_F(7), ESC_STR "[23~", MCKEY_NOACTION}, /* Alt-F7 */
|
|
|
|
{KEY_M_ALT | KEY_F(8), ESC_STR "[24~", MCKEY_NOACTION}, /* Alt-F8 */
|
|
|
|
{KEY_M_ALT | KEY_F(9), ESC_STR "[25~", MCKEY_NOACTION}, /* Alt-F9 */
|
|
|
|
{KEY_M_ALT | KEY_F(10), ESC_STR "[26~", MCKEY_NOACTION}, /* Alt-F10 */
|
|
|
|
{KEY_M_ALT | KEY_F(11), ESC_STR "[27~", MCKEY_NOACTION}, /* Alt-F11 */
|
|
|
|
{KEY_M_ALT | KEY_F(12), ESC_STR "[28~", MCKEY_NOACTION}, /* Alt-F12 */
|
|
|
|
{KEY_M_ALT | 'a', ESC_STR "Na", MCKEY_NOACTION}, /* Alt-a */
|
|
|
|
{KEY_M_ALT | 'b', ESC_STR "Nb", MCKEY_NOACTION}, /* Alt-b */
|
|
|
|
{KEY_M_ALT | 'c', ESC_STR "Nc", MCKEY_NOACTION}, /* Alt-c */
|
|
|
|
{KEY_M_ALT | 'd', ESC_STR "Nd", MCKEY_NOACTION}, /* Alt-d */
|
|
|
|
{KEY_M_ALT | 'e', ESC_STR "Ne", MCKEY_NOACTION}, /* Alt-e */
|
|
|
|
{KEY_M_ALT | 'f', ESC_STR "Nf", MCKEY_NOACTION}, /* Alt-f */
|
|
|
|
{KEY_M_ALT | 'g', ESC_STR "Ng", MCKEY_NOACTION}, /* Alt-g */
|
|
|
|
{KEY_M_ALT | 'i', ESC_STR "Ni", MCKEY_NOACTION}, /* Alt-i */
|
|
|
|
{KEY_M_ALT | 'j', ESC_STR "Nj", MCKEY_NOACTION}, /* Alt-j */
|
|
|
|
{KEY_M_ALT | 'k', ESC_STR "Nk", MCKEY_NOACTION}, /* Alt-k */
|
|
|
|
{KEY_M_ALT | 'l', ESC_STR "Nl", MCKEY_NOACTION}, /* Alt-l */
|
|
|
|
{KEY_M_ALT | 'm', ESC_STR "Nm", MCKEY_NOACTION}, /* Alt-m */
|
|
|
|
{KEY_M_ALT | 'n', ESC_STR "Nn", MCKEY_NOACTION}, /* Alt-n */
|
|
|
|
{KEY_M_ALT | 'o', ESC_STR "No", MCKEY_NOACTION}, /* Alt-o */
|
|
|
|
{KEY_M_ALT | 'p', ESC_STR "Np", MCKEY_NOACTION}, /* Alt-p */
|
|
|
|
{KEY_M_ALT | 'q', ESC_STR "Nq", MCKEY_NOACTION}, /* Alt-r */
|
|
|
|
{KEY_M_ALT | 's', ESC_STR "Ns", MCKEY_NOACTION}, /* Alt-s */
|
|
|
|
{KEY_M_ALT | 't', ESC_STR "Nt", MCKEY_NOACTION}, /* Alt-t */
|
|
|
|
{KEY_M_ALT | 'u', ESC_STR "Nu", MCKEY_NOACTION}, /* Alt-u */
|
|
|
|
{KEY_M_ALT | 'v', ESC_STR "Nv", MCKEY_NOACTION}, /* Alt-v */
|
|
|
|
{KEY_M_ALT | 'w', ESC_STR "Nw", MCKEY_NOACTION}, /* Alt-w */
|
|
|
|
{KEY_M_ALT | 'x', ESC_STR "Nx", MCKEY_NOACTION}, /* Alt-x */
|
|
|
|
{KEY_M_ALT | 'y', ESC_STR "Ny", MCKEY_NOACTION}, /* Alt-y */
|
|
|
|
{KEY_M_ALT | 'z', ESC_STR "Nz", MCKEY_NOACTION}, /* Alt-z */
|
2006-01-07 15:49:08 +03:00
|
|
|
{KEY_KP_SUBTRACT, ESC_STR "[S", MCKEY_NOACTION}, /* Gr-Minus */
|
2005-03-25 12:38:24 +03:00
|
|
|
{KEY_KP_ADD, ESC_STR "[T", MCKEY_NOACTION}, /* Gr-Plus */
|
2006-01-07 15:49:08 +03:00
|
|
|
{0, NULL, MCKEY_NOACTION},
|
2004-09-26 04:58:47 +04:00
|
|
|
};
|
|
|
|
|
2001-06-05 20:41:44 +04:00
|
|
|
static key_define_t mc_default_keys [] = {
|
1998-02-27 07:54:42 +03:00
|
|
|
{ ESC_CHAR, ESC_STR, MCKEY_ESCAPE },
|
|
|
|
{ ESC_CHAR, ESC_STR ESC_STR, MCKEY_NOACTION },
|
2006-01-07 15:49:08 +03:00
|
|
|
{ 0, NULL, MCKEY_NOACTION },
|
1998-02-27 07:54:42 +03:00
|
|
|
};
|
|
|
|
|
1998-12-03 00:27:27 +03:00
|
|
|
static void
|
|
|
|
define_sequences (key_define_t *kd)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
|
|
|
int i;
|
2006-01-07 15:49:08 +03:00
|
|
|
|
|
|
|
for (i = 0; kd[i].code != 0; i++)
|
|
|
|
define_sequence(kd[i].code, kd[i].seq, kd[i].action);
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
2001-06-05 20:41:44 +04:00
|
|
|
#ifdef HAVE_TEXTMODE_X11_SUPPORT
|
2003-02-23 08:05:49 +03:00
|
|
|
|
2001-06-06 02:08:31 +04:00
|
|
|
static Display *x11_display;
|
|
|
|
static Window x11_window;
|
2003-02-23 08:05:49 +03:00
|
|
|
|
|
|
|
static void
|
|
|
|
init_key_x11 (void)
|
|
|
|
{
|
2003-02-23 08:23:04 +03:00
|
|
|
if (!getenv ("DISPLAY"))
|
|
|
|
return;
|
|
|
|
|
2005-03-10 12:44:36 +03:00
|
|
|
x11_display = mc_XOpenDisplay (0);
|
2003-02-23 08:05:49 +03:00
|
|
|
|
|
|
|
if (x11_display)
|
|
|
|
x11_window = DefaultRootWindow (x11_display);
|
|
|
|
}
|
|
|
|
#endif /* HAVE_TEXTMODE_X11_SUPPORT */
|
|
|
|
|
1999-04-21 23:18:31 +04:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
/* This has to be called before slang_init or whatever routine
|
|
|
|
calls any define_sequence */
|
2005-03-21 23:27:55 +03:00
|
|
|
void
|
|
|
|
init_key (void)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
2004-08-16 21:45:38 +04:00
|
|
|
const char *term = getenv ("TERM");
|
2006-08-10 01:19:18 +04:00
|
|
|
char *kt = getenv ("KEYBOARD_KEY_TIMEOUT_US");
|
|
|
|
if (kt != NULL)
|
|
|
|
keyboard_key_timeout = atoi (kt);
|
2005-03-21 23:27:55 +03:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
/* This has to be the first define_sequence */
|
|
|
|
/* So, we can assume that the first keys member has ESC */
|
|
|
|
define_sequences (mc_default_keys);
|
2003-05-30 23:56:43 +04:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
/* Terminfo on irix does not have some keys */
|
2005-07-21 00:29:08 +04:00
|
|
|
if (xterm_flag
|
|
|
|
|| (term != NULL
|
|
|
|
&& (strncmp (term, "iris-ansi", 9) == 0
|
|
|
|
|| strncmp (term, "xterm", 5) == 0
|
|
|
|
|| strncmp (term, "rxvt", 4) == 0
|
|
|
|
|| strcmp (term, "screen") == 0)))
|
1998-02-27 07:54:42 +03:00
|
|
|
define_sequences (xterm_key_defines);
|
2003-05-30 23:56:43 +04:00
|
|
|
|
1998-05-20 06:19:17 +04:00
|
|
|
/* load some additional keys (e.g. direct Alt-? support) */
|
2005-03-21 23:27:55 +03:00
|
|
|
load_xtra_key_defines ();
|
|
|
|
|
1998-05-20 06:19:17 +04:00
|
|
|
#ifdef __QNX__
|
2003-05-30 23:56:43 +04:00
|
|
|
if (term && strncmp (term, "qnx", 3) == 0) {
|
1998-05-20 06:19:17 +04:00
|
|
|
/* Modify the default value of use_8th_bit_as_meta: we would
|
|
|
|
* like to provide a working mc for a newbie who knows nothing
|
|
|
|
* about [Options|Display bits|Full 8 bits input]...
|
2006-01-07 15:49:08 +03:00
|
|
|
*
|
|
|
|
* Don't use 'meta'-bit, when we are dealing with a
|
1998-05-20 06:19:17 +04:00
|
|
|
* 'qnx*'-type terminal: clear the default value!
|
|
|
|
* These terminal types use 0xFF as an escape character,
|
|
|
|
* so use_8th_bit_as_meta==1 must not be enabled!
|
2006-01-07 15:49:08 +03:00
|
|
|
*
|
1998-05-20 06:19:17 +04:00
|
|
|
* [mc-4.1.21+,slint.c/getch(): the DEC_8BIT_HACK stuff
|
|
|
|
* is not used now (doesn't even depend on use_8th_bit_as_meta
|
|
|
|
* as in mc-3.1.2)...GREAT!...no additional code is required!]
|
|
|
|
*/
|
|
|
|
use_8th_bit_as_meta = 0;
|
|
|
|
}
|
2005-03-21 23:27:55 +03:00
|
|
|
#endif /* __QNX__ */
|
2001-06-06 02:08:31 +04:00
|
|
|
|
|
|
|
#ifdef HAVE_TEXTMODE_X11_SUPPORT
|
2003-02-23 08:05:49 +03:00
|
|
|
init_key_x11 ();
|
2005-03-21 23:27:55 +03:00
|
|
|
#endif /* HAVE_TEXTMODE_X11_SUPPORT */
|
2004-09-26 04:58:47 +04:00
|
|
|
|
2006-01-07 15:49:08 +03:00
|
|
|
/* Load the qansi-m key definitions
|
2004-09-26 04:58:47 +04:00
|
|
|
if we are running under the qansi-m terminal */
|
2006-01-07 15:49:08 +03:00
|
|
|
if (term != NULL && (strncmp (term, "qansi-m", 7) == 0)) {
|
2005-03-21 23:27:55 +03:00
|
|
|
define_sequences (qansi_key_defines);
|
2004-09-26 04:58:47 +04:00
|
|
|
}
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* This has to be called after SLang_init_tty/slint_init */
|
|
|
|
void init_key_input_fd (void)
|
|
|
|
{
|
|
|
|
#ifdef HAVE_SLANG
|
|
|
|
input_fd = SLang_TT_Read_FD;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-12-03 00:27:27 +03:00
|
|
|
static void
|
|
|
|
xmouse_get_event (Gpm_Event *ev)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
|
|
|
int btn;
|
|
|
|
static struct timeval tv1 = { 0, 0 }; /* Force first click as single */
|
|
|
|
static struct timeval tv2;
|
|
|
|
static int clicks;
|
2001-08-18 23:27:31 +04:00
|
|
|
static int last_btn = 0;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
/* Decode Xterm mouse information to a GPM style event */
|
|
|
|
|
|
|
|
/* Variable btn has following meaning: */
|
|
|
|
/* 0 = btn1 dn, 1 = btn2 dn, 2 = btn3 dn, 3 = btn up */
|
2002-09-04 02:23:27 +04:00
|
|
|
btn = getch () - 32;
|
2006-01-07 15:49:08 +03:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
/* There seems to be no way of knowing which button was released */
|
|
|
|
/* So we assume all the buttons were released */
|
|
|
|
|
2006-01-07 15:49:08 +03:00
|
|
|
if (btn == 3) {
|
2001-08-18 23:27:31 +04:00
|
|
|
if (last_btn) {
|
|
|
|
ev->type = GPM_UP | (GPM_SINGLE << clicks);
|
|
|
|
ev->buttons = 0;
|
|
|
|
last_btn = 0;
|
|
|
|
GET_TIME (tv1);
|
|
|
|
clicks = 0;
|
|
|
|
} else {
|
|
|
|
/* Bogus event, maybe mouse wheel */
|
|
|
|
ev->type = 0;
|
|
|
|
}
|
1998-02-27 07:54:42 +03:00
|
|
|
} else {
|
2005-09-28 21:21:53 +04:00
|
|
|
if (btn >= 32 && btn <= 34) {
|
|
|
|
btn -= 32;
|
|
|
|
ev->type = GPM_DRAG;
|
|
|
|
} else
|
|
|
|
ev->type = GPM_DOWN;
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
GET_TIME (tv2);
|
2006-01-07 15:49:08 +03:00
|
|
|
if (tv1.tv_sec && (DIF_TIME (tv1,tv2) < double_click_speed)) {
|
1998-02-27 07:54:42 +03:00
|
|
|
clicks++;
|
|
|
|
clicks %= 3;
|
|
|
|
} else
|
|
|
|
clicks = 0;
|
2006-01-07 15:49:08 +03:00
|
|
|
|
|
|
|
switch (btn) {
|
1998-02-27 07:54:42 +03:00
|
|
|
case 0:
|
2006-01-07 15:49:08 +03:00
|
|
|
ev->buttons = GPM_B_LEFT;
|
|
|
|
break;
|
1998-02-27 07:54:42 +03:00
|
|
|
case 1:
|
2006-01-07 15:49:08 +03:00
|
|
|
ev->buttons = GPM_B_MIDDLE;
|
|
|
|
break;
|
1998-02-27 07:54:42 +03:00
|
|
|
case 2:
|
2006-01-07 15:49:08 +03:00
|
|
|
ev->buttons = GPM_B_RIGHT;
|
|
|
|
break;
|
2002-09-21 04:11:59 +04:00
|
|
|
case 64:
|
2006-01-07 15:49:08 +03:00
|
|
|
ev->buttons = GPM_B_UP;
|
|
|
|
clicks = 0;
|
|
|
|
break;
|
2002-09-21 04:11:59 +04:00
|
|
|
case 65:
|
2006-01-07 15:49:08 +03:00
|
|
|
ev->buttons = GPM_B_DOWN;
|
|
|
|
clicks = 0;
|
|
|
|
break;
|
1998-02-27 07:54:42 +03:00
|
|
|
default:
|
2006-01-07 15:49:08 +03:00
|
|
|
/* Nothing */
|
2001-08-18 23:27:31 +04:00
|
|
|
ev->type = 0;
|
|
|
|
ev->buttons = 0;
|
2006-01-07 15:49:08 +03:00
|
|
|
break;
|
|
|
|
}
|
2001-08-18 23:27:31 +04:00
|
|
|
last_btn = ev->buttons;
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
/* Coordinates are 33-based */
|
|
|
|
/* Transform them to 1-based */
|
2002-09-04 02:23:27 +04:00
|
|
|
ev->x = getch () - 32;
|
|
|
|
ev->y = getch () - 32;
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
2004-08-30 03:27:40 +04:00
|
|
|
static key_def *create_sequence (const char *seq, int code, int action)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
|
|
|
key_def *base, *p, *attach;
|
|
|
|
|
2006-01-07 15:49:08 +03:00
|
|
|
for (base = attach = NULL; *seq; seq++) {
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 04:08:30 +03:00
|
|
|
p = g_new (key_def, 1);
|
1998-02-27 07:54:42 +03:00
|
|
|
if (!base) base = p;
|
|
|
|
if (attach) attach->child = p;
|
2006-01-07 15:49:08 +03:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
p->ch = *seq;
|
|
|
|
p->code = code;
|
|
|
|
p->child = p->next = NULL;
|
|
|
|
if (!seq[1])
|
|
|
|
p->action = action;
|
|
|
|
else
|
|
|
|
p->action = MCKEY_NOACTION;
|
|
|
|
attach = p;
|
|
|
|
}
|
|
|
|
return base;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The maximum sequence length (32 + null terminator) */
|
2001-10-26 14:21:25 +04:00
|
|
|
#define SEQ_BUFFER_LEN 33
|
|
|
|
static int seq_buffer [SEQ_BUFFER_LEN];
|
1998-02-27 07:54:42 +03:00
|
|
|
static int *seq_append = 0;
|
|
|
|
|
|
|
|
static int push_char (int c)
|
|
|
|
{
|
|
|
|
if (!seq_append)
|
|
|
|
seq_append = seq_buffer;
|
2006-01-07 15:49:08 +03:00
|
|
|
|
2001-10-26 14:21:25 +04:00
|
|
|
if (seq_append == &(seq_buffer [SEQ_BUFFER_LEN-2]))
|
1998-02-27 07:54:42 +03:00
|
|
|
return 0;
|
|
|
|
*(seq_append++) = c;
|
|
|
|
*seq_append = 0;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2001-08-14 08:48:26 +04:00
|
|
|
/*
|
|
|
|
* Return 1 on success, 0 on error.
|
|
|
|
* An error happens if SEQ is a beginning of an existing longer sequence.
|
|
|
|
*/
|
2004-08-29 20:42:40 +04:00
|
|
|
int define_sequence (int code, const char *seq, int action)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
|
|
|
key_def *base;
|
|
|
|
|
2001-10-26 14:21:25 +04:00
|
|
|
if (strlen (seq) > SEQ_BUFFER_LEN-1)
|
2001-08-14 08:48:26 +04:00
|
|
|
return 0;
|
2006-01-07 15:49:08 +03:00
|
|
|
|
|
|
|
for (base = keys; (base != 0) && *seq; ) {
|
|
|
|
if (*seq == base->ch) {
|
|
|
|
if (base->child == 0) {
|
|
|
|
if (*(seq+1)) {
|
1998-02-27 07:54:42 +03:00
|
|
|
base->child = create_sequence (seq+1, code, action);
|
2001-08-14 08:48:26 +04:00
|
|
|
return 1;
|
1998-02-27 07:54:42 +03:00
|
|
|
} else {
|
2001-08-14 08:48:26 +04:00
|
|
|
/* The sequence matches an existing one. */
|
2006-01-07 15:49:08 +03:00
|
|
|
base->code = code;
|
|
|
|
base->action = action;
|
2001-08-14 08:48:26 +04:00
|
|
|
return 1;
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
base = base->child;
|
|
|
|
seq++;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (base->next)
|
|
|
|
base = base->next;
|
|
|
|
else {
|
|
|
|
base->next = create_sequence (seq, code, action);
|
2001-08-14 08:48:26 +04:00
|
|
|
return 1;
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2001-08-14 08:48:26 +04:00
|
|
|
|
|
|
|
if (!*seq) {
|
|
|
|
/* Attempt to redefine a sequence with a shorter sequence. */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
keys = create_sequence (seq, code, action);
|
2001-08-14 08:48:26 +04:00
|
|
|
return 1;
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static int *pending_keys;
|
|
|
|
|
2002-12-23 12:46:28 +03:00
|
|
|
/* Apply corrections for the keycode generated in get_key_code() */
|
1998-12-03 00:27:27 +03:00
|
|
|
static int
|
2002-12-23 12:46:28 +03:00
|
|
|
correct_key_code (int code)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
2002-12-23 12:46:28 +03:00
|
|
|
unsigned int c = code & ~KEY_M_MASK; /* code without modifier */
|
|
|
|
unsigned int mod = code & KEY_M_MASK; /* modifier */
|
2004-09-26 04:58:47 +04:00
|
|
|
#ifdef __QNXNTO__
|
|
|
|
unsigned int qmod; /* bunch of the QNX console
|
|
|
|
modifiers needs unchanged */
|
|
|
|
#endif /* __QNXNTO__ */
|
2002-12-21 10:34:49 +03:00
|
|
|
|
2002-12-27 19:27:44 +03:00
|
|
|
/*
|
|
|
|
* Add key modifiers directly from X11 or OS.
|
|
|
|
* Ordinary characters only get modifiers from sequences.
|
|
|
|
*/
|
|
|
|
if (c < 32 || c >= 256) {
|
|
|
|
mod |= get_modifier ();
|
|
|
|
}
|
2002-12-23 12:46:28 +03:00
|
|
|
|
|
|
|
/* This is needed if the newline is reported as carriage return */
|
1998-02-27 07:54:42 +03:00
|
|
|
if (c == '\r')
|
2002-12-23 12:46:28 +03:00
|
|
|
c = '\n';
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2002-12-23 12:46:28 +03:00
|
|
|
/* This is reported to be useful on AIX */
|
1998-02-27 07:54:42 +03:00
|
|
|
if (c == KEY_SCANCEL)
|
2002-12-23 12:46:28 +03:00
|
|
|
c = '\t';
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2002-12-26 02:30:49 +03:00
|
|
|
/* Convert Shift+Tab and Ctrl+Tab to Back Tab */
|
|
|
|
if ((c == '\t') && (mod & (KEY_M_SHIFT | KEY_M_CTRL))) {
|
|
|
|
c = KEY_BTAB;
|
|
|
|
mod = 0;
|
|
|
|
}
|
|
|
|
|
2002-12-23 12:46:28 +03:00
|
|
|
/* F0 is the same as F10 for out purposes */
|
|
|
|
if (c == KEY_F (0))
|
|
|
|
c = KEY_F (10);
|
1998-04-01 02:36:24 +04:00
|
|
|
|
2002-12-23 12:46:28 +03:00
|
|
|
/*
|
|
|
|
* We are not interested if Ctrl was pressed when entering control
|
|
|
|
* characters, so assume that it was. When checking for such keys,
|
|
|
|
* XCTRL macro should be used. In some cases, we are interested,
|
|
|
|
* e.g. to distinguish Ctrl-Enter from Enter.
|
|
|
|
*/
|
|
|
|
if (c < 32 && c != ESC_CHAR && c != '\t' && c != '\n') {
|
|
|
|
mod |= KEY_M_CTRL;
|
|
|
|
}
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2004-09-26 04:58:47 +04:00
|
|
|
#ifdef __QNXNTO__
|
|
|
|
qmod=get_modifier();
|
|
|
|
|
|
|
|
if ((c == 127) && (mod==0)) /* Add Ctrl/Alt/Shift-BackSpace */
|
|
|
|
{
|
|
|
|
mod |= get_modifier();
|
2006-01-07 15:49:08 +03:00
|
|
|
c = KEY_BACKSPACE;
|
2004-09-26 04:58:47 +04:00
|
|
|
}
|
2006-01-07 15:49:08 +03:00
|
|
|
|
2004-09-26 04:58:47 +04:00
|
|
|
if ((c=='0') && (mod==0)) /* Add Shift-Insert on key pad */
|
|
|
|
{
|
2006-01-07 15:49:08 +03:00
|
|
|
if ((qmod & KEY_M_SHIFT) == KEY_M_SHIFT)
|
|
|
|
{
|
2004-09-26 04:58:47 +04:00
|
|
|
mod = KEY_M_SHIFT;
|
2006-01-07 15:49:08 +03:00
|
|
|
c = KEY_IC;
|
|
|
|
}
|
2004-09-26 04:58:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((c=='.') && (mod==0)) /* Add Shift-Del on key pad */
|
|
|
|
{
|
2006-01-07 15:49:08 +03:00
|
|
|
if ((qmod & KEY_M_SHIFT) == KEY_M_SHIFT)
|
|
|
|
{
|
2004-09-26 04:58:47 +04:00
|
|
|
mod = KEY_M_SHIFT;
|
2006-01-07 15:49:08 +03:00
|
|
|
c = KEY_DC;
|
|
|
|
}
|
2004-09-26 04:58:47 +04:00
|
|
|
}
|
|
|
|
#endif /* __QNXNTO__ */
|
|
|
|
|
2003-03-10 23:27:54 +03:00
|
|
|
/* Unrecognized 0177 is delete (preserve Ctrl) */
|
|
|
|
if (c == 0177) {
|
|
|
|
c = KEY_BACKSPACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Unrecognized Ctrl-d is delete */
|
|
|
|
if (c == (31 & 'd')) {
|
|
|
|
c = KEY_DC;
|
|
|
|
mod &= ~KEY_M_CTRL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Unrecognized Ctrl-h is backspace */
|
|
|
|
if (c == (31 & 'h')) {
|
|
|
|
c = KEY_BACKSPACE;
|
|
|
|
mod &= ~KEY_M_CTRL;
|
|
|
|
}
|
|
|
|
|
2003-06-09 09:59:00 +04:00
|
|
|
/* Shift+BackSpace is backspace */
|
|
|
|
if (c == KEY_BACKSPACE && (mod & KEY_M_SHIFT)) {
|
|
|
|
mod &= ~KEY_M_SHIFT;
|
|
|
|
}
|
|
|
|
|
2002-12-23 12:46:28 +03:00
|
|
|
/* Convert Shift+Fn to F(n+10) */
|
|
|
|
if (c >= KEY_F (1) && c <= KEY_F (10) && (mod & KEY_M_SHIFT)) {
|
|
|
|
c += 10;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Remove Shift information from function keys */
|
|
|
|
if (c >= KEY_F (1) && c <= KEY_F (20)) {
|
|
|
|
mod &= ~KEY_M_SHIFT;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!alternate_plus_minus)
|
|
|
|
switch (c) {
|
|
|
|
case KEY_KP_ADD:
|
|
|
|
c = '+';
|
|
|
|
break;
|
|
|
|
case KEY_KP_SUBTRACT:
|
|
|
|
c = '-';
|
|
|
|
break;
|
|
|
|
case KEY_KP_MULTIPLY:
|
|
|
|
c = '*';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (mod | c);
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int get_key_code (int no_delay)
|
|
|
|
{
|
|
|
|
int c;
|
|
|
|
static key_def *this = NULL, *parent;
|
|
|
|
static struct timeval esctime = { -1, -1 };
|
|
|
|
static int lastnodelay = -1;
|
2006-01-07 15:49:08 +03:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
if (no_delay != lastnodelay) {
|
2006-01-07 15:49:08 +03:00
|
|
|
this = NULL;
|
|
|
|
lastnodelay = no_delay;
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
pend_send:
|
2006-01-07 15:49:08 +03:00
|
|
|
if (pending_keys) {
|
1998-02-27 07:54:42 +03:00
|
|
|
int d = *pending_keys++;
|
|
|
|
check_pend:
|
2006-01-07 15:49:08 +03:00
|
|
|
if (!*pending_keys) {
|
1998-02-27 07:54:42 +03:00
|
|
|
pending_keys = 0;
|
|
|
|
seq_append = 0;
|
|
|
|
}
|
2006-01-07 15:49:08 +03:00
|
|
|
if (d == ESC_CHAR && pending_keys) {
|
1998-02-27 07:54:42 +03:00
|
|
|
d = ALT(*pending_keys++);
|
|
|
|
goto check_pend;
|
|
|
|
}
|
2006-09-19 01:06:58 +04:00
|
|
|
if ((d > 127 && d < 256) && use_8th_bit_as_meta)
|
1998-02-27 07:54:42 +03:00
|
|
|
d = ALT(d & 0x7f);
|
|
|
|
this = NULL;
|
|
|
|
return correct_key_code (d);
|
|
|
|
}
|
|
|
|
|
|
|
|
nodelay_try_again:
|
|
|
|
if (no_delay) {
|
2006-01-07 15:49:08 +03:00
|
|
|
nodelay (stdscr, TRUE);
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
2002-09-04 02:23:27 +04:00
|
|
|
c = getch ();
|
2002-02-06 08:23:50 +03:00
|
|
|
#if defined(USE_NCURSES) && defined(KEY_RESIZE)
|
|
|
|
if (c == KEY_RESIZE)
|
2006-01-07 15:49:08 +03:00
|
|
|
goto nodelay_try_again;
|
2002-02-06 08:23:50 +03:00
|
|
|
#endif
|
1998-02-27 07:54:42 +03:00
|
|
|
if (no_delay) {
|
2006-01-07 15:49:08 +03:00
|
|
|
nodelay (stdscr, FALSE);
|
|
|
|
if (c == -1) {
|
|
|
|
if (this != NULL && parent != NULL &&
|
|
|
|
parent->action == MCKEY_ESCAPE && old_esc_mode) {
|
|
|
|
struct timeval current, timeout;
|
|
|
|
|
|
|
|
if (esctime.tv_sec == -1)
|
|
|
|
return -1;
|
|
|
|
GET_TIME (current);
|
2006-08-10 01:19:18 +04:00
|
|
|
timeout.tv_sec = keyboard_key_timeout / 1000000 + esctime.tv_sec;
|
|
|
|
timeout.tv_usec = keyboard_key_timeout % 1000000 + esctime.tv_usec;
|
2006-01-07 15:49:08 +03:00
|
|
|
if (timeout.tv_usec > 1000000) {
|
|
|
|
timeout.tv_usec -= 1000000;
|
|
|
|
timeout.tv_sec++;
|
|
|
|
}
|
|
|
|
if (current.tv_sec < timeout.tv_sec)
|
|
|
|
return -1;
|
|
|
|
if (current.tv_sec == timeout.tv_sec &&
|
|
|
|
current.tv_usec < timeout.tv_usec)
|
|
|
|
return -1;
|
|
|
|
this = NULL;
|
1998-02-27 07:54:42 +03:00
|
|
|
pending_keys = seq_append = NULL;
|
|
|
|
return ESC_CHAR;
|
2006-01-07 15:49:08 +03:00
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
} else if (c == -1) {
|
1998-02-27 07:54:42 +03:00
|
|
|
/* Maybe we got an incomplete match.
|
|
|
|
This we do only in delay mode, since otherwise
|
2002-11-06 09:08:11 +03:00
|
|
|
getch can return -1 at any time. */
|
1998-02-27 07:54:42 +03:00
|
|
|
if (seq_append) {
|
|
|
|
pending_keys = seq_buffer;
|
|
|
|
goto pend_send;
|
|
|
|
}
|
|
|
|
this = NULL;
|
2002-11-06 09:08:11 +03:00
|
|
|
return -1;
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
2006-01-07 15:49:08 +03:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
/* Search the key on the root */
|
|
|
|
if (!no_delay || this == NULL) {
|
2006-01-07 15:49:08 +03:00
|
|
|
this = keys;
|
|
|
|
parent = NULL;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2006-09-19 01:06:58 +04:00
|
|
|
if ((c > 127 && c < 256) && use_8th_bit_as_meta) {
|
2006-01-07 15:49:08 +03:00
|
|
|
c &= 0x7f;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
/* The first sequence defined starts with esc */
|
|
|
|
parent = keys;
|
|
|
|
this = keys->child;
|
2006-01-07 15:49:08 +03:00
|
|
|
}
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
2006-01-07 15:49:08 +03:00
|
|
|
while (this) {
|
|
|
|
if (c == this->ch) {
|
|
|
|
if (this->child) {
|
|
|
|
if (!push_char (c)) {
|
1998-02-27 07:54:42 +03:00
|
|
|
pending_keys = seq_buffer;
|
|
|
|
goto pend_send;
|
|
|
|
}
|
|
|
|
parent = this;
|
|
|
|
this = this->child;
|
|
|
|
if (parent->action == MCKEY_ESCAPE && old_esc_mode) {
|
|
|
|
if (no_delay) {
|
2006-01-07 15:49:08 +03:00
|
|
|
GET_TIME (esctime);
|
|
|
|
if (this == NULL) {
|
|
|
|
/* Shouldn't happen */
|
|
|
|
fputs ("Internal error\n", stderr);
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
goto nodelay_try_again;
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
esctime.tv_sec = -1;
|
|
|
|
c = xgetch_second ();
|
2002-11-06 09:08:11 +03:00
|
|
|
if (c == -1) {
|
2006-01-07 15:49:08 +03:00
|
|
|
pending_keys = seq_append = NULL;
|
|
|
|
this = NULL;
|
|
|
|
return ESC_CHAR;
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (no_delay)
|
2006-01-07 15:49:08 +03:00
|
|
|
goto nodelay_try_again;
|
2002-09-04 02:23:27 +04:00
|
|
|
c = getch ();
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* We got a complete match, return and reset search */
|
|
|
|
int code;
|
2006-01-07 15:49:08 +03:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
pending_keys = seq_append = NULL;
|
|
|
|
code = this->code;
|
|
|
|
this = NULL;
|
|
|
|
return correct_key_code (code);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (this->next)
|
|
|
|
this = this->next;
|
|
|
|
else {
|
2006-01-07 15:49:08 +03:00
|
|
|
if (parent != NULL && parent->action == MCKEY_ESCAPE) {
|
2003-06-14 09:19:19 +04:00
|
|
|
|
|
|
|
/* Convert escape-digits to F-keys */
|
|
|
|
if (isdigit(c))
|
2006-01-07 15:49:08 +03:00
|
|
|
c = KEY_F (c - '0');
|
1998-02-27 07:54:42 +03:00
|
|
|
else if (c == ' ')
|
|
|
|
c = ESC_CHAR;
|
2006-01-07 15:49:08 +03:00
|
|
|
else
|
2003-06-14 09:19:19 +04:00
|
|
|
c = ALT(c);
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
pending_keys = seq_append = NULL;
|
|
|
|
this = NULL;
|
|
|
|
return correct_key_code (c);
|
|
|
|
}
|
|
|
|
/* Did not find a match or {c} was changed in the if above,
|
|
|
|
so we have to return everything we had skipped
|
|
|
|
*/
|
|
|
|
push_char (c);
|
|
|
|
pending_keys = seq_buffer;
|
|
|
|
goto pend_send;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this = NULL;
|
|
|
|
return correct_key_code (c);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If set timeout is set, then we wait 0.1 seconds, else, we block */
|
1998-12-03 00:27:27 +03:00
|
|
|
static void
|
|
|
|
try_channels (int set_timeout)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
|
|
|
struct timeval timeout;
|
|
|
|
static fd_set select_set;
|
|
|
|
struct timeval *timeptr;
|
|
|
|
int v;
|
2002-08-25 09:44:57 +04:00
|
|
|
int maxfdp;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2006-01-07 15:49:08 +03:00
|
|
|
while (1) {
|
1998-02-27 07:54:42 +03:00
|
|
|
FD_ZERO (&select_set);
|
|
|
|
FD_SET (input_fd, &select_set); /* Add stdin */
|
2002-08-25 09:44:57 +04:00
|
|
|
maxfdp = max (add_selects (&select_set), input_fd);
|
2006-01-07 15:49:08 +03:00
|
|
|
|
|
|
|
if (set_timeout) {
|
1998-02-27 07:54:42 +03:00
|
|
|
timeout.tv_sec = 0;
|
|
|
|
timeout.tv_usec = 100000;
|
|
|
|
timeptr = &timeout;
|
|
|
|
} else
|
|
|
|
timeptr = 0;
|
|
|
|
|
2002-08-25 09:44:57 +04:00
|
|
|
v = select (maxfdp + 1, &select_set, NULL, NULL, timeptr);
|
2006-01-07 15:49:08 +03:00
|
|
|
if (v > 0) {
|
1998-02-27 07:54:42 +03:00
|
|
|
check_selects (&select_set);
|
|
|
|
if (FD_ISSET (input_fd, &select_set))
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Workaround for System V Curses vt100 bug */
|
|
|
|
static int getch_with_delay (void)
|
|
|
|
{
|
|
|
|
int c;
|
|
|
|
|
|
|
|
/* This routine could be used on systems without mouse support,
|
|
|
|
so we need to do the select check :-( */
|
2006-01-07 15:49:08 +03:00
|
|
|
while (1) {
|
1998-02-27 07:54:42 +03:00
|
|
|
if (!pending_keys)
|
|
|
|
try_channels (0);
|
|
|
|
|
|
|
|
/* Try to get a character */
|
|
|
|
c = get_key_code (0);
|
2002-11-06 09:08:11 +03:00
|
|
|
if (c != -1)
|
1998-02-27 07:54:42 +03:00
|
|
|
break;
|
|
|
|
/* Failed -> wait 0.1 secs and try again */
|
|
|
|
try_channels (1);
|
|
|
|
}
|
|
|
|
/* Success -> return the character */
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Returns a character read from stdin with appropriate interpretation */
|
|
|
|
/* Also takes care of generated mouse events */
|
|
|
|
/* Returns EV_MOUSE if it is a mouse event */
|
|
|
|
/* Returns EV_NONE if non-blocking or interrupt set and nothing was done */
|
2002-08-31 10:40:47 +04:00
|
|
|
int
|
2003-12-24 10:21:34 +03:00
|
|
|
get_event (struct Gpm_Event *event, int redo_event, int block)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
|
|
|
int c;
|
2002-08-31 10:40:47 +04:00
|
|
|
static int flag; /* Return value from select */
|
1998-02-27 07:54:42 +03:00
|
|
|
#ifdef HAVE_LIBGPM
|
2003-10-26 07:03:07 +03:00
|
|
|
static struct Gpm_Event ev; /* Mouse event */
|
1998-02-27 07:54:42 +03:00
|
|
|
#endif
|
|
|
|
struct timeval timeout;
|
|
|
|
struct timeval *time_addr = NULL;
|
|
|
|
static int dirty = 3;
|
|
|
|
|
2002-08-31 10:40:47 +04:00
|
|
|
if ((dirty == 3) || is_idle ()) {
|
1998-02-27 07:54:42 +03:00
|
|
|
mc_refresh ();
|
|
|
|
doupdate ();
|
|
|
|
dirty = 1;
|
|
|
|
} else
|
|
|
|
dirty++;
|
|
|
|
|
|
|
|
vfs_timeout_handler ();
|
2002-08-31 10:40:47 +04:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
/* Ok, we use (event->x < 0) to signal that the event does not contain
|
|
|
|
a suitable position for the mouse, so we can't use show_mouse_pointer
|
|
|
|
on it.
|
2002-08-31 10:40:47 +04:00
|
|
|
*/
|
|
|
|
if (event->x > 0) {
|
1998-02-27 07:54:42 +03:00
|
|
|
show_mouse_pointer (event->x, event->y);
|
|
|
|
if (!redo_event)
|
|
|
|
event->x = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Repeat if using mouse */
|
2001-09-17 08:43:58 +04:00
|
|
|
while (mouse_enabled && !pending_keys) {
|
2002-08-31 10:40:47 +04:00
|
|
|
int maxfdp;
|
|
|
|
fd_set select_set;
|
|
|
|
|
|
|
|
FD_ZERO (&select_set);
|
|
|
|
FD_SET (input_fd, &select_set);
|
|
|
|
maxfdp = max (add_selects (&select_set), input_fd);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
#ifdef HAVE_LIBGPM
|
2002-08-31 10:40:47 +04:00
|
|
|
if (use_mouse_p == MOUSE_GPM) {
|
2003-12-24 10:21:34 +03:00
|
|
|
if (gpm_fd < 0) {
|
2002-09-08 19:50:02 +04:00
|
|
|
/* Connection to gpm broken, possibly gpm has died */
|
|
|
|
mouse_enabled = 0;
|
|
|
|
use_mouse_p = MOUSE_NONE;
|
|
|
|
break;
|
2003-12-24 10:21:34 +03:00
|
|
|
} else {
|
|
|
|
FD_SET (gpm_fd, &select_set);
|
|
|
|
maxfdp = max (maxfdp, gpm_fd);
|
2002-09-08 19:50:02 +04:00
|
|
|
}
|
2002-08-31 10:40:47 +04:00
|
|
|
}
|
1998-02-27 07:54:42 +03:00
|
|
|
#endif
|
|
|
|
|
2002-08-31 10:40:47 +04:00
|
|
|
if (redo_event) {
|
|
|
|
timeout.tv_usec = mou_auto_repeat * 1000;
|
|
|
|
timeout.tv_sec = 0;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2002-08-31 10:40:47 +04:00
|
|
|
time_addr = &timeout;
|
|
|
|
} else {
|
|
|
|
int seconds;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2002-08-31 10:40:47 +04:00
|
|
|
if ((seconds = vfs_timeouts ())) {
|
|
|
|
/* the timeout could be improved and actually be
|
|
|
|
* the number of seconds until the next vfs entry
|
|
|
|
* timeouts in the stamp list.
|
|
|
|
*/
|
|
|
|
|
|
|
|
timeout.tv_sec = seconds;
|
1998-02-27 07:54:42 +03:00
|
|
|
timeout.tv_usec = 0;
|
2002-08-31 10:40:47 +04:00
|
|
|
time_addr = &timeout;
|
|
|
|
} else
|
|
|
|
time_addr = NULL;
|
|
|
|
}
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2006-11-08 16:37:24 +03:00
|
|
|
if (!block || winch_flag) {
|
2002-08-31 10:40:47 +04:00
|
|
|
time_addr = &timeout;
|
|
|
|
timeout.tv_sec = 0;
|
|
|
|
timeout.tv_usec = 0;
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
2002-08-31 10:40:47 +04:00
|
|
|
enable_interrupt_key ();
|
|
|
|
flag = select (maxfdp + 1, &select_set, NULL, NULL, time_addr);
|
|
|
|
disable_interrupt_key ();
|
|
|
|
|
|
|
|
/* select timed out: it could be for any of the following reasons:
|
|
|
|
* redo_event -> it was because of the MOU_REPEAT handler
|
|
|
|
* !block -> we did not block in the select call
|
|
|
|
* else -> 10 second timeout to check the vfs status.
|
|
|
|
*/
|
|
|
|
if (flag == 0) {
|
|
|
|
if (redo_event)
|
|
|
|
return EV_MOUSE;
|
2006-11-08 16:37:24 +03:00
|
|
|
if (!block || winch_flag)
|
2002-08-31 10:40:47 +04:00
|
|
|
return EV_NONE;
|
|
|
|
vfs_timeout_handler ();
|
|
|
|
}
|
|
|
|
if (flag == -1 && errno == EINTR)
|
|
|
|
return EV_NONE;
|
|
|
|
|
|
|
|
check_selects (&select_set);
|
|
|
|
|
|
|
|
if (FD_ISSET (input_fd, &select_set))
|
|
|
|
break;
|
1998-02-27 07:54:42 +03:00
|
|
|
#ifdef HAVE_LIBGPM
|
2003-12-24 10:21:34 +03:00
|
|
|
if (use_mouse_p == MOUSE_GPM && gpm_fd > 0
|
|
|
|
&& FD_ISSET (gpm_fd, &select_set)) {
|
2001-09-17 08:43:58 +04:00
|
|
|
Gpm_GetEvent (&ev);
|
|
|
|
Gpm_FitEvent (&ev);
|
1998-02-27 07:54:42 +03:00
|
|
|
*event = ev;
|
|
|
|
return EV_MOUSE;
|
|
|
|
}
|
2002-08-31 10:40:47 +04:00
|
|
|
#endif /* !HAVE_LIBGPM */
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
2001-09-15 05:18:11 +04:00
|
|
|
#ifndef HAVE_SLANG
|
2002-08-31 10:40:47 +04:00
|
|
|
flag = is_wintouched (stdscr);
|
1998-02-27 07:54:42 +03:00
|
|
|
untouchwin (stdscr);
|
2002-08-31 10:40:47 +04:00
|
|
|
#endif /* !HAVE_SLANG */
|
|
|
|
c = block ? getch_with_delay () : get_key_code (1);
|
1998-12-02 08:18:20 +03:00
|
|
|
|
2001-09-15 05:18:11 +04:00
|
|
|
#ifndef HAVE_SLANG
|
1998-02-27 07:54:42 +03:00
|
|
|
if (flag)
|
2002-08-31 10:40:47 +04:00
|
|
|
touchwin (stdscr);
|
|
|
|
#endif /* !HAVE_SLANG */
|
|
|
|
|
2001-09-15 05:18:11 +04:00
|
|
|
if (c == MCKEY_MOUSE
|
|
|
|
#ifdef KEY_MOUSE
|
2002-08-31 10:40:47 +04:00
|
|
|
|| c == KEY_MOUSE
|
|
|
|
#endif /* KEY_MOUSE */
|
|
|
|
) {
|
2001-09-15 05:18:11 +04:00
|
|
|
/* Mouse event */
|
2002-08-31 10:40:47 +04:00
|
|
|
xmouse_get_event (event);
|
2001-08-18 23:27:31 +04:00
|
|
|
if (event->type)
|
|
|
|
return EV_MOUSE;
|
|
|
|
else
|
|
|
|
return EV_NONE;
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return c;
|
1998-12-02 08:18:20 +03:00
|
|
|
}
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
/* Returns a key press, mouse events are discarded */
|
|
|
|
int mi_getch ()
|
|
|
|
{
|
|
|
|
Gpm_Event ev;
|
|
|
|
int key;
|
1998-04-15 10:05:34 +04:00
|
|
|
|
1998-04-15 10:15:42 +04:00
|
|
|
ev.x = -1;
|
2001-03-03 02:04:52 +03:00
|
|
|
while ((key = get_event (&ev, 0, 1)) == EV_NONE)
|
1998-02-27 07:54:42 +03:00
|
|
|
;
|
|
|
|
return key;
|
|
|
|
}
|
|
|
|
|
2001-07-20 20:19:28 +04:00
|
|
|
static int xgetch_second (void)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
|
|
|
fd_set Read_FD_Set;
|
|
|
|
int c;
|
|
|
|
struct timeval timeout;
|
|
|
|
|
2006-08-10 01:19:18 +04:00
|
|
|
timeout.tv_sec = keyboard_key_timeout / 1000000;
|
|
|
|
timeout.tv_usec = keyboard_key_timeout % 1000000;
|
1998-02-27 07:54:42 +03:00
|
|
|
nodelay (stdscr, TRUE);
|
|
|
|
FD_ZERO (&Read_FD_Set);
|
|
|
|
FD_SET (input_fd, &Read_FD_Set);
|
2002-08-25 09:44:57 +04:00
|
|
|
select (input_fd + 1, &Read_FD_Set, NULL, NULL, &timeout);
|
2002-09-04 02:23:27 +04:00
|
|
|
c = getch ();
|
1998-02-27 07:54:42 +03:00
|
|
|
nodelay (stdscr, FALSE);
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
1998-12-03 00:27:27 +03:00
|
|
|
static void
|
|
|
|
learn_store_key (char *buffer, char **p, int c)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
|
|
|
if (*p - buffer > 253)
|
2006-01-07 15:49:08 +03:00
|
|
|
return;
|
1998-02-27 07:54:42 +03:00
|
|
|
if (c == ESC_CHAR) {
|
2006-01-07 15:49:08 +03:00
|
|
|
*(*p)++ = '\\';
|
|
|
|
*(*p)++ = 'e';
|
1998-02-27 07:54:42 +03:00
|
|
|
} else if (c < ' ') {
|
2006-01-07 15:49:08 +03:00
|
|
|
*(*p)++ = '^';
|
|
|
|
*(*p)++ = c + 'a' - 1;
|
1998-02-27 07:54:42 +03:00
|
|
|
} else if (c == '^') {
|
2006-01-07 15:49:08 +03:00
|
|
|
*(*p)++ = '^';
|
|
|
|
*(*p)++ = '^';
|
1998-02-27 07:54:42 +03:00
|
|
|
} else
|
2006-01-07 15:49:08 +03:00
|
|
|
*(*p)++ = (char) c;
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
char *learn_key (void)
|
|
|
|
{
|
|
|
|
/* LEARN_TIMEOUT in usec */
|
|
|
|
#define LEARN_TIMEOUT 200000
|
|
|
|
|
|
|
|
fd_set Read_FD_Set;
|
|
|
|
struct timeval endtime;
|
|
|
|
struct timeval timeout;
|
2001-08-28 01:24:29 +04:00
|
|
|
int c;
|
1998-02-27 07:54:42 +03:00
|
|
|
char buffer [256];
|
|
|
|
char *p = buffer;
|
2006-01-07 15:49:08 +03:00
|
|
|
|
2001-08-28 01:24:29 +04:00
|
|
|
keypad(stdscr, FALSE); /* disable intepreting keys by ncurses */
|
2002-09-04 02:23:27 +04:00
|
|
|
c = getch ();
|
2002-11-06 09:08:11 +03:00
|
|
|
while (c == -1)
|
2006-01-07 15:49:08 +03:00
|
|
|
c = getch (); /* Sanity check, should be unnecessary */
|
1998-02-27 07:54:42 +03:00
|
|
|
learn_store_key (buffer, &p, c);
|
|
|
|
GET_TIME (endtime);
|
|
|
|
endtime.tv_usec += LEARN_TIMEOUT;
|
|
|
|
if (endtime.tv_usec > 1000000) {
|
2006-01-07 15:49:08 +03:00
|
|
|
endtime.tv_usec -= 1000000;
|
|
|
|
endtime.tv_sec++;
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
nodelay (stdscr, TRUE);
|
|
|
|
for (;;) {
|
2006-01-07 15:49:08 +03:00
|
|
|
while ((c = getch ()) == -1) {
|
|
|
|
GET_TIME (timeout);
|
|
|
|
timeout.tv_usec = endtime.tv_usec - timeout.tv_usec;
|
|
|
|
if (timeout.tv_usec < 0)
|
|
|
|
timeout.tv_sec++;
|
|
|
|
timeout.tv_sec = endtime.tv_sec - timeout.tv_sec;
|
|
|
|
if (timeout.tv_sec >= 0 && timeout.tv_usec > 0) {
|
|
|
|
FD_ZERO (&Read_FD_Set);
|
|
|
|
FD_SET (input_fd, &Read_FD_Set);
|
|
|
|
select (input_fd + 1, &Read_FD_Set, NULL, NULL, &timeout);
|
|
|
|
} else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (c == -1)
|
|
|
|
break;
|
2001-08-28 01:24:29 +04:00
|
|
|
learn_store_key (buffer, &p, c);
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
2001-08-28 01:24:29 +04:00
|
|
|
keypad(stdscr, TRUE);
|
1998-02-27 07:54:42 +03:00
|
|
|
nodelay (stdscr, FALSE);
|
|
|
|
*p = 0;
|
2009-02-06 01:40:32 +03:00
|
|
|
return g_strdup (buffer);
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
1998-04-01 02:36:24 +04:00
|
|
|
|
|
|
|
/* xterm and linux console only: set keypad to numeric or application
|
|
|
|
mode. Only in application keypad mode it's possible to distinguish
|
|
|
|
the '+' key and the '+' on the keypad ('*' and '-' ditto)*/
|
|
|
|
void
|
|
|
|
numeric_keypad_mode (void)
|
|
|
|
{
|
|
|
|
if (console_flag || xterm_flag) {
|
2003-03-11 15:23:08 +03:00
|
|
|
fputs ("\033>", stdout);
|
2006-01-07 15:49:08 +03:00
|
|
|
fflush (stdout);
|
1998-04-01 02:36:24 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
application_keypad_mode (void)
|
|
|
|
{
|
|
|
|
if (console_flag || xterm_flag) {
|
2006-01-07 15:49:08 +03:00
|
|
|
fputs ("\033=", stdout);
|
|
|
|
fflush (stdout);
|
1998-04-01 02:36:24 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2002-12-25 05:01:31 +03:00
|
|
|
/*
|
|
|
|
* Check if we are idle, i.e. there are no pending keyboard or mouse
|
|
|
|
* events. Return 1 is idle, 0 is there are pending events.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
is_idle (void)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
2002-12-25 05:01:31 +03:00
|
|
|
int maxfdp;
|
1998-02-27 07:54:42 +03:00
|
|
|
fd_set select_set;
|
|
|
|
struct timeval timeout;
|
2002-12-25 05:01:31 +03:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
FD_ZERO (&select_set);
|
2002-12-25 05:01:31 +03:00
|
|
|
FD_SET (input_fd, &select_set);
|
|
|
|
maxfdp = input_fd;
|
|
|
|
#ifdef HAVE_LIBGPM
|
2003-12-24 10:21:34 +03:00
|
|
|
if (use_mouse_p == MOUSE_GPM && mouse_enabled && gpm_fd > 0) {
|
2002-12-25 05:01:31 +03:00
|
|
|
FD_SET (gpm_fd, &select_set);
|
|
|
|
maxfdp = max (maxfdp, gpm_fd);
|
|
|
|
}
|
|
|
|
#endif
|
1998-02-27 07:54:42 +03:00
|
|
|
timeout.tv_sec = 0;
|
|
|
|
timeout.tv_usec = 0;
|
2003-01-28 01:37:32 +03:00
|
|
|
return (select (maxfdp + 1, &select_set, 0, 0, &timeout) <= 0);
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-12-21 11:43:15 +03:00
|
|
|
/*
|
|
|
|
* Get modifier state (shift, alt, ctrl) for the last key pressed.
|
|
|
|
* We are assuming that the state didn't change since the key press.
|
|
|
|
* This is only correct if get_modifier() is called very fast after
|
|
|
|
* the input was received, so that the user didn't release the
|
|
|
|
* modifier keys yet.
|
|
|
|
*/
|
|
|
|
static int
|
1998-12-03 00:27:27 +03:00
|
|
|
get_modifier (void)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
2002-12-21 10:34:49 +03:00
|
|
|
int result = 0;
|
2003-02-23 08:36:49 +03:00
|
|
|
#ifdef __QNXNTO__
|
|
|
|
int mod_status, shift_ext_status;
|
2003-03-10 11:47:37 +03:00
|
|
|
static int in_photon = 0;
|
|
|
|
static int ph_ig = 0;
|
|
|
|
PhCursorInfo_t cursor_info;
|
2003-03-10 17:38:12 +03:00
|
|
|
#endif /* __QNXNTO__ */
|
2002-12-21 10:34:49 +03:00
|
|
|
|
2001-06-05 20:41:44 +04:00
|
|
|
#ifdef HAVE_TEXTMODE_X11_SUPPORT
|
2003-02-23 08:05:49 +03:00
|
|
|
if (x11_window) {
|
2002-12-21 10:34:49 +03:00
|
|
|
Window root, child;
|
|
|
|
int root_x, root_y;
|
|
|
|
int win_x, win_y;
|
|
|
|
unsigned int mask;
|
1999-04-21 23:18:31 +04:00
|
|
|
|
2005-03-10 12:44:36 +03:00
|
|
|
mc_XQueryPointer (x11_display, x11_window, &root, &child, &root_x,
|
2002-12-23 12:46:28 +03:00
|
|
|
&root_y, &win_x, &win_y, &mask);
|
1999-04-21 23:18:31 +04:00
|
|
|
|
|
|
|
if (mask & ShiftMask)
|
2002-12-21 11:43:15 +03:00
|
|
|
result |= KEY_M_SHIFT;
|
2002-12-21 10:34:49 +03:00
|
|
|
if (mask & ControlMask)
|
2002-12-21 11:43:15 +03:00
|
|
|
result |= KEY_M_CTRL;
|
1999-04-21 23:18:31 +04:00
|
|
|
return result;
|
2002-12-21 11:43:15 +03:00
|
|
|
}
|
2003-03-10 17:38:12 +03:00
|
|
|
#endif /* HAVE_TEXTMODE_X11_SUPPORT */
|
2003-02-23 08:36:49 +03:00
|
|
|
#ifdef __QNXNTO__
|
2003-03-10 11:47:37 +03:00
|
|
|
|
|
|
|
if (in_photon == 0) {
|
|
|
|
/* First time here, let's load Photon library and attach
|
|
|
|
to Photon */
|
|
|
|
in_photon = -1;
|
2005-03-25 12:38:24 +03:00
|
|
|
if (getenv ("PHOTON2_PATH") != NULL) {
|
2003-03-10 17:38:12 +03:00
|
|
|
/* QNX 6.x has no support for RTLD_LAZY */
|
2005-03-25 12:38:24 +03:00
|
|
|
void *ph_handle = dlopen ("/usr/lib/libph.so", RTLD_NOW);
|
2003-03-10 17:38:12 +03:00
|
|
|
if (ph_handle != NULL) {
|
|
|
|
ph_attach = (ph_dv_f) dlsym (ph_handle, "PhAttach");
|
|
|
|
ph_input_group =
|
|
|
|
(ph_ov_f) dlsym (ph_handle, "PhInputGroup");
|
|
|
|
ph_query_cursor =
|
|
|
|
(ph_pqc_f) dlsym (ph_handle, "PhQueryCursor");
|
|
|
|
if ((ph_attach != NULL) && (ph_input_group != NULL)
|
|
|
|
&& (ph_query_cursor != NULL)) {
|
|
|
|
if ((*ph_attach) (0, 0)) { /* Attached */
|
|
|
|
ph_ig = (*ph_input_group) (0);
|
|
|
|
in_photon = 1;
|
2003-03-10 11:47:37 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-01-07 15:49:08 +03:00
|
|
|
/* We do not have Photon running. Assume we are in text
|
2003-03-10 11:47:37 +03:00
|
|
|
console or xterm */
|
|
|
|
if (in_photon == -1) {
|
|
|
|
if (devctl
|
|
|
|
(fileno (stdin), DCMD_CHR_LINESTATUS, &mod_status,
|
|
|
|
sizeof (int), NULL) == -1)
|
|
|
|
return 0;
|
|
|
|
shift_ext_status = mod_status & 0xffffff00UL;
|
|
|
|
mod_status &= 0x7f;
|
|
|
|
if (mod_status & _LINESTATUS_CON_ALT)
|
|
|
|
result |= KEY_M_ALT;
|
|
|
|
if (mod_status & _LINESTATUS_CON_CTRL)
|
|
|
|
result |= KEY_M_CTRL;
|
|
|
|
if ((mod_status & _LINESTATUS_CON_SHIFT)
|
|
|
|
|| (shift_ext_status & 0x00000800UL))
|
|
|
|
result |= KEY_M_SHIFT;
|
|
|
|
} else {
|
|
|
|
(*ph_query_cursor) (ph_ig, &cursor_info);
|
|
|
|
if (cursor_info.key_mods & 0x04)
|
|
|
|
result |= KEY_M_ALT;
|
|
|
|
if (cursor_info.key_mods & 0x02)
|
|
|
|
result |= KEY_M_CTRL;
|
|
|
|
if (cursor_info.key_mods & 0x01)
|
|
|
|
result |= KEY_M_SHIFT;
|
|
|
|
}
|
2004-09-26 04:58:47 +04:00
|
|
|
#endif /* __QNXNTO__ */
|
|
|
|
|
2004-09-14 21:18:25 +04:00
|
|
|
#if defined __linux__ || (defined __CYGWIN__ && defined TIOCLINUX)
|
1999-04-21 23:18:31 +04:00
|
|
|
{
|
2002-12-21 10:34:49 +03:00
|
|
|
unsigned char modifiers = 6;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2002-12-21 11:43:15 +03:00
|
|
|
if (ioctl (0, TIOCLINUX, &modifiers) < 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* Translate Linux modifiers into mc modifiers */
|
|
|
|
if (modifiers & SHIFT_PRESSED)
|
|
|
|
result |= KEY_M_SHIFT;
|
2002-12-23 12:46:28 +03:00
|
|
|
if (modifiers & (ALTL_PRESSED | ALTR_PRESSED))
|
2002-12-21 11:43:15 +03:00
|
|
|
result |= KEY_M_ALT;
|
|
|
|
if (modifiers & CONTROL_PRESSED)
|
|
|
|
result |= KEY_M_CTRL;
|
1999-04-21 23:18:31 +04:00
|
|
|
}
|
2003-03-10 17:38:12 +03:00
|
|
|
#endif /* !__linux__ */
|
2005-03-25 12:38:24 +03:00
|
|
|
return result;
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
2001-06-06 02:08:31 +04:00
|
|
|
static void k_dispose (key_def *k)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
|
|
|
if (!k)
|
|
|
|
return;
|
|
|
|
k_dispose (k->child);
|
|
|
|
k_dispose (k->next);
|
2009-02-06 01:27:37 +03:00
|
|
|
g_free (k);
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
2001-06-06 02:08:31 +04:00
|
|
|
static void s_dispose (SelectList *sel)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
|
|
|
if (!sel)
|
|
|
|
return;
|
|
|
|
|
|
|
|
s_dispose (sel->next);
|
2009-02-06 01:27:37 +03:00
|
|
|
g_free (sel);
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void done_key ()
|
|
|
|
{
|
|
|
|
k_dispose (keys);
|
|
|
|
s_dispose (select_list);
|
1999-04-21 23:18:31 +04:00
|
|
|
|
2001-06-05 20:41:44 +04:00
|
|
|
#ifdef HAVE_TEXTMODE_X11_SUPPORT
|
2003-02-23 08:05:49 +03:00
|
|
|
if (x11_display)
|
2005-03-10 12:44:36 +03:00
|
|
|
mc_XCloseDisplay (x11_display);
|
|
|
|
#endif
|
2001-06-06 02:08:31 +04:00
|
|
|
}
|