1
1

Reorganization of key and window management functions.

Этот коммит содержится в:
Andrew Borodin 2009-05-24 13:39:14 +04:00
родитель d91122a172
Коммит 5a5a8bd3c0
24 изменённых файлов: 287 добавлений и 290 удалений

Просмотреть файл

@ -38,7 +38,6 @@
#include "../src/tty/tty.h" #include "../src/tty/tty.h"
#include "../src/tty/key.h" /* XCTRL and ALT macros */ #include "../src/tty/key.h" /* XCTRL and ALT macros */
#include "../src/tty/color.h" #include "../src/tty/color.h"
#include "../src/tty/win.h"
#include "dialog.h" #include "dialog.h"
#include "widget.h" #include "widget.h"

Просмотреть файл

@ -39,7 +39,6 @@
#include "../src/tty/tty.h" #include "../src/tty/tty.h"
#include "../src/tty/color.h" /* Color definitions */ #include "../src/tty/color.h" /* Color definitions */
#include "../src/tty/key.h" /* XCTRL and ALT macros */ #include "../src/tty/key.h" /* XCTRL and ALT macros */
#include "../src/tty/win.h" /* Our window tools */
#include "dialog.h" /* The nice dialog manager */ #include "dialog.h" /* The nice dialog manager */
#include "widget.h" /* The widgets for the nice dialog manager */ #include "widget.h" /* The widgets for the nice dialog manager */

Просмотреть файл

@ -36,7 +36,6 @@
#include "../src/tty/tty.h" #include "../src/tty/tty.h"
#include "../src/tty/color.h" #include "../src/tty/color.h"
#include "../src/tty/win.h"
#include "dialog.h" #include "dialog.h"
#include "widget.h" #include "widget.h"

Просмотреть файл

@ -41,7 +41,6 @@
#include "../src/tty/tty.h" #include "../src/tty/tty.h"
#include "../src/tty/color.h" #include "../src/tty/color.h"
#include "../src/tty/key.h" /* XCTRL and ALT macros */ #include "../src/tty/key.h" /* XCTRL and ALT macros */
#include "../src/tty/win.h"
#include "dialog.h" #include "dialog.h"
#include "widget.h" #include "widget.h"

Просмотреть файл

@ -64,6 +64,7 @@
#define LINUX_CONS_SAVER_C #define LINUX_CONS_SAVER_C
#include "cons.saver.h" #include "cons.saver.h"
#include "../src/tty/win.h"
static void static void
send_contents (char *buffer, unsigned int columns, unsigned int rows) send_contents (char *buffer, unsigned int columns, unsigned int rows)

Просмотреть файл

@ -29,9 +29,6 @@ extern signed char console_flag;
void show_console_contents (int starty, unsigned char begin_line, unsigned char end_line); void show_console_contents (int starty, unsigned char begin_line, unsigned char end_line);
void handle_console (unsigned char action); void handle_console (unsigned char action);
void show_rxvt_contents (int starty, unsigned char y1, unsigned char y2);
int look_for_rxvt_extensions (void);
extern int cons_saver_pid; extern int cons_saver_pid;
#endif /* !LINUX_CONS_SAVER_C */ #endif /* !LINUX_CONS_SAVER_C */

Просмотреть файл

@ -61,7 +61,6 @@
#include "../src/tty/tty.h" #include "../src/tty/tty.h"
#include "../src/tty/color.h" #include "../src/tty/color.h"
#include "../src/tty/key.h" #include "../src/tty/key.h"
#include "../src/tty/win.h"
#include "../src/search/search.h" #include "../src/search/search.h"

Просмотреть файл

@ -37,7 +37,6 @@
#include "../src/tty/tty.h" #include "../src/tty/tty.h"
#include "../src/tty/color.h" #include "../src/tty/color.h"
#include "../src/tty/key.h" #include "../src/tty/key.h"
#include "../src/tty/win.h"
#include "../src/search/search.h" #include "../src/search/search.h"

Просмотреть файл

@ -57,7 +57,6 @@
#include "../src/tty/color.h" #include "../src/tty/color.h"
#include "../src/tty/mouse.h" #include "../src/tty/mouse.h"
#include "../src/tty/key.h" /* For mi_getch() */ #include "../src/tty/key.h" /* For mi_getch() */
#include "../src/tty/win.h"
#include "help.h" #include "help.h"
#include "dialog.h" /* For Dlg_head */ #include "dialog.h" /* For Dlg_head */

