2014-10-14 00:08:15 +02:00
|
|
|
#ifndef TERMO_INTERNAL_H
|
|
|
|
#define TERMO_INTERNAL_H
|
2008-10-07 00:27:19 +02:00
|
|
|
|
2014-10-14 00:08:15 +02:00
|
|
|
#include "termo.h"
|
2008-10-07 00:27:19 +02:00
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <termios.h>
|
2014-09-28 03:51:45 +02:00
|
|
|
#include <stdbool.h>
|
|
|
|
#include <iconv.h>
|
2008-10-07 00:27:19 +02:00
|
|
|
|
2014-10-14 00:08:15 +02:00
|
|
|
typedef struct termo_driver termo_driver_t;
|
|
|
|
struct termo_driver
|
2008-10-07 00:27:19 +02:00
|
|
|
{
|
2014-09-23 01:38:08 +02:00
|
|
|
const char *name;
|
2014-10-14 00:08:15 +02:00
|
|
|
void *(*new_driver) (termo_t *tk, const char *term);
|
2014-09-23 01:38:08 +02:00
|
|
|
void (*free_driver) (void *info);
|
2014-10-14 00:08:15 +02:00
|
|
|
int (*start_driver) (termo_t *tk, void *info);
|
|
|
|
int (*stop_driver) (termo_t *tk, void *info);
|
|
|
|
termo_result_t (*peekkey) (termo_t *tk,
|
|
|
|
void *info, termo_key_t *key, int force, size_t *nbytes);
|
2008-10-07 00:27:19 +02:00
|
|
|
};
|
|
|
|
|
2014-09-23 01:38:08 +02:00
|
|
|
typedef struct keyinfo keyinfo_t;
|
|
|
|
struct keyinfo
|
|
|
|
{
|
2014-10-14 00:08:15 +02:00
|
|
|
termo_type_t type;
|
|
|
|
termo_sym_t sym;
|
2014-09-23 01:38:08 +02:00
|
|
|
int modifier_mask;
|
|
|
|
int modifier_set;
|
2008-10-08 01:12:41 +02:00
|
|
|
};
|
|
|
|
|
2014-10-14 00:08:15 +02:00
|
|
|
typedef struct termo_driver_node termo_driver_node_t;
|
|
|
|
struct termo_driver_node
|
2014-09-23 01:38:08 +02:00
|
|
|
{
|
2014-10-14 00:08:15 +02:00
|
|
|
termo_driver_t *driver;
|
2014-09-23 01:38:08 +02:00
|
|
|
void *info;
|
2014-10-14 00:08:15 +02:00
|
|
|
termo_driver_node_t *next;
|
2008-11-09 20:58:11 +01:00
|
|
|
};
|
|
|
|
|
2015-08-08 23:51:29 +02:00
|
|
|
enum peekey_flags
|
|
|
|
{
|
|
|
|
PEEKKEY_FORCE = 1 << 0,
|
|
|
|
PEEKKEY_ALT_PREFIXED = 1 << 1
|
|
|
|
};
|
|
|
|
|
2014-10-14 00:08:15 +02:00
|
|
|
struct termo
|
2014-09-23 01:38:08 +02:00
|
|
|
{
|
|
|
|
int fd;
|
|
|
|
int flags;
|
|
|
|
int canonflags;
|
2014-09-28 03:51:45 +02:00
|
|
|
|
2014-09-23 01:38:08 +02:00
|
|
|
unsigned char *buffer;
|
|
|
|
size_t buffstart; // First offset in buffer
|
2014-09-28 03:51:45 +02:00
|
|
|
size_t buffcount; // Number of entires valid in buffer
|
2014-09-23 01:38:08 +02:00
|
|
|
size_t buffsize; // Total malloc'ed size
|
|
|
|
|
2014-09-28 03:51:45 +02:00
|
|
|
// Position beyond buffstart at which peekkey() should next start.
|
2014-10-14 00:08:15 +02:00
|
|
|
// Normally 0, but see also termo_interpret_csi().
|
2014-09-23 01:38:08 +02:00
|
|
|
size_t hightide;
|
|
|
|
|
|
|
|
struct termios restore_termios;
|
2014-09-28 03:51:45 +02:00
|
|
|
bool restore_termios_valid;
|
2014-09-23 01:38:08 +02:00
|
|
|
|
2014-09-28 03:51:45 +02:00
|
|
|
int waittime; // In milliseconds
|
2014-09-23 01:38:08 +02:00
|
|
|
|
2014-09-28 03:51:45 +02:00
|
|
|
bool is_closed; // We've received EOF
|
|
|
|
bool is_started;
|
2014-09-23 01:38:08 +02:00
|
|
|
|
|
|
|
int nkeynames;
|
|
|
|
const char **keynames;
|
|
|
|
|
2014-09-28 03:51:45 +02:00
|
|
|
keyinfo_t c0[32]; // There are 32 C0 codes
|
|
|
|
iconv_t to_utf32_conv;
|
|
|
|
iconv_t from_utf32_conv;
|
2014-10-14 00:08:15 +02:00
|
|
|
termo_driver_node_t *drivers;
|
2014-09-23 01:38:08 +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
|
|
|
|
{
|
2014-10-14 00:08:15 +02:00
|
|
|
void (*emit_codepoint) (termo_t *tk,
|
|
|
|
uint32_t codepoint, termo_key_t *key);
|
|
|
|
termo_result_t (*peekkey_simple) (termo_t *tk,
|
2015-08-08 23:51:29 +02:00
|
|
|
termo_key_t *key, int flags, size_t *nbytes);
|
2014-10-14 00:08:15 +02:00
|
|
|
termo_result_t (*peekkey_mouse) (termo_t *tk,
|
|
|
|
termo_key_t *key, size_t *nbytes);
|
2014-09-23 01:38:08 +02:00
|
|
|
}
|
|
|
|
method;
|
2014-10-22 22:23:01 +02:00
|
|
|
|
2014-11-19 02:41:36 +01:00
|
|
|
// What we think should be the mouse protocol
|
|
|
|
termo_mouse_proto_t guessed_mouse_proto;
|
|
|
|
// The active mouse protocol
|
|
|
|
termo_mouse_proto_t mouse_proto;
|
|
|
|
// Mouse tracking mode
|
|
|
|
termo_mouse_tracking_t mouse_tracking;
|
2014-10-22 22:23:01 +02:00
|
|
|
|
|
|
|
// The mouse unfortunately directly depends on the terminfo driver to let
|
|
|
|
// it handle changes in the mouse protocol.
|
|
|
|
|
|
|
|
void *ti_data; // termo_ti_t pointer
|
|
|
|
|
|
|
|
struct
|
|
|
|
{
|
2014-11-19 02:41:36 +01:00
|
|
|
bool (*set_mouse_proto) (void *, termo_mouse_proto_t, bool);
|
2014-10-22 22:23:01 +02:00
|
|
|
bool (*set_mouse_tracking_mode) (void *, termo_mouse_tracking_t, bool);
|
|
|
|
}
|
|
|
|
ti_method;
|
2008-10-07 00:27:19 +02:00
|
|
|
};
|
|
|
|
|
2014-09-23 01:38:08 +02:00
|
|
|
static inline void
|
2014-10-14 00:08:15 +02:00
|
|
|
termo_key_get_linecol (const termo_key_t *key, int *line, int *col)
|
2012-04-24 16:25:17 +02:00
|
|
|
{
|
2014-09-23 01:38:08 +02:00
|
|
|
if (col)
|
2014-10-13 23:36:14 +02:00
|
|
|
*col = key->code.mouse.x;
|
2012-04-24 16:25:17 +02:00
|
|
|
|
2014-09-23 01:38:08 +02:00
|
|
|
if (line)
|
2014-10-13 23:36:14 +02:00
|
|
|
*line = key->code.mouse.y;
|
2012-04-24 16:25:17 +02:00
|
|
|
}
|
|
|
|
|
2014-09-23 01:38:08 +02:00
|
|
|
static inline void
|
2014-10-14 00:08:15 +02:00
|
|
|
termo_key_set_linecol (termo_key_t *key, int line, int col)
|
2012-04-24 16:25:17 +02:00
|
|
|
{
|
2014-10-13 23:36:14 +02:00
|
|
|
if (line > UINT16_MAX)
|
|
|
|
line = UINT16_MAX;
|
2012-04-24 16:25:17 +02:00
|
|
|
|
2014-10-13 23:36:14 +02:00
|
|
|
if (col > UINT16_MAX)
|
|
|
|
col = UINT16_MAX;
|
2012-04-24 16:25:17 +02:00
|
|
|
|
2014-10-13 23:36:14 +02:00
|
|
|
key->code.mouse.x = col;
|
|
|
|
key->code.mouse.y = line;
|
2012-04-24 16:25:17 +02:00
|
|
|
}
|
|
|
|
|
2014-10-14 00:08:15 +02:00
|
|
|
extern termo_driver_t termo_driver_csi;
|
|
|
|
extern termo_driver_t termo_driver_ti;
|
2014-09-23 01:38:08 +02:00
|
|
|
|
2014-10-14 00:08:15 +02:00
|
|
|
#endif // ! TERMO_INTERNAL_H
|
2008-10-07 00:27:19 +02:00
|
|
|
|