DEVEL_COMMIT: added some code for init and initial handle keyboard via glib

Signed-off-by: Slava Zanko <slavazanko@gmail.com>
This commit is contained in:
Slava Zanko 2009-08-31 17:55:12 +03:00
parent 2715dab362
commit 169e707637
10 changed files with 1694 additions and 6 deletions

43
src/event/gsource.c Normal file
View File

@ -0,0 +1,43 @@
/*
Handle any events in application.
Interface functions: add/del gsource to mainloop
Copyright (C) 2009 The Free Software Foundation, Inc.
Written by:
Slava Zanko <slavazanko@gmail.com>, 2009.
This file is part of the Midnight Commander.
The Midnight Commander 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.
The Midnight Commander 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
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA.
*/
#include "event.h"
#include "internal.h"
/*** global variables ****************************************************************************/
/*** file scope macro definitions ****************************************************************/
/*** file scope type declarations ****************************************************************/
/*** file scope variables ************************************************************************/
/*** file scope functions ************************************************************************/
/*** public functions ****************************************************************************/
/* --------------------------------------------------------------------------------------------- */

View File

@ -14,7 +14,7 @@ endif
TTY_SRC = \
color-internal.c color-internal.h\
color.c color.h \
key.c key.h key_define.h keyxdef.c \
key.c key.h key-gsource.c key-internal.h key-define.h keyxdef.c \
mouse.c mouse.h \
tty.c tty.h tty-internal.h \
win.c win.h \

118
src/tty/key-gsource.c Normal file
View File

@ -0,0 +1,118 @@
/* Keyboard support routines.
Handle keyboard via GMainLoop.
Copyright (C) 1994, 1995, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
2005, 2006, 2007, 2009 Free Software Foundation, Inc.
Written by: 1994, 1995 Miguel de Icaza.
1994, 1995 Janne Kukonlehto.
1995 Jakub Jelinek.
1997 Norbert Warmuth
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.
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
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
/** \file key.c
* \brief Source: keyboard support routines
*/
#include <config.h>
#include "../../src/global.h"
#include "../../src/tty/key-internal.h"
#include "../../src/event/event.h"
/*** global variables **************************************************/
tty_key_event_t tty_key_event;
/*** file scope macro definitions **************************************/
/* The maximum sequence length (32 + null terminator) */
#define SEQ_BUFFER_LEN 33
/*** file scope type declarations **************************************/
/*** file scope variables **********************************************/
static GIOChannel *tty_key_channel_key;
/*** file scope functions **********************************************/
/* --------------------------------------------------------------------------------------------- */
static gboolean
tty_key_gsource_keyboard_callback(GIOChannel *source, GIOCondition condition, gpointer data)
{
tty_key_event_t *tty_key_event;
int seq_buffer [SEQ_BUFFER_LEN];
int seq_count=0;
gchar buf;
gsize bytes_read;
while (g_io_channel_read_chars (source, &buf, 1 , &bytes_read, NULL) == G_IO_STATUS_NORMAL)
{
seq_buffer [seq_count++] = (int) buf;
}
/*
TODO:
1) parse seq_buffer
2) handle ESC, <key> begavior
3) handle mouse
*/
tty_key_event.key = 0;
mcevent_raise("keyboard.press", (gpointer) &tty_key_event);
return TRUE;
}
/* --------------------------------------------------------------------------------------------- */
static void
tty_key_gsource_keyboard_init(void)
{
#ifdef __CYGWIN__
tty_key_channel_key = g_io_channel_win32_new (input_fd);
#else
tty_key_channel_key = g_io_channel_unix_new (input_fd);
#endif
g_io_channel_set_encoding (tty_key_channel_key, NULL, NULL);
g_io_channel_set_buffered (tty_key_channel_key, FALSE);
g_io_channel_set_flags (tty_key_channel_key, G_IO_FLAG_NONBLOCK, NULL);
g_io_add_watch (tty_key_channel_key, G_IO_IN /*|G_IO_HUP|G_IO_PRI|G_IO_ERR|G_IO_NVAL*/ , tty_key_gsource_keyboard_callback, NULL);
}
/* --------------------------------------------------------------------------------------------- */
/*** public functions **************************************************/
/* --------------------------------------------------------------------------------------------- */
void
tty_key_gsource_init(void)
{
tty_key_gsource_keyboard_init();
}
/* --------------------------------------------------------------------------------------------- */
void
tty_key_gsource_deinit(void)
{
}
/* --------------------------------------------------------------------------------------------- */