Просмотреть файл

@ -39,7 +39,6 @@
#include "../src/tty/tty.h" #include "../src/tty/tty.h"
#include "../src/tty/color.h" #include "../src/tty/color.h"
#include "../src/tty/key.h" #include "../src/tty/key.h"
#include "../src/tty/win.h"
#include "dialog.h" #include "dialog.h"
#include "widget.h" #include "widget.h"

Просмотреть файл

@ -37,7 +37,7 @@
#include "global.h" #include "global.h"
#include "tty.h" #include "tty.h"
#include "win.h" #include "key.h"
#include "color.h" #include "color.h"
#include "dialog.h" #include "dialog.h"
#include "widget.h" #include "widget.h"

Просмотреть файл

@ -46,7 +46,7 @@
#include "../src/tty/color.h" #include "../src/tty/color.h"
#include "../src/tty/mouse.h" #include "../src/tty/mouse.h"
#include "../src/tty/key.h" /* For init_key() and mi_getch() */ #include "../src/tty/key.h" /* For init_key() and mi_getch() */
#include "../src/tty/win.h" #include "../src/tty/win.h" /* xterm_flag */
#include "dir.h" #include "dir.h"
#include "dialog.h" #include "dialog.h"

Просмотреть файл

@ -33,7 +33,6 @@
#include "../src/tty/color.h" #include "../src/tty/color.h"
#include "../src/tty/mouse.h" #include "../src/tty/mouse.h"
#include "../src/tty/key.h" /* For mi_getch() */ #include "../src/tty/key.h" /* For mi_getch() */
#include "../src/tty/win.h"
#include "menu.h" #include "menu.h"
#include "help.h" #include "help.h"

Просмотреть файл

@ -34,7 +34,6 @@
#include "../src/tty/tty.h" #include "../src/tty/tty.h"
#include "../src/tty/color.h" #include "../src/tty/color.h"
#include "../src/tty/win.h"
#include "dialog.h" #include "dialog.h"
#include "widget.h" #include "widget.h"

Просмотреть файл

@ -37,7 +37,6 @@
#include "../src/tty/tty.h" /* tty_setcolor() */ #include "../src/tty/tty.h" /* tty_setcolor() */
#include "../src/tty/color.h" #include "../src/tty/color.h"
#include "../src/tty/win.h"
#include "dialog.h" #include "dialog.h"
#include "widget.h" #include "widget.h"

Просмотреть файл

@ -37,7 +37,6 @@
#include "../src/tty/color.h" #include "../src/tty/color.h"
#include "../src/tty/mouse.h" /* For Gpm_Event */ #include "../src/tty/mouse.h" /* For Gpm_Event */
#include "../src/tty/key.h" /* XCTRL and ALT macros */ #include "../src/tty/key.h" /* XCTRL and ALT macros */
#include "../src/tty/win.h"
#include "dir.h" #include "dir.h"
#include "panel.h" #include "panel.h"

Просмотреть файл

@ -31,9 +31,8 @@
#include "global.h" #include "global.h"
#include "../src/tty/tty.h" #include "../src/tty/tty.h"
#include "../src/tty/key.h" /* For the externs */ #include "../src/tty/key.h"
#include "../src/tty/mouse.h" /* To make view.h happy */ #include "../src/tty/mouse.h" /* To make view.h happy */
#include "../src/tty/win.h" /* lookup_key */
#include "dir.h" #include "dir.h"
#include "panel.h" #include "panel.h"

Просмотреть файл

