* 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.
Этот коммит содержится в:
родитель
e1805e4350
Коммит
0d0009e263
@ -1,5 +1,10 @@
|
|||||||
2002-12-21 Pavel Roskin <proski@gnu.org>
|
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
|
* key.h: Add definitions for the keyboard modifiers that can be
|
||||||
part of the key code.
|
part of the key code.
|
||||||
* key.c (xterm_key_defines): Add some common key definitions
|
* key.c (xterm_key_defines): Add some common key definitions
|
||||||
|
@ -48,7 +48,7 @@
|
|||||||
#include "panel.h" /* cpanel */
|
#include "panel.h" /* cpanel */
|
||||||
#include "main.h" /* repaint_screen */
|
#include "main.h" /* repaint_screen */
|
||||||
#include "hotlist.h"
|
#include "hotlist.h"
|
||||||
#include "key.h" /* ctrl_pressed */
|
#include "key.h" /* KEY_M_CTRL */
|
||||||
#include "command.h" /* cmdline */
|
#include "command.h" /* cmdline */
|
||||||
|
|
||||||
#define UX 5
|
#define UX 5
|
||||||
@ -385,9 +385,9 @@ static int hotlist_callback (Dlg_head * h, int Par, int Msg)
|
|||||||
|
|
||||||
case DLG_UNHANDLED_KEY:
|
case DLG_UNHANDLED_KEY:
|
||||||
switch (Par) {
|
switch (Par) {
|
||||||
|
case KEY_M_CTRL | '\n':
|
||||||
|
goto l1;
|
||||||
case '\n':
|
case '\n':
|
||||||
if (ctrl_pressed())
|
|
||||||
goto l1;
|
|
||||||
case KEY_ENTER:
|
case KEY_ENTER:
|
||||||
case KEY_RIGHT:
|
case KEY_RIGHT:
|
||||||
if (hotlist_button_callback (B_ENTER, 0)) {
|
if (hotlist_button_callback (B_ENTER, 0)) {
|
||||||
|
63
src/key.c
63
src/key.c
@ -60,6 +60,13 @@
|
|||||||
/* timeout for old_esc_mode in usec */
|
/* timeout for old_esc_mode in usec */
|
||||||
#define ESCMODE_TIMEOUT 1000000
|
#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 mou_auto_repeat = 100;
|
||||||
int double_click_speed = 250;
|
int double_click_speed = 250;
|
||||||
int old_esc_mode = 0;
|
int old_esc_mode = 0;
|
||||||
@ -82,6 +89,7 @@ static key_def *keys = 0;
|
|||||||
static int input_fd;
|
static int input_fd;
|
||||||
static int disabled_channels = 0; /* Disable channels checking */
|
static int disabled_channels = 0; /* Disable channels checking */
|
||||||
static int xgetch_second (void);
|
static int xgetch_second (void);
|
||||||
|
static int get_modifier (void);
|
||||||
|
|
||||||
/* File descriptor monitoring add/remove routines */
|
/* File descriptor monitoring add/remove routines */
|
||||||
typedef struct SelectList {
|
typedef struct SelectList {
|
||||||
@ -450,14 +458,12 @@ int define_sequence (int code, char *seq, int action)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int *pending_keys;
|
static int *pending_keys;
|
||||||
static int last_modifiers;
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
correct_key_code (int c)
|
correct_key_code (int c)
|
||||||
{
|
{
|
||||||
/* Remember key modifiers and strip them from the code */
|
/* Add key modifiers that cannot be deduced from the sequences */
|
||||||
last_modifiers = c & KEY_M_MASK;
|
c |= get_modifier ();
|
||||||
c &= ~KEY_M_MASK;
|
|
||||||
|
|
||||||
/* This is needed on some OS that do not support ncurses and */
|
/* This is needed on some OS that do not support ncurses and */
|
||||||
/* do some magic after read()ing the data */
|
/* 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)
|
get_modifier (void)
|
||||||
{
|
{
|
||||||
int result = 0;
|
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
|
#ifdef HAVE_TEXTMODE_X11_SUPPORT
|
||||||
if (x11_display) {
|
if (x11_display) {
|
||||||
Window root, child;
|
Window root, child;
|
||||||
@ -1006,35 +1010,36 @@ get_modifier (void)
|
|||||||
&root_y, &win_x, &win_y, &mask);
|
&root_y, &win_x, &win_y, &mask);
|
||||||
|
|
||||||
if (mask & ShiftMask)
|
if (mask & ShiftMask)
|
||||||
result |= SHIFT_PRESSED;
|
result |= KEY_M_SHIFT;
|
||||||
if (mask & ControlMask)
|
if (mask & ControlMask)
|
||||||
result |= CONTROL_PRESSED;
|
result |= KEY_M_CTRL;
|
||||||
return result;
|
return result;
|
||||||
} else
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
{
|
{
|
||||||
unsigned char modifiers = 6;
|
unsigned char modifiers = 6;
|
||||||
|
|
||||||
if (ioctl (0, TIOCLINUX, &modifiers) >= 0)
|
if (ioctl (0, TIOCLINUX, &modifiers) < 0)
|
||||||
result |= modifiers;
|
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;
|
return result;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
return 0;
|
return 0;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
|
||||||
ctrl_pressed (void)
|
|
||||||
{
|
|
||||||
if (get_modifier () & CONTROL_PRESSED)
|
|
||||||
return 1;
|
|
||||||
else
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void k_dispose (key_def *k)
|
static void k_dispose (key_def *k)
|
||||||
{
|
{
|
||||||
if (!k)
|
if (!k)
|
||||||
|
19
src/key.h
19
src/key.h
@ -9,33 +9,16 @@ void done_key (void);
|
|||||||
|
|
||||||
int get_event (Gpm_Event *event, int redo_event, int block);
|
int get_event (Gpm_Event *event, int redo_event, int block);
|
||||||
int is_idle (void);
|
int is_idle (void);
|
||||||
int ctrl_pressed (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
|
||||||
|
|
||||||
/* 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
|
* Internal representation of the key modifiers. It is used in the
|
||||||
* sequence tables. In the future, it will be part of the key code.
|
* sequence tables and the keycodes in the mc sources.
|
||||||
* Currently those bits are stripped in correct_key_code() and
|
|
||||||
* remembered in the last_modifiers variable.
|
|
||||||
*/
|
*/
|
||||||
#define KEY_M_SHIFT 0x1000
|
#define KEY_M_SHIFT 0x1000
|
||||||
#define KEY_M_ALT 0x2000
|
#define KEY_M_ALT 0x2000
|
||||||
|
@ -1741,8 +1741,8 @@ midnight_callback (struct Dlg_head *h, int id, int msg)
|
|||||||
if (id == '\t')
|
if (id == '\t')
|
||||||
free_completions (cmdline);
|
free_completions (cmdline);
|
||||||
|
|
||||||
/* On Linux, we can tell the difference */
|
/* Ctrl-Enter */
|
||||||
if (id == '\n' && ctrl_pressed ()) {
|
if (id == ('\n' | KEY_M_CTRL)) {
|
||||||
copy_prog_name ();
|
copy_prog_name ();
|
||||||
return MSG_HANDLED;
|
return MSG_HANDLED;
|
||||||
}
|
}
|
||||||
|
36
src/screen.c
36
src/screen.c
@ -1661,13 +1661,9 @@ prev_page (WPanel *panel)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
prev_page_key (WPanel *panel)
|
ctrl_prev_page (WPanel *panel)
|
||||||
{
|
{
|
||||||
if (ctrl_pressed ()){
|
do_cd ("..", cd_exact);
|
||||||
do_cd ("..", cd_exact);
|
|
||||||
} else {
|
|
||||||
prev_page (panel);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -1676,17 +1672,17 @@ next_page (WPanel *panel)
|
|||||||
int items;
|
int items;
|
||||||
|
|
||||||
if (panel->selected == panel->count - 1)
|
if (panel->selected == panel->count - 1)
|
||||||
return;
|
return;
|
||||||
unselect_item (panel);
|
unselect_item (panel);
|
||||||
items = ITEMS (panel);
|
items = ITEMS (panel);
|
||||||
if (panel->top_file > panel->count - 2 * items)
|
if (panel->top_file > panel->count - 2 * items)
|
||||||
items = panel->count - items - panel->top_file;
|
items = panel->count - items - panel->top_file;
|
||||||
if (panel->top_file + items < 0)
|
if (panel->top_file + items < 0)
|
||||||
items = - panel->top_file;
|
items = -panel->top_file;
|
||||||
if (!items)
|
if (!items)
|
||||||
panel->selected = panel->count - 1;
|
panel->selected = panel->count - 1;
|
||||||
else
|
else
|
||||||
panel->selected += items;
|
panel->selected += items;
|
||||||
panel->top_file += items;
|
panel->top_file += items;
|
||||||
|
|
||||||
/* This keeps the selection in it's relative position */
|
/* This keeps the selection in it's relative position */
|
||||||
@ -1698,14 +1694,12 @@ next_page (WPanel *panel)
|
|||||||
paint_dir (panel);
|
paint_dir (panel);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void next_page_key (WPanel *panel)
|
static void
|
||||||
|
ctrl_next_page (WPanel *panel)
|
||||||
{
|
{
|
||||||
if (ctrl_pressed() &&
|
if ((S_ISDIR (selection (panel)->buf.st_mode)
|
||||||
(S_ISDIR(selection (panel)->buf.st_mode) ||
|
|| link_isdir (selection (panel)))) {
|
||||||
link_isdir (selection (panel)))) {
|
do_cd (selection (panel)->fname, cd_exact);
|
||||||
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_C1, move_end },
|
||||||
{ KEY_END, move_end },
|
{ KEY_END, move_end },
|
||||||
{ KEY_A1, move_home },
|
{ KEY_A1, move_home },
|
||||||
{ KEY_NPAGE, next_page_key },
|
{ KEY_NPAGE, next_page },
|
||||||
{ KEY_PPAGE, prev_page_key },
|
{ 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 */
|
/* To quickly move in the panel */
|
||||||
{ ALT('g'), goto_top_file },
|
{ ALT('g'), goto_top_file },
|
||||||
|
25
src/widget.c
25
src/widget.c
@ -1190,21 +1190,26 @@ backward_word (WInput *in)
|
|||||||
static void
|
static void
|
||||||
key_left (WInput *in)
|
key_left (WInput *in)
|
||||||
{
|
{
|
||||||
if (ctrl_pressed ())
|
backward_char (in);
|
||||||
backward_word (in);
|
}
|
||||||
else
|
|
||||||
backward_char (in);
|
static void
|
||||||
|
key_ctrl_left (WInput *in)
|
||||||
|
{
|
||||||
|
backward_word (in);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
key_right (WInput *in)
|
key_right (WInput *in)
|
||||||
{
|
{
|
||||||
if (ctrl_pressed ())
|
forward_char (in);
|
||||||
forward_word (in);
|
}
|
||||||
else
|
|
||||||
forward_char (in);
|
static void
|
||||||
|
key_ctrl_right (WInput *in)
|
||||||
|
{
|
||||||
|
forward_word (in);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
backward_delete (WInput *in)
|
backward_delete (WInput *in)
|
||||||
{
|
{
|
||||||
@ -1396,9 +1401,11 @@ static const struct {
|
|||||||
{ KEY_END, end_of_line },
|
{ KEY_END, end_of_line },
|
||||||
{ KEY_C1, end_of_line },
|
{ KEY_C1, end_of_line },
|
||||||
{ KEY_LEFT, key_left },
|
{ KEY_LEFT, key_left },
|
||||||
|
{ KEY_LEFT | KEY_M_CTRL, key_ctrl_left },
|
||||||
{ XCTRL('b'), backward_char },
|
{ XCTRL('b'), backward_char },
|
||||||
{ ALT('b'), backward_word },
|
{ ALT('b'), backward_word },
|
||||||
{ KEY_RIGHT, key_right },
|
{ KEY_RIGHT, key_right },
|
||||||
|
{ KEY_RIGHT | KEY_M_CTRL, key_ctrl_right },
|
||||||
{ XCTRL('f'), forward_char },
|
{ XCTRL('f'), forward_char },
|
||||||
{ ALT('f'), forward_word },
|
{ ALT('f'), forward_word },
|
||||||
|
|
||||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user