25
src/tty/key-internal.h Normal file
View File

@ -0,0 +1,25 @@
/** \file key-internal.h
* \brief Header: keyboard support routines. Internal functions
*/
#ifndef MC_KEY_INTERNAL_H
#define MC_KEY_INTERNAL_H
/*** typedefs(not structures) and defined constants ********************/
/*** enums *************************************************************/
/*** structures declarations (and typedefs of structures)***************/
/*** global variables defined in .c file *******************************/
extern int input_fd;
/*** declarations of public functions **********************************/
void tty_key_gsource_init(void);
void tty_key_gsource_deinit(void);
#endif /* MC_KEY_INTERNAL_H */

1480
src/tty/key-old.c Normal file

File diff suppressed because it is too large Load Diff

View File

@ -43,13 +43,14 @@
#include "../../src/tty/tty-internal.h" /* mouse_enabled */
#include "../../src/tty/mouse.h"
#include "../../src/tty/key.h"
#include "../../src/tty/key_define.h"
#include "../../src/tty/key-define.h"
#include "../../src/tty/win.h" /* xterm_flag */
#include "../../src/main.h"
#include "../../src/layout.h" /* winch_flag, mc_refresh() */
#include "../../src/cons.saver.h"
#include "../../src/strutil.h" /* str_casecmp */
#include "../../src/event/event.h"
#ifdef USE_VFS
#include "../../vfs/gc.h"
@ -81,6 +82,9 @@
/*** global variables **************************************************/
int input_fd;
/* If true, use + and \ keys normally and select/unselect do if M-+ / M-\.
and M-- and keypad + / - */
int alternate_plus_minus = 0;
@ -221,7 +225,6 @@ static int keyboard_key_timeout = 1000000; /* settable via env */
/* This holds all the key definitions */
static key_def *keys = NULL;
static int input_fd;
static int disabled_channels = 0; /* Disable channels checking */
static SelectList *select_list = NULL;
@ -759,6 +762,7 @@ s_dispose (SelectList *sel)
}
}
/*** public functions **************************************************/
/* This has to be called before init_slang or whatever routine
@ -771,6 +775,8 @@ init_key (void)
if (kt != NULL)
keyboard_key_timeout = atoi (kt);
tty_key_gsource_init();
/* This has to be the first define_sequence */
/* So, we can assume that the first keys member has ESC */
define_sequences (mc_default_keys);
@ -833,6 +839,7 @@ done_key (void)
if (x11_display)
mc_XCloseDisplay (x11_display);
#endif
tty_key_gsource_deinit();
}
void
@ -1257,6 +1264,14 @@ get_key_code (int no_delay)
/* Returns EV_NONE if non-blocking or interrupt set and nothing was done */
int
tty_get_event (struct Gpm_Event *event, gboolean redo_event, gboolean block)
{
sleep(1);
mc_log("tty_get_event\n");
return EV_MOUSE;
}
int
tty_get_event_NONUSED (struct Gpm_Event *event, gboolean redo_event, gboolean block)
{
int c;
static int flag = 0; /* Return value from select */
@ -1402,6 +1417,8 @@ tty_getch (void)
Gpm_Event ev;
int key;
mc_log("tty_getch\n");
ev.x = -1;
while ((key = tty_get_event (&ev, FALSE, TRUE)) == EV_NONE)
;

View File

@ -11,9 +11,14 @@
#include "../../src/tty/tty.h" /* KEY_F macro */
typedef struct tty_key_event_struct {
int key;
} tty_key_event_t;
gboolean define_sequence (int code, const char *seq, int action);
void init_key (void);
void tty_key_init (void);
void init_key_input_fd (void);
void done_key (void);

View File

@ -415,7 +415,7 @@ void load_qnx_key_defines (void)
#endif /* HAVE_QNX_KEYS */
/* called from key.c/init_key() */
/* called from key.c/tty_key_init() */
void load_xtra_key_defines (void)
{
#ifdef HAVE_QNX_KEYS

View File

@ -246,7 +246,7 @@ tty_init (gboolean slow, gboolean ugly_lines)
tty_start_interrupt_key ();
/* It's the small part from the previous init_key() */
/* It's the small part from the previous tty_key_init() */
init_key_input_fd ();
SLsmg_init_smg ();