@ -42,11 +42,12 @@
#include "../../src/tty/tty.h" #include "../../src/tty/tty.h"
#include "../../src/tty/mouse.h" #include "../../src/tty/mouse.h"
#include "../../src/tty/key.h" #include "../../src/tty/key.h"
#include "../../src/tty/win.h" #include "../../src/tty/win.h" /* xterm_flag */
#include "../../src/main.h" #include "../../src/main.h"
#include "../../src/layout.h" /* winch_flag */ #include "../../src/layout.h" /* winch_flag */
#include "../../src/cons.saver.h" #include "../../src/cons.saver.h"
#include "../../src/strutil.h" /* str_casecmp */
#ifdef USE_VFS #ifdef USE_VFS
#include "../../vfs/gc.h" #include "../../vfs/gc.h"
@ -59,7 +60,7 @@
#ifdef __linux__ #ifdef __linux__
# if defined(__GLIBC__) && (__GLIBC__ < 2) # if defined(__GLIBC__) && (__GLIBC__ < 2)
# include <linux/termios.h> /* TIOCLINUX */ # include <linux/termios.h> /* TIOCLINUX */
# else # elif defined HAVE_TERMIOS_H
# include <termios.h> # include <termios.h>
# endif # endif
# include <sys/ioctl.h> # include <sys/ioctl.h>
@ -224,6 +225,84 @@ is_abort_char (int c)
c == KEY_F(10)); c == KEY_F(10));
} }
/*
* Common handler for standard movement keys in a text area. Provided
* functions are called with the "data" argument. backfn and forfn also
* get an argument indicating how many lines to scroll. Return MSG_HANDLED
* if the key was handled, MSG_NOT_HANDLED otherwise.
*/
cb_ret_t
check_movement_keys (int key, int page_size, void *data, move_fn backfn,
move_fn forfn, move_fn topfn, move_fn bottomfn)
{
switch (key) {
case KEY_UP:
case XCTRL ('p'):
(*backfn) (data, 1);
break;
case KEY_DOWN:
case XCTRL ('n'):
(*forfn) (data, 1);
break;
case KEY_PPAGE:
case ALT ('v'):
(*backfn) (data, page_size - 1);
break;
case KEY_NPAGE:
case XCTRL ('v'):
(*forfn) (data, page_size - 1);
break;
case KEY_HOME:
case KEY_M_CTRL | KEY_HOME:
case KEY_M_CTRL | KEY_PPAGE:
case KEY_A1:
case ALT ('<'):
(*topfn) (data, 0);
break;
case KEY_END:
case KEY_M_CTRL | KEY_END:
case KEY_M_CTRL | KEY_NPAGE:
case KEY_C1:
case ALT ('>'):
(*bottomfn) (data, 0);
break;
case 'b':
case KEY_BACKSPACE:
(*backfn) (data, page_size - 1);
break;
case ' ':
(*forfn) (data, page_size - 1);
break;
case 'u':
(*backfn) (data, page_size / 2);
break;
case 'd':
(*forfn) (data, page_size / 2);
break;
case 'g':
(*topfn) (data, 0);
break;
case 'G':
(*bottomfn) (data, 0);
break;
default:
return MSG_NOT_HANDLED;
}
return MSG_HANDLED;
}
typedef const struct { typedef const struct {
int code; int code;
const char *seq; const char *seq;
@ -467,6 +546,142 @@ static key_define_t mc_default_keys [] = {
{ 0, NULL, MCKEY_NOACTION }, { 0, NULL, MCKEY_NOACTION },
}; };
/* This table is a mapping between names and the constants we use
* We use this to allow users to define alternate definitions for
* certain keys that may be missing from the terminal database
*/
key_code_name_t key_name_conv_tab [] = {
/* KEY_F(0) is not here, since we are mapping it to f10, so there is no reason
to define f0 as well. Also, it makes Learn keys a bunch of problems :( */
{ KEY_F(1), "f1", N_("Function key 1") },
{ KEY_F(2), "f2", N_("Function key 2") },
{ KEY_F(3), "f3", N_("Function key 3") },
{ KEY_F(4), "f4", N_("Function key 4") },
{ KEY_F(5), "f5", N_("Function key 5") },
{ KEY_F(6), "f6", N_("Function key 6") },
{ KEY_F(7), "f7", N_("Function key 7") },
{ KEY_F(8), "f8", N_("Function key 8") },
{ KEY_F(9), "f9", N_("Function key 9") },
{ KEY_F(10), "f10", N_("Function key 10") },
{ KEY_F(11), "f11", N_("Function key 11") },
{ KEY_F(12), "f12", N_("Function key 12") },
{ KEY_F(13), "f13", N_("Function key 13") },
{ KEY_F(14), "f14", N_("Function key 14") },
{ KEY_F(15), "f15", N_("Function key 15") },
{ KEY_F(16), "f16", N_("Function key 16") },
{ KEY_F(17), "f17", N_("Function key 17") },
{ KEY_F(18), "f18", N_("Function key 18") },
{ KEY_F(19), "f19", N_("Function key 19") },
{ KEY_F(20), "f20", N_("Function key 20") },
{ KEY_BACKSPACE, "bs", N_("Backspace key") },
{ KEY_END, "end", N_("End key") },
{ KEY_UP, "up", N_("Up arrow key") },
{ KEY_DOWN, "down", N_("Down arrow key") },
{ KEY_LEFT, "left", N_("Left arrow key") },
{ KEY_RIGHT, "right", N_("Right arrow key") },
{ KEY_HOME, "home", N_("Home key") },
{ KEY_NPAGE, "pgdn", N_("Page Down key") },
{ KEY_PPAGE, "pgup", N_("Page Up key") },
{ KEY_IC, "ins", N_("Insert key") },
{ KEY_DC, "delete", N_("Delete key") },
{ ALT('\t'), "complete", N_("Completion/M-tab") },
{ KEY_KP_ADD, "kpplus", N_("+ on keypad") },
{ KEY_KP_SUBTRACT,"kpminus", N_("- on keypad") },
{ KEY_KP_MULTIPLY,"kpasterix", N_("* on keypad") },
/* From here on, these won't be shown in Learn keys (no space) */
{ KEY_LEFT, "kpleft", N_("Left arrow keypad") },
{ KEY_RIGHT, "kpright", N_("Right arrow keypad") },
{ KEY_UP, "kpup", N_("Up arrow keypad") },
{ KEY_DOWN, "kpdown", N_("Down arrow keypad") },
{ KEY_HOME, "kphome", N_("Home on keypad") },
{ KEY_END, "kpend", N_("End on keypad") },
{ KEY_NPAGE, "kpnpage", N_("Page Down keypad") },
{ KEY_PPAGE, "kpppage", N_("Page Up keypad") },
{ KEY_IC, "kpinsert", N_("Insert on keypad") },
{ KEY_DC, "kpdelete", N_("Delete on keypad") },
{ (int) '\n', "kpenter", N_("Enter on keypad") },
{ (int) '\n', "enter", N_("Enter on keypad") },
{ (int) '\t', "tab", N_("Tab on keypad") },
{ (int) ' ', "space", N_("Space on keypad") },
{ (int) '/', "kpslash", N_("Slash on keypad") },
{ (int) '#', "kpnumlock", N_("NumLock on keypad") },
/* Alternative label */
{ KEY_BACKSPACE, "backspace", N_("Backspace key") },
{ KEY_IC, "insert", N_("Insert key") },
{ KEY_KP_ADD, "plus", N_("+ on keypad") },
{ KEY_KP_SUBTRACT,"minus", N_("- on keypad") },
{ KEY_KP_MULTIPLY,"asterix", N_("* on keypad") },
/* meta keys */
{ KEY_M_CTRL, "control", N_("Ctrl") },
{ KEY_M_CTRL, "ctrl", N_("Ctrl") },
{ KEY_M_ALT, "alt", N_("Alt") },
{ KEY_M_ALT, "ralt", N_("Alt") },
{ KEY_M_ALT, "meta", N_("Alt") },
{ KEY_M_SHIFT, "shift", N_("Shift") },
{ 0, 0, 0 }
};
int
lookup_keyname (char *keyname)
{
int i;
if (keyname[0] == '\0')
return 0;
if (keyname[1] == '\0')
return (int) keyname[0];
for (i = 0; key_name_conv_tab [i].code; i++)
if (str_casecmp (key_name_conv_tab [i].name, keyname) == 0)
return key_name_conv_tab [i].code;
return 0;
}
/* Return the code associated with the symbolic name keyname */
int
lookup_key (char *keyname)
{
int k = -1;
char **keys;
guint keys_count = -1;
int key = 0;
int i = 0;
if (keyname == NULL)
return 0;
keys = g_strsplit (keyname, " ", -1);
keys_count = g_strv_length (keys);
for (i = keys_count - 1; i >= 0; i--) {
if (keys[i] !=NULL && keys[i][0] != 0) {
key = lookup_keyname (keys[i]);
if (key & KEY_M_CTRL) {
if (k < 256)
k = XCTRL(k);
else
k |= key;
} else {
if (k == -1)
k = key;
else
k |= key;
}
}
}
if (k == -1)
return 0;
return k;
}
static void static void
define_sequences (key_define_t *kd) define_sequences (key_define_t *kd)
{ {
@ -1006,6 +1221,18 @@ int get_key_code (int no_delay)
return correct_key_code (c); return correct_key_code (c);
} }
/* Return the code associated with the symbolic name keyname */
int lookup_key (char *keyname)
{
int i;
for (i = 0; key_name_conv_tab [i].code; i++){
if (str_casecmp (key_name_conv_tab [i].name, keyname))
continue;
return key_name_conv_tab [i].code;
}
return 0;
}
/* If set timeout is set, then we wait 0.1 seconds, else, we block */ /* If set timeout is set, then we wait 0.1 seconds, else, we block */
static void static void
try_channels (int set_timeout) try_channels (int set_timeout)

Просмотреть файл

@ -7,16 +7,34 @@
#define MC_KEY_H #define MC_KEY_H
#include "../../src/global.h" /* <glib.h> */ #include "../../src/global.h" /* <glib.h> */
#include "../../src/dialog.h" /* cb_ret_t */
void init_key (void); void init_key (void);
void init_key_input_fd (void); void init_key_input_fd (void);
void done_key (void); void done_key (void);
/* Keys management */
typedef void (*move_fn) (void *data, int param);
cb_ret_t check_movement_keys (int key, int page_size, void *data,
move_fn backfn, move_fn forfn,
move_fn topfn, move_fn bottomfn);
int lookup_keyname (char *keyname);
int lookup_key (char *keyname);
typedef const struct {
int code;
const char *name;
const char *longname;
} key_code_name_t;
extern key_code_name_t key_name_conv_tab [];
/* mouse support */
struct Gpm_Event; struct Gpm_Event;
int get_event (struct Gpm_Event *event, int redo_event, int block); int get_event (struct Gpm_Event *event, int redo_event, int block);
int is_idle (void); int is_idle (void);
int mi_getch (void); int mi_getch (void);
/* Possible return values from get_event: */ /* Possible return values from get_event: */
#define EV_MOUSE -2 #define EV_MOUSE -2
#define EV_NONE -1 #define EV_NONE -1
@ -37,7 +55,6 @@ extern int irix_fn_keys;
extern int use_8th_bit_as_meta; extern int use_8th_bit_as_meta;
/* While waiting for input, the program can select on more than one file */ /* While waiting for input, the program can select on more than one file */
typedef int (*select_fn)(int fd, void *info); typedef int (*select_fn)(int fd, void *info);
/* Channel manipulation */ /* Channel manipulation */
@ -72,16 +89,8 @@ char *learn_key (void);
/* Returns a key code (interpreted) */ /* Returns a key code (interpreted) */
int get_key_code (int nodelay); int get_key_code (int nodelay);
typedef const struct {
int code;
const char *name;
const char *longname;
} key_code_name_t;
extern key_code_name_t key_name_conv_tab [];
/* Set keypad mode (xterm and linux console only) */ /* Set keypad mode (xterm and linux console only) */
void numeric_keypad_mode (void); void numeric_keypad_mode (void);
void application_keypad_mode (void); void application_keypad_mode (void);
#endif #endif /* MC_KEY_H */

Просмотреть файл

@ -30,46 +30,50 @@
#include "../../src/global.h" #include "../../src/global.h"
#include "../../src/tty/tty.h" /* tty_gotoyx, addch */ #include "../../src/tty/tty.h" /* tty_gotoyx, addch */
#include "../../src/cons.saver.h" #include "../../src/cons.saver.h" /* console_flag */
static int rxvt_extensions = 0; static gboolean rxvt_extensions = FALSE;
int look_for_rxvt_extensions (void) gboolean
look_for_rxvt_extensions (void)
{ {
static int been_called = 0; static gboolean been_called = FALSE;
const char *e;
if (!been_called) { if (!been_called) {
rxvt_extensions = 0; const char *e = getenv ("RXVT_EXT");
e = getenv ("RXVT_EXT"); rxvt_extensions = ((e != NULL) && (strcmp (e, "1.0") == 0));
if (e) been_called = TRUE;
if (!strcmp (e, "1.0"))
rxvt_extensions = 1;
been_called = 1;
} }
if (rxvt_extensions) if (rxvt_extensions)
console_flag = 4; console_flag = 4;
return rxvt_extensions; return rxvt_extensions;
} }
/* my own wierd protocol base 16 - paul */ /* my own wierd protocol base 16 - paul */
static int rxvt_getc (void) static int
rxvt_getc (void)
{ {
int r; int r;
unsigned char c; unsigned char c;
while (read (0, &c, 1) != 1); while (read (0, &c, 1) != 1)
;
if (c == '\n') if (c == '\n')
return -1; return -1;
r = (c - 'A') * 16; r = (c - 'A') * 16;
while (read (0, &c, 1) != 1); while (read (0, &c, 1) != 1)
;
r += (c - 'A'); r += (c - 'A');
return r; return r;
} }
extern int keybar_visible; extern int keybar_visible;
static int anything_ready (void) static int
anything_ready (void)
{ {
fd_set fds; fd_set fds;
struct timeval tv; struct timeval tv;
@ -81,10 +85,12 @@ static int anything_ready (void)
return select (1, &fds, 0, 0, &tv); return select (1, &fds, 0, 0, &tv);
} }
void show_rxvt_contents (int starty, unsigned char y1, unsigned char y2) void
show_rxvt_contents (int starty, unsigned char y1, unsigned char y2)
{ {
unsigned char *k; unsigned char *k;
int bytes, i, j, cols = 0; int bytes, i, j, cols = 0;
y1 += (keybar_visible != 0); /* i don't knwo why we need this - paul */ y1 += (keybar_visible != 0); /* i don't knwo why we need this - paul */
y2 += (keybar_visible != 0); y2 += (keybar_visible != 0);
while (anything_ready ()) while (anything_ready ())

Просмотреть файл

@ -1,12 +1,12 @@
/* Curses utilities /* Curses utilities
Copyright (C) 1995, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, Copyright (C) 1995, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
2007 Free Software Foundation, Inc. 2007 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify 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 it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or the Free Software Foundation; either version 2 of the License, or
(at your option) any later version. (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
@ -25,108 +25,16 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#ifdef HAVE_TERMIOS_H
#include <termios.h>
#endif
#include "../../src/global.h"
#include "../../src/tty/tty.h"
#include "../../src/tty/color.h"
#include "../../src/tty/mouse.h"
#include "../../src/tty/key.h" /* XCTRL and ALT macros */
#include "../../src/tty/win.h" #include "../../src/tty/win.h"
#include "../../src/dialog.h"
#include "../../src/widget.h"
#include "../../src/layout.h"
#include "../../src/strutil.h"
/*
* Common handler for standard movement keys in a text area. Provided
* functions are called with the "data" argument. backfn and forfn also
* get an argument indicating how many lines to scroll. Return MSG_HANDLED
* if the key was handled, MSG_NOT_HANDLED otherwise.
*/
cb_ret_t
check_movement_keys (int key, int page_size, void *data, movefn backfn,
movefn forfn, movefn topfn, movefn bottomfn)
{
switch (key) {
case KEY_UP:
case XCTRL ('p'):
(*backfn) (data, 1);
break;
case KEY_DOWN:
case XCTRL ('n'):
(*forfn) (data, 1);
break;
case KEY_PPAGE:
case ALT ('v'):
(*backfn) (data, page_size - 1);
break;
case KEY_NPAGE:
case XCTRL ('v'):
(*forfn) (data, page_size - 1);
break;
case KEY_HOME:
case KEY_M_CTRL | KEY_HOME:
case KEY_M_CTRL | KEY_PPAGE:
case KEY_A1:
case ALT ('<'):
(*topfn) (data, 0);
break;
case KEY_END:
case KEY_M_CTRL | KEY_END:
case KEY_M_CTRL | KEY_NPAGE:
case KEY_C1:
case ALT ('>'):
(*bottomfn) (data, 0);
break;
case 'b':
case KEY_BACKSPACE:
(*backfn) (data, page_size - 1);
break;
case ' ':
(*forfn) (data, page_size - 1);
break;
case 'u':
(*backfn) (data, page_size / 2);
break;
case 'd':
(*forfn) (data, page_size / 2);
break;
case 'g':
(*topfn) (data, 0);
break;
case 'G':
(*bottomfn) (data, 0);
break;
default:
return MSG_NOT_HANDLED;
}
return MSG_HANDLED;
}
/* This flag is set by xterm detection routine in function main() */ /* This flag is set by xterm detection routine in function main() */
/* It is used by function view_other_cmd() */ /* It is used by function view_other_cmd() */
int xterm_flag = 0; int xterm_flag = 0;
/* The following routines only work on xterm terminals */ /* The following routines only work on xterm terminals */
void do_enter_ca_mode (void) void
do_enter_ca_mode (void)
{ {
if (!xterm_flag) if (!xterm_flag)
return; return;
@ -134,143 +42,11 @@ void do_enter_ca_mode (void)
fflush (stdout); fflush (stdout);
} }
void do_exit_ca_mode (void) void
do_exit_ca_mode (void)
{ {
if (!xterm_flag) if (!xterm_flag)
return; return;
fprintf (stdout, ESC_STR "[?47l" ESC_STR "8" ESC_STR "[m"); fprintf (stdout, ESC_STR "[?47l" ESC_STR "8" ESC_STR "[m");
fflush (stdout); fflush (stdout);
} }
/* This table is a mapping between names and the constants we use
* We use this to allow users to define alternate definitions for
* certain keys that may be missing from the terminal database
*/
key_code_name_t key_name_conv_tab [] = {
/* KEY_F(0) is not here, since we are mapping it to f10, so there is no reason
to define f0 as well. Also, it makes Learn keys a bunch of problems :( */
{ KEY_F(1), "f1", N_("Function key 1") },
{ KEY_F(2), "f2", N_("Function key 2") },
{ KEY_F(3), "f3", N_("Function key 3") },
{ KEY_F(4), "f4", N_("Function key 4") },
{ KEY_F(5), "f5", N_("Function key 5") },
{ KEY_F(6), "f6", N_("Function key 6") },
{ KEY_F(7), "f7", N_("Function key 7") },
{ KEY_F(8), "f8", N_("Function key 8") },
{ KEY_F(9), "f9", N_("Function key 9") },
{ KEY_F(10), "f10", N_("Function key 10") },
{ KEY_F(11), "f11", N_("Function key 11") },
{ KEY_F(12), "f12", N_("Function key 12") },
{ KEY_F(13), "f13", N_("Function key 13") },
{ KEY_F(14), "f14", N_("Function key 14") },
{ KEY_F(15), "f15", N_("Function key 15") },
{ KEY_F(16), "f16", N_("Function key 16") },
{ KEY_F(17), "f17", N_("Function key 17") },
{ KEY_F(18), "f18", N_("Function key 18") },
{ KEY_F(19), "f19", N_("Function key 19") },
{ KEY_F(20), "f20", N_("Function key 20") },
{ KEY_BACKSPACE, "bs", N_("Backspace key") },
{ KEY_END, "end", N_("End key") },
{ KEY_UP, "up", N_("Up arrow key") },
{ KEY_DOWN, "down", N_("Down arrow key") },
{ KEY_LEFT, "left", N_("Left arrow key") },
{ KEY_RIGHT, "right", N_("Right arrow key") },
{ KEY_HOME, "home", N_("Home key") },
{ KEY_NPAGE, "pgdn", N_("Page Down key") },
{ KEY_PPAGE, "pgup", N_("Page Up key") },
{ KEY_IC, "ins", N_("Insert key") },
{ KEY_DC, "delete", N_("Delete key") },
{ ALT('\t'), "complete", N_("Completion/M-tab") },
{ KEY_KP_ADD, "kpplus", N_("+ on keypad") },
{ KEY_KP_SUBTRACT,"kpminus", N_("- on keypad") },
{ KEY_KP_MULTIPLY,"kpasterix", N_("* on keypad") },
/* From here on, these won't be shown in Learn keys (no space) */
{ KEY_LEFT, "kpleft", N_("Left arrow keypad") },
{ KEY_RIGHT, "kpright", N_("Right arrow keypad") },
{ KEY_UP, "kpup", N_("Up arrow keypad") },
{ KEY_DOWN, "kpdown", N_("Down arrow keypad") },
{ KEY_HOME, "kphome", N_("Home on keypad") },
{ KEY_END, "kpend", N_("End on keypad") },
{ KEY_NPAGE, "kpnpage", N_("Page Down keypad") },
{ KEY_PPAGE, "kpppage", N_("Page Up keypad") },
{ KEY_IC, "kpinsert", N_("Insert on keypad") },
{ KEY_DC, "kpdelete", N_("Delete on keypad") },
{ (int) '\n', "kpenter", N_("Enter on keypad") },
{ (int) '\n', "enter", N_("Enter on keypad") },
{ (int) '\t', "tab", N_("Tab on keypad") },
{ (int) ' ', "space", N_("Space on keypad") },
{ (int) '/', "kpslash", N_("Slash on keypad") },
{ (int) '#', "kpnumlock", N_("NumLock on keypad") },
/* Alternative label */
{ KEY_BACKSPACE, "backspace", N_("Backspace key") },
{ KEY_IC, "insert", N_("Insert key") },
{ KEY_KP_ADD, "plus", N_("+ on keypad") },
{ KEY_KP_SUBTRACT,"minus", N_("- on keypad") },
{ KEY_KP_MULTIPLY,"asterix", N_("* on keypad") },
/* meta keys */
{ KEY_M_CTRL, "control", N_("Ctrl") },
{ KEY_M_CTRL, "ctrl", N_("Ctrl") },
{ KEY_M_ALT, "alt", N_("Alt") },
{ KEY_M_ALT, "ralt", N_("Alt") },
{ KEY_M_ALT, "meta", N_("Alt") },
{ KEY_M_SHIFT, "shift", N_("Shift") },
{ 0, 0, 0 }
};
int lookup_keyname (char *keyname)
{
int i;
if (keyname[0] == '\0')
return 0;
if (keyname[1] == '\0')
return (int) keyname[0];
for (i = 0; key_name_conv_tab [i].code; i++)
if (str_casecmp (key_name_conv_tab [i].name, keyname) == 0)
return key_name_conv_tab [i].code;
return 0;
}
/* Return the code associated with the symbolic name keyname */
int lookup_key (char *keyname)
{
int k = -1;
char **keys;
guint keys_count = -1;
int key = 0;
int i = 0;
if (keyname == NULL)
return 0;
keys = g_strsplit (keyname, " ", -1);
keys_count = g_strv_length (keys);
for (i = keys_count - 1; i >= 0; i--) {
if (keys[i] !=NULL && keys[i][0] != 0) {
key = lookup_keyname (keys[i]);
if (key & KEY_M_CTRL) {
if (k < 256)
k = XCTRL(k);
else
k |= key;
} else {
if (k == -1)
k = key;
else
k |= key;
}
}
}
if (k == -1)
return 0;
return k;
}

Просмотреть файл

@ -6,18 +6,14 @@
#ifndef MC_WIN_H #ifndef MC_WIN_H
#define MC_WIN_H #define MC_WIN_H
#include "../../src/dialog.h" /* cb_ret_t */ #include "../../src/global.h" /* <glib.h> */
/* Keys management */
typedef void (*movefn) (void *, int);
cb_ret_t check_movement_keys (int key, int page_size, void *data,
movefn backfn, movefn forfn,
movefn topfn, movefn bottomfn);
int lookup_key (char *keyname);
/* Terminal management */ /* Terminal management */
extern int xterm_flag; extern int xterm_flag;
void do_enter_ca_mode (void); void do_enter_ca_mode (void);
void do_exit_ca_mode (void); void do_exit_ca_mode (void);
void show_rxvt_contents (int starty, unsigned char y1, unsigned char y2);
gboolean look_for_rxvt_extensions (void);
#endif /* MC_WIN_H */ #endif /* MC_WIN_H */

Просмотреть файл

@ -53,7 +53,6 @@
#include "../src/tty/color.h" #include "../src/tty/color.h"
#include "../src/tty/key.h" /* For mi_getch() */ #include "../src/tty/key.h" /* For mi_getch() */
#include "../src/tty/mouse.h" #include "../src/tty/mouse.h"
#include "../src/tty/win.h"
#include "cmd.h" /* For view_other_cmd */ #include "cmd.h" /* For view_other_cmd */
#include "dialog.h" /* Needed by widget.h */ #include "dialog.h" /* Needed by widget.h */

Просмотреть файл

@ -46,7 +46,6 @@
#include "../src/tty/color.h" #include "../src/tty/color.h"
#include "../src/tty/mouse.h" #include "../src/tty/mouse.h"
#include "../src/tty/key.h" /* XCTRL and ALT macros */ #include "../src/tty/key.h" /* XCTRL and ALT macros */
#include "../src/tty/win.h"
#include "dialog.h" #include "dialog.h"
#include "widget.h" #include "widget.h"