* key.c (get_modifier): Make static. Return the mc internal

representation, not the Linux console code.
(correct_key_code): Add the modifier, not strip it.
(ctrl_pressed): Remove.  Adjust all dependencies.
This commit is contained in:
Pavel Roskin 2002-12-21 08:43:15 +00:00
parent e1805e4350
commit 0d0009e263
7 changed files with 77 additions and 81 deletions

View File

@ -1,5 +1,10 @@
2002-12-21 Pavel Roskin <proski@gnu.org>
* key.c (get_modifier): Make static. Return the mc internal
representation, not the Linux console code.
(correct_key_code): Add the modifier, not strip it.
(ctrl_pressed): Remove. Adjust all dependencies.
* key.h: Add definitions for the keyboard modifiers that can be
part of the key code.
* key.c (xterm_key_defines): Add some common key definitions

View File

@ -48,7 +48,7 @@
#include "panel.h" /* cpanel */
#include "main.h" /* repaint_screen */
#include "hotlist.h"
#include "key.h" /* ctrl_pressed */
#include "key.h" /* KEY_M_CTRL */
#include "command.h" /* cmdline */
#define UX 5
@ -385,9 +385,9 @@ static int hotlist_callback (Dlg_head * h, int Par, int Msg)
case DLG_UNHANDLED_KEY:
switch (Par) {
case '\n':
if (ctrl_pressed())
case KEY_M_CTRL | '\n':
goto l1;
case '\n':
case KEY_ENTER:
case KEY_RIGHT:
if (hotlist_button_callback (B_ENTER, 0)) {

View File

@ -60,6 +60,13 @@
/* timeout for old_esc_mode in usec */
#define ESCMODE_TIMEOUT 1000000
/* Linux console keyboard modifiers */
#define SHIFT_PRESSED 1
#define ALTR_PRESSED 2
#define CONTROL_PRESSED 4
#define ALTL_PRESSED 8
int mou_auto_repeat = 100;
int double_click_speed = 250;
int old_esc_mode = 0;
@ -82,6 +89,7 @@ static key_def *keys = 0;
static int input_fd;
static int disabled_channels = 0; /* Disable channels checking */
static int xgetch_second (void);
static int get_modifier (void);
/* File descriptor monitoring add/remove routines */
typedef struct SelectList {
@ -450,14 +458,12 @@ int define_sequence (int code, char *seq, int action)
}
static int *pending_keys;
static int last_modifiers;
static int
correct_key_code (int c)
{
/* Remember key modifiers and strip them from the code */
last_modifiers = c & KEY_M_MASK;
c &= ~KEY_M_MASK;
/* Add key modifiers that cannot be deduced from the sequences */
c |= get_modifier ();
/* This is needed on some OS that do not support ncurses and */
/* do some magic after read()ing the data */
@ -979,20 +985,18 @@ int is_idle (void)
}
/* Get modifier state (shift, alt, ctrl) for the last key pressed */
int
/*
* 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
get_modifier (void)
{
int result = 0;
/* Data about modifiers determined from the escape sequences */
if (last_modifiers & KEY_M_SHIFT)
result |= SHIFT_PRESSED;
if (last_modifiers & KEY_M_ALT)
result |= ALTL_PRESSED;
if (last_modifiers & KEY_M_CTRL)
result |= CONTROL_PRESSED;
#ifdef HAVE_TEXTMODE_X11_SUPPORT
if (x11_display) {
Window root, child;
@ -1006,18 +1010,28 @@ get_modifier (void)
&root_y, &win_x, &win_y, &mask);
if (mask & ShiftMask)
result |= SHIFT_PRESSED;
result |= KEY_M_SHIFT;
if (mask & ControlMask)
result |= CONTROL_PRESSED;
result |= KEY_M_CTRL;
return result;
} else
}
#endif
#ifdef __linux__
{
unsigned char modifiers = 6;
if (ioctl (0, TIOCLINUX, &modifiers) >= 0)
result |= modifiers;
if (ioctl (0, TIOCLINUX, &modifiers) < 0)
return 0;
/* Translate Linux modifiers into mc modifiers */
if (modifiers & SHIFT_PRESSED)
result |= KEY_M_SHIFT;
if (modifiers & ALTL_PRESSED)
result |= KEY_M_ALT;
if (modifiers & ALTR_PRESSED)
result |= KEY_M_ALT;
if (modifiers & CONTROL_PRESSED)
result |= KEY_M_CTRL;
return result;
}
@ -1026,15 +1040,6 @@ get_modifier (void)
#endif
}
int
ctrl_pressed (void)
{
if (get_modifier () & CONTROL_PRESSED)
return 1;
else
return 0;
}
static void k_dispose (key_def *k)
{
if (!k)

View File

@ -9,33 +9,16 @@ void done_key (void);
int get_event (Gpm_Event *event, int redo_event, int block);
int is_idle (void);
int ctrl_pressed (void);
int mi_getch (void);
/* Possible return values from get_event: */
#define EV_MOUSE -2
#define EV_NONE -1
/* Used to get the modifier information */
/* Currently, it just works on the Linux console */
#ifdef NATIVE_WIN32
# ifndef SHIFT_PRESSED
# define SHIFT_PRESSED 0x0010
# endif
#else
# define SHIFT_PRESSED 1
#endif
#define ALTR_PRESSED 2
#define CONTROL_PRESSED 4
#define ALTL_PRESSED 8
int get_modifier (void);
/*
* Internal representation of the key modifiers. It is used in the
* sequence tables. In the future, it will be part of the key code.
* Currently those bits are stripped in correct_key_code() and
* remembered in the last_modifiers variable.
* sequence tables and the keycodes in the mc sources.
*/
#define KEY_M_SHIFT 0x1000
#define KEY_M_ALT 0x2000

View File

@ -1741,8 +1741,8 @@ midnight_callback (struct Dlg_head *h, int id, int msg)
if (id == '\t')
free_completions (cmdline);
/* On Linux, we can tell the difference */
if (id == '\n' && ctrl_pressed ()) {
/* Ctrl-Enter */
if (id == ('\n' | KEY_M_CTRL)) {
copy_prog_name ();
return MSG_HANDLED;
}

View File

@ -1661,13 +1661,9 @@ prev_page (WPanel *panel)
}
static void
prev_page_key (WPanel *panel)
ctrl_prev_page (WPanel *panel)
{
if (ctrl_pressed ()){
do_cd ("..", cd_exact);
} else {
prev_page (panel);
}
}
static void
@ -1698,14 +1694,12 @@ next_page (WPanel *panel)
paint_dir (panel);
}
static void next_page_key (WPanel *panel)
static void
ctrl_next_page (WPanel *panel)
{
if (ctrl_pressed() &&
(S_ISDIR(selection (panel)->buf.st_mode) ||
link_isdir (selection (panel)))) {
if ((S_ISDIR (selection (panel)->buf.st_mode)
|| link_isdir (selection (panel)))) {
do_cd (selection (panel)->fname, cd_exact);
} else {
next_page (panel);
}
}
@ -2058,8 +2052,10 @@ static const key_map panel_keymap [] = {
{ KEY_C1, move_end },
{ KEY_END, move_end },
{ KEY_A1, move_home },
{ KEY_NPAGE, next_page_key },
{ KEY_PPAGE, prev_page_key },
{ KEY_NPAGE, next_page },
{ KEY_PPAGE, prev_page },
{ KEY_NPAGE | KEY_M_CTRL, ctrl_next_page },
{ KEY_PPAGE | KEY_M_CTRL, ctrl_prev_page },
/* To quickly move in the panel */
{ ALT('g'), goto_top_file },

View File

@ -1190,21 +1190,26 @@ backward_word (WInput *in)
static void
key_left (WInput *in)
{
if (ctrl_pressed ())
backward_word (in);
else
backward_char (in);
}
static void
key_ctrl_left (WInput *in)
{
backward_word (in);
}
static void
key_right (WInput *in)
{
if (ctrl_pressed ())
forward_word (in);
else
forward_char (in);
}
static void
key_ctrl_right (WInput *in)
{
forward_word (in);
}
static void
backward_delete (WInput *in)
{
@ -1396,9 +1401,11 @@ static const struct {
{ KEY_END, end_of_line },
{ KEY_C1, end_of_line },
{ KEY_LEFT, key_left },
{ KEY_LEFT | KEY_M_CTRL, key_ctrl_left },
{ XCTRL('b'), backward_char },
{ ALT('b'), backward_word },
{ KEY_RIGHT, key_right },
{ KEY_RIGHT | KEY_M_CTRL, key_ctrl_right },
{ XCTRL('f'), forward_char },
{ ALT('f'), forward_word },