Fix build on systems that have a separate libintl library
[centerim5.git] / cppconsui / libtermkey / termkey-internal.h
blob733f148167a0ab91b5b94b00942ce49dcc819894
1 #ifndef GUARD_TERMKEY_INTERNAL_H_
2 #define GUARD_TERMKEY_INTERNAL_H_
4 #include "termkey.h"
6 #include <stdint.h>
7 #include <termios.h>
9 struct TermKeyDriver
11 const char *name;
12 void *(*new_driver)(TermKey *tk, const char *term);
13 void (*free_driver)(void *info);
14 int (*start_driver)(TermKey *tk, void *info);
15 int (*stop_driver)(TermKey *tk, void *info);
16 TermKeyResult (*peekkey)(TermKey *tk, void *info, TermKeyKey *key, int force, size_t *nbytes);
19 struct keyinfo {
20 TermKeyType type;
21 TermKeySym sym;
22 int modifier_mask;
23 int modifier_set;
26 struct TermKeyDriverNode;
27 struct TermKeyDriverNode {
28 struct TermKeyDriver *driver;
29 void *info;
30 struct TermKeyDriverNode *next;
33 struct TermKey {
34 int fd;
35 int flags;
36 int canonflags;
37 unsigned char *buffer;
38 size_t buffstart; // First offset in buffer
39 size_t buffcount; // NUMBER of entires valid in buffer
40 size_t buffsize; // Total malloc'ed size
41 size_t hightide; /* Position beyond buffstart at which peekkey() should next start
42 * normally 0, but see also termkey_interpret_csi */
44 struct termios restore_termios;
45 char restore_termios_valid;
47 int waittime; // msec
49 char is_closed;
50 char is_started;
52 int nkeynames;
53 const char **keynames;
55 // There are 32 C0 codes
56 struct keyinfo c0[32];
58 struct TermKeyDriverNode *drivers;
60 // Now some "protected" methods for the driver to call but which we don't
61 // want exported as real symbols in the library
62 struct {
63 void (*emit_codepoint)(TermKey *tk, long codepoint, TermKeyKey *key);
64 TermKeyResult (*peekkey_simple)(TermKey *tk, TermKeyKey *key, int force, size_t *nbytes);
65 TermKeyResult (*peekkey_mouse)(TermKey *tk, TermKeyKey *key, size_t *nbytes);
66 } method;
69 static inline void termkey_key_get_linecol(const TermKeyKey *key, int *line, int *col)
71 if(col)
72 *col = (unsigned char)key->code.mouse[1] | ((unsigned char)key->code.mouse[3] & 0x0f) << 8;
74 if(line)
75 *line = (unsigned char)key->code.mouse[2] | ((unsigned char)key->code.mouse[3] & 0x70) << 4;
78 static inline void termkey_key_set_linecol(TermKeyKey *key, int line, int col)
80 if(line > 0xfff)
81 line = 0xfff;
83 if(col > 0x7ff)
84 col = 0x7ff;
86 key->code.mouse[1] = (line & 0x0ff);
87 key->code.mouse[2] = (col & 0x0ff);
88 key->code.mouse[3] = (line & 0xf00) >> 8 | (col & 0x300) >> 4;
91 extern struct TermKeyDriver termkey_driver_csi;
92 extern struct TermKeyDriver termkey_driver_ti;
94 #endif