2008-10-07 00:27:19 +02:00
|
|
|
#ifndef GUARD_TERMKEY_INTERNAL_H_
|
|
|
|
#define GUARD_TERMKEY_INTERNAL_H_
|
|
|
|
|
|
|
|
#include "termkey.h"
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <termios.h>
|
|
|
|
|
2009-07-15 21:40:44 +02:00
|
|
|
struct TermKeyDriver
|
2008-10-07 00:27:19 +02:00
|
|
|
{
|
2008-11-08 18:56:44 +01:00
|
|
|
const char *name;
|
2009-07-15 21:40:44 +02:00
|
|
|
void *(*new_driver)(TermKey *tk, const char *term);
|
2008-11-08 18:47:57 +01:00
|
|
|
void (*free_driver)(void *info);
|
2012-01-20 18:00:09 +01:00
|
|
|
int (*start_driver)(TermKey *tk, void *info);
|
|
|
|
int (*stop_driver)(TermKey *tk, void *info);
|
2009-07-15 21:40:44 +02:00
|
|
|
TermKeyResult (*peekkey)(TermKey *tk, void *info, TermKeyKey *key, int force, size_t *nbytes);
|
2008-10-07 00:27:19 +02:00
|
|
|
};
|
|
|
|
|
2008-10-08 01:12:41 +02:00
|
|
|
struct keyinfo {
|
2009-07-15 21:40:44 +02:00
|
|
|
TermKeyType type;
|
|
|
|
TermKeySym sym;
|
2008-10-08 01:12:41 +02:00
|
|
|
int modifier_mask;
|
|
|
|
int modifier_set;
|
|
|
|
};
|
|
|
|
|
2009-07-15 21:40:44 +02:00
|
|
|
struct TermKeyDriverNode;
|
|
|
|
struct TermKeyDriverNode {
|
|
|
|
struct TermKeyDriver *driver;
|
2008-11-09 20:58:11 +01:00
|
|
|
void *info;
|
2009-07-15 21:40:44 +02:00
|
|
|
struct TermKeyDriverNode *next;
|
2008-11-09 20:58:11 +01:00
|
|
|
};
|
|
|
|
|
2012-03-26 19:30:04 +02:00
|
|
|
struct TermKey {
|
2008-10-07 00:27:19 +02:00
|
|
|
int fd;
|
|
|
|
int flags;
|
2011-08-28 18:50:18 +02:00
|
|
|
int canonflags;
|
2008-10-07 00:27:19 +02:00
|
|
|
unsigned char *buffer;
|
|
|
|
size_t buffstart; // First offset in buffer
|
|
|
|
size_t buffcount; // NUMBER of entires valid in buffer
|
|
|
|
size_t buffsize; // Total malloc'ed size
|
2012-11-30 15:35:23 +01:00
|
|
|
size_t hightide; /* Position beyond buffstart at which peekkey() should next start
|
|
|
|
* normally 0, but see also termkey_interpret_csi */
|
2008-10-07 00:27:19 +02:00
|
|
|
|
|
|
|
struct termios restore_termios;
|
|
|
|
char restore_termios_valid;
|
|
|
|
|
|
|
|
int waittime; // msec
|
|
|
|
|
|
|
|
char is_closed;
|
2012-03-08 22:15:25 +01:00
|
|
|
char is_started;
|
2008-10-07 00:27:19 +02:00
|
|
|
|
|
|
|
int nkeynames;
|
|
|
|
const char **keynames;
|
|
|
|
|
2008-10-08 01:12:41 +02:00
|
|
|
// There are 32 C0 codes
|
|
|
|
struct keyinfo c0[32];
|
|
|
|
|
2009-07-15 21:40:44 +02:00
|
|
|
struct TermKeyDriverNode *drivers;
|
2008-10-07 23:22:59 +02:00
|
|
|
|
|
|
|
// Now some "protected" methods for the driver to call but which we don't
|
|
|
|
// want exported as real symbols in the library
|
|
|
|
struct {
|
2009-07-15 21:40:44 +02:00
|
|
|
void (*emit_codepoint)(TermKey *tk, long codepoint, TermKeyKey *key);
|
|
|
|
TermKeyResult (*peekkey_simple)(TermKey *tk, TermKeyKey *key, int force, size_t *nbytes);
|
2009-11-26 01:27:58 +01:00
|
|
|
TermKeyResult (*peekkey_mouse)(TermKey *tk, TermKeyKey *key, size_t *nbytes);
|
2008-10-07 23:22:59 +02:00
|
|
|
} method;
|
2008-10-07 00:27:19 +02:00
|
|
|
};
|
|
|
|
|
2012-04-24 16:25:17 +02:00
|
|
|
static inline void termkey_key_get_linecol(const TermKeyKey *key, int *line, int *col)
|
|
|
|
{
|
|
|
|
if(col)
|
|
|
|
*col = (unsigned char)key->code.mouse[1] | ((unsigned char)key->code.mouse[3] & 0x0f) << 8;
|
|
|
|
|
|
|
|
if(line)
|
|
|
|
*line = (unsigned char)key->code.mouse[2] | ((unsigned char)key->code.mouse[3] & 0x70) << 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void termkey_key_set_linecol(TermKeyKey *key, int line, int col)
|
|
|
|
{
|
|
|
|
if(line > 0xfff)
|
|
|
|
line = 0xfff;
|
|
|
|
|
|
|
|
if(col > 0x7ff)
|
|
|
|
col = 0x7ff;
|
|
|
|
|
|
|
|
key->code.mouse[1] = (line & 0x0ff);
|
|
|
|
key->code.mouse[2] = (col & 0x0ff);
|
|
|
|
key->code.mouse[3] = (line & 0xf00) >> 8 | (col & 0x300) >> 4;
|
|
|
|
}
|
|
|
|
|
2009-07-15 21:40:44 +02:00
|
|
|
extern struct TermKeyDriver termkey_driver_csi;
|
|
|
|
extern struct TermKeyDriver termkey_driver_ti;
|
2008-10-07 00:27:19 +02:00
|
|
|
|
|
|
|
#endif
|