mirror of
https://github.com/rkd77/elinks.git
synced 2024-12-04 14:46:47 -05:00
terminal: Define separate structs for events passed via the interlink socket.
This way, struct term_event can be changed without any interprocess compatibility problems.
This commit is contained in:
parent
51bc99a175
commit
6052fa12d8
@ -456,7 +456,7 @@ struct os2_mouse_spec {
|
||||
int p[2];
|
||||
void (*fn)(void *, unsigned char *, int);
|
||||
void *data;
|
||||
unsigned char buffer[sizeof(struct term_event)];
|
||||
unsigned char buffer[sizeof(struct interlink_event)];
|
||||
int bufptr;
|
||||
int terminate;
|
||||
};
|
||||
@ -483,8 +483,8 @@ mouse_thread(void *p)
|
||||
status = -1;
|
||||
|
||||
while (1) {
|
||||
struct term_event ev;
|
||||
struct term_event_mouse mouse;
|
||||
struct interlink_event ev;
|
||||
struct interlink_event_mouse mouse;
|
||||
int w, ww;
|
||||
|
||||
if (MouReadEventQue(ms, rd, *mh)) break;
|
||||
@ -514,7 +514,7 @@ mouse_thread(void *p)
|
||||
status = -1;
|
||||
}
|
||||
|
||||
set_mouse_term_event(&ev, mouse.x, mouse.y, mouse.button);
|
||||
set_mouse_interlink_event(&ev, mouse.x, mouse.y, mouse.button);
|
||||
if (hard_write(oms->p[1], (unsigned char *) &ev, sizeof(ev)) != sizeof(ev)) break;
|
||||
}
|
||||
#ifdef HAVE_SYS_FMUTEX_H
|
||||
@ -535,7 +535,7 @@ void
|
||||
mouse_handle(struct os2_mouse_spec *oms)
|
||||
{
|
||||
ssize_t r = safe_read(oms->p[0], oms->buffer + oms->bufptr,
|
||||
sizeof(struct term_event) - oms->bufptr);
|
||||
sizeof(struct interlink_event) - oms->bufptr);
|
||||
|
||||
if (r <= 0) {
|
||||
unhandle_mouse(oms);
|
||||
@ -543,9 +543,9 @@ mouse_handle(struct os2_mouse_spec *oms)
|
||||
}
|
||||
|
||||
oms->bufptr += r;
|
||||
if (oms->bufptr == sizeof(struct term_event)) {
|
||||
if (oms->bufptr == sizeof(struct interlink_event)) {
|
||||
oms->bufptr = 0;
|
||||
oms->fn(oms->data, oms->buffer, sizeof(struct term_event));
|
||||
oms->fn(oms->data, oms->buffer, sizeof(struct interlink_event));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -36,7 +36,7 @@ struct sysmouse_spec {
|
||||
static void
|
||||
sysmouse_handler(void *data)
|
||||
{
|
||||
static struct term_event_mouse prev_mouse;
|
||||
static struct interlink_event_mouse prev_mouse;
|
||||
static int prev_buttons;
|
||||
struct sysmouse_spec *sp = data;
|
||||
void *itrm = sp->itrm;
|
||||
@ -44,8 +44,8 @@ sysmouse_handler(void *data)
|
||||
int buttons, change;
|
||||
int extended_button;
|
||||
mouse_info_t mi;
|
||||
struct term_event_mouse mouse;
|
||||
struct term_event ev;
|
||||
struct interlink_event_mouse mouse;
|
||||
struct interlink_event ev;
|
||||
|
||||
mi.operation = MOUSE_GETINFO;
|
||||
if (ioctl(fd, CONS_MOUSECTL, &mi) == -1) return;
|
||||
@ -154,7 +154,7 @@ sysmouse_handler(void *data)
|
||||
}
|
||||
|
||||
prev_buttons = buttons;
|
||||
set_mouse_term_event(&ev, mouse.x, mouse.y, mouse.button);
|
||||
set_mouse_interlink_event(&ev, mouse.x, mouse.y, mouse.button);
|
||||
sp->fn(itrm, (unsigned char *)&ev, sizeof(ev));
|
||||
}
|
||||
|
||||
|
@ -34,8 +34,8 @@ static void
|
||||
gpm_mouse_in(struct gpm_mouse_spec *gms)
|
||||
{
|
||||
Gpm_Event gev;
|
||||
struct term_event ev;
|
||||
struct term_event_mouse mouse;
|
||||
struct interlink_event ev;
|
||||
struct interlink_event_mouse mouse;
|
||||
|
||||
if (Gpm_GetEvent(&gev) <= 0) {
|
||||
clear_handlers(gms->h);
|
||||
@ -72,7 +72,7 @@ gpm_mouse_in(struct gpm_mouse_spec *gms)
|
||||
else
|
||||
return;
|
||||
|
||||
set_mouse_term_event(&ev, mouse.x, mouse.y, mouse.button);
|
||||
set_mouse_interlink_event(&ev, mouse.x, mouse.y, mouse.button);
|
||||
gms->fn(gms->data, (char *) &ev, sizeof(ev));
|
||||
}
|
||||
|
||||
|
@ -192,17 +192,18 @@ ignore_mouse_event(struct terminal *term, struct term_event *ev)
|
||||
#endif
|
||||
|
||||
static int
|
||||
handle_interlink_event(struct terminal *term, struct term_event *ev)
|
||||
handle_interlink_event(struct terminal *term, struct interlink_event *ilev)
|
||||
{
|
||||
struct terminal_info *info = NULL;
|
||||
struct terminal_interlink *interlink = term->interlink;
|
||||
struct term_event tev;
|
||||
|
||||
switch (ev->ev) {
|
||||
switch (ilev->ev) {
|
||||
case EVENT_INIT:
|
||||
if (interlink->qlen < TERMINAL_INFO_SIZE)
|
||||
return 0;
|
||||
|
||||
info = (struct terminal_info *) ev;
|
||||
info = (struct terminal_info *) ilev;
|
||||
|
||||
if (interlink->qlen < TERMINAL_INFO_SIZE + info->length)
|
||||
return 0;
|
||||
@ -219,7 +220,10 @@ handle_interlink_event(struct terminal *term, struct term_event *ev)
|
||||
* terminal screen before decoding the session info so that
|
||||
* handling of bad URL syntax by openning msg_box() will be
|
||||
* possible. */
|
||||
term_send_event(term, ev);
|
||||
set_init_term_event(&tev,
|
||||
ilev->info.size.width,
|
||||
ilev->info.size.height);
|
||||
term_send_event(term, &tev);
|
||||
|
||||
/* Either the initialization of the first session failed or we
|
||||
* are doing a remote session so quit.*/
|
||||
@ -234,29 +238,38 @@ handle_interlink_event(struct terminal *term, struct term_event *ev)
|
||||
return 0;
|
||||
}
|
||||
|
||||
ev->ev = EVENT_REDRAW;
|
||||
ilev->ev = EVENT_REDRAW;
|
||||
/* Fall through */
|
||||
case EVENT_REDRAW:
|
||||
case EVENT_RESIZE:
|
||||
term_send_event(term, ev);
|
||||
set_wh_term_event(&tev, ilev->ev,
|
||||
ilev->info.size.width,
|
||||
ilev->info.size.height);
|
||||
term_send_event(term, &tev);
|
||||
break;
|
||||
|
||||
case EVENT_MOUSE:
|
||||
#ifdef CONFIG_MOUSE
|
||||
reset_timer();
|
||||
if (!ignore_mouse_event(term, ev))
|
||||
term_send_event(term, ev);
|
||||
tev.ev = ilev->ev;
|
||||
copy_struct(&tev.info.mouse, &ilev->info.mouse);
|
||||
if (!ignore_mouse_event(term, &tev))
|
||||
term_send_event(term, &tev);
|
||||
#endif
|
||||
break;
|
||||
|
||||
case EVENT_KBD:
|
||||
{
|
||||
int utf8_io = -1;
|
||||
int key = get_kbd_key(ev);
|
||||
int key;
|
||||
|
||||
set_kbd_term_event(&tev, ilev->info.keyboard.key, ilev->info.keyboard.modifier);
|
||||
|
||||
key = get_kbd_key(&tev);
|
||||
|
||||
reset_timer();
|
||||
|
||||
if (check_kbd_modifier(ev, KBD_MOD_CTRL) && (key == 'l' || key == 'L')) {
|
||||
if (check_kbd_modifier(&tev, KBD_MOD_CTRL) && (key == 'l' || key == 'L')) {
|
||||
redraw_terminal_cls(term);
|
||||
break;
|
||||
|
||||
@ -280,18 +293,18 @@ handle_interlink_event(struct terminal *term, struct term_event *ev)
|
||||
|
||||
if (u < interlink->utf_8.min)
|
||||
u = UCS_NO_CHAR;
|
||||
term_send_ucs(term, ev, u);
|
||||
term_send_ucs(term, &tev, u);
|
||||
}
|
||||
break;
|
||||
|
||||
} else {
|
||||
interlink->utf_8.len = 0;
|
||||
term_send_ucs(term, ev, UCS_NO_CHAR);
|
||||
term_send_ucs(term, &tev, UCS_NO_CHAR);
|
||||
}
|
||||
}
|
||||
|
||||
if (key < 0x80 || key > 0xFF || !utf8_io) {
|
||||
term_send_event(term, ev);
|
||||
term_send_event(term, &tev);
|
||||
break;
|
||||
|
||||
} else if ((key & 0xC0) == 0xC0 && (key & 0xFE) != 0xFE) {
|
||||
@ -309,7 +322,7 @@ handle_interlink_event(struct terminal *term, struct term_event *ev)
|
||||
break;
|
||||
}
|
||||
|
||||
term_send_ucs(term, ev, UCS_NO_CHAR);
|
||||
term_send_ucs(term, &tev, UCS_NO_CHAR);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -318,12 +331,12 @@ handle_interlink_event(struct terminal *term, struct term_event *ev)
|
||||
return 0;
|
||||
|
||||
default:
|
||||
ERROR(gettext("Bad event %d"), ev->ev);
|
||||
ERROR(gettext("Bad event %d"), ilev->ev);
|
||||
}
|
||||
|
||||
/* For EVENT_INIT we read a liitle more */
|
||||
if (info) return TERMINAL_INFO_SIZE + info->length;
|
||||
return sizeof(*ev);
|
||||
return sizeof(*ilev);
|
||||
}
|
||||
|
||||
void
|
||||
@ -368,8 +381,8 @@ in_term(struct terminal *term)
|
||||
interlink->qlen += r;
|
||||
interlink->qfreespace -= r;
|
||||
|
||||
while (interlink->qlen >= sizeof(struct term_event)) {
|
||||
struct term_event *ev = (struct term_event *) iq;
|
||||
while (interlink->qlen >= sizeof(struct interlink_event)) {
|
||||
struct interlink_event *ev = (struct interlink_event *) iq;
|
||||
int event_size = handle_interlink_event(term, ev);
|
||||
|
||||
/* If the event was not handled save the bytes in the queue for
|
||||
|
@ -38,6 +38,22 @@ struct term_event {
|
||||
} info;
|
||||
};
|
||||
|
||||
struct interlink_event {
|
||||
enum term_event_type ev;
|
||||
|
||||
union {
|
||||
/* EVENT_MOUSE */
|
||||
struct interlink_event_mouse mouse;
|
||||
|
||||
/* EVENT_KBD */
|
||||
struct interlink_event_keyboard keyboard;
|
||||
|
||||
/* EVENT_INIT, EVENT_RESIZE, EVENT_REDRAW */
|
||||
#define interlink_event_size term_event_size
|
||||
struct interlink_event_size size;
|
||||
} info;
|
||||
};
|
||||
|
||||
static inline void
|
||||
set_mouse_term_event(struct term_event *ev, int x, int y, unsigned int button)
|
||||
{
|
||||
@ -46,6 +62,14 @@ set_mouse_term_event(struct term_event *ev, int x, int y, unsigned int button)
|
||||
set_mouse(&ev->info.mouse, x, y, button);
|
||||
}
|
||||
|
||||
static inline void
|
||||
set_mouse_interlink_event(struct interlink_event *ev, int x, int y, unsigned int button)
|
||||
{
|
||||
memset(ev, 0, sizeof(*ev));
|
||||
ev->ev = EVENT_MOUSE;
|
||||
set_mouse(&ev->info.mouse, x, y, button);
|
||||
}
|
||||
|
||||
static inline void
|
||||
set_kbd_term_event(struct term_event *ev, int key, int modifier)
|
||||
{
|
||||
@ -54,6 +78,14 @@ set_kbd_term_event(struct term_event *ev, int key, int modifier)
|
||||
kbd_set(&ev->info.keyboard, key, modifier);
|
||||
}
|
||||
|
||||
static inline void
|
||||
set_kbd_interlink_event(struct interlink_event *ev, int key, int modifier)
|
||||
{
|
||||
memset(ev, 0, sizeof(*ev));
|
||||
ev->ev = EVENT_KBD;
|
||||
kbd_set(&ev->info.keyboard, key, modifier);
|
||||
}
|
||||
|
||||
static inline void
|
||||
set_abort_term_event(struct term_event *ev)
|
||||
{
|
||||
@ -74,6 +106,17 @@ set_wh_term_event(struct term_event *ev, enum term_event_type type, int width, i
|
||||
#define set_resize_term_event(ev, w, h) set_wh_term_event(ev, EVENT_RESIZE, w, h)
|
||||
#define set_redraw_term_event(ev, w, h) set_wh_term_event(ev, EVENT_REDRAW, w, h)
|
||||
|
||||
static inline void
|
||||
set_wh_interlink_event(struct interlink_event *ev, enum term_event_type type, int width, int height)
|
||||
{
|
||||
memset(ev, 0, sizeof(*ev));
|
||||
ev->ev = type;
|
||||
ev->info.size.width = width;
|
||||
ev->info.size.height = height;
|
||||
}
|
||||
|
||||
#define set_resize_interlink_event(ev, w, h) set_wh_interlink_event(ev, EVENT_RESIZE, w, h)
|
||||
|
||||
|
||||
/* This holds the information used when handling the initial connection between
|
||||
* a dumb and master terminal. */
|
||||
@ -83,7 +126,7 @@ set_wh_term_event(struct term_event *ev, enum term_event_type type, int width, i
|
||||
* add new members add them at the bottom and use magic variables to
|
||||
* distinguish them when decoding the terminal info. */
|
||||
struct terminal_info {
|
||||
struct term_event event; /* The EVENT_INIT event */
|
||||
struct interlink_event event; /* The EVENT_INIT event */
|
||||
unsigned char name[MAX_TERM_LEN]; /* $TERM environment name */
|
||||
unsigned char cwd[MAX_CWD_LEN]; /* Current working directory */
|
||||
int system_env; /* System info (X, screen) */
|
||||
|
@ -67,7 +67,7 @@ struct itrm_out {
|
||||
* socket connection is terminal.fdin in the master process.
|
||||
* If the connection is from the master process to itself, it
|
||||
* uses a pipe; otherwise a socket. The events are formatted
|
||||
* as struct term_event, but at the beginning of the
|
||||
* as struct interlink_event, but at the beginning of the
|
||||
* connection, a struct terminal_info and extra data are also
|
||||
* sent. */
|
||||
int sock;
|
||||
|
@ -135,10 +135,10 @@ itrm_queue_event(struct itrm *itrm, unsigned char *data, int len)
|
||||
void
|
||||
kbd_ctrl_c(void)
|
||||
{
|
||||
struct term_event ev;
|
||||
struct interlink_event ev;
|
||||
|
||||
if (!ditrm) return;
|
||||
set_kbd_term_event(&ev, KBD_CTRL_C, KBD_MOD_NONE);
|
||||
set_kbd_interlink_event(&ev, KBD_CTRL_C, KBD_MOD_NONE);
|
||||
itrm_queue_event(ditrm, (unsigned char *) &ev, sizeof(ev));
|
||||
}
|
||||
|
||||
@ -190,11 +190,11 @@ send_done_sequence(int h, int altscreen)
|
||||
void
|
||||
resize_terminal(void)
|
||||
{
|
||||
struct term_event ev;
|
||||
struct interlink_event ev;
|
||||
int width, height;
|
||||
|
||||
get_terminal_size(ditrm->out.std, &width, &height);
|
||||
set_resize_term_event(&ev, width, height);
|
||||
set_resize_interlink_event(&ev, width, height);
|
||||
itrm_queue_event(ditrm, (char *) &ev, sizeof(ev));
|
||||
}
|
||||
|
||||
@ -265,7 +265,7 @@ handle_trm(int std_in, int std_out, int sock_in, int sock_out, int ctl_in,
|
||||
{
|
||||
struct itrm *itrm;
|
||||
struct terminal_info info;
|
||||
struct term_event_size *size = &info.event.info.size;
|
||||
struct interlink_event_size *size = &info.event.info.size;
|
||||
unsigned char *ts;
|
||||
|
||||
memset(&info, 0, sizeof(info));
|
||||
@ -654,7 +654,7 @@ get_esc_code(unsigned char *str, int len, unsigned char *code, int *num)
|
||||
/* Returns length of the escape sequence or -1 if the caller needs to set up
|
||||
* the ESC delay timer. */
|
||||
static int
|
||||
decode_terminal_escape_sequence(struct itrm *itrm, struct term_event *ev)
|
||||
decode_terminal_escape_sequence(struct itrm *itrm, struct interlink_event *ev)
|
||||
{
|
||||
struct term_event_keyboard kbd = { KBD_UNDEF, KBD_MOD_NONE };
|
||||
unsigned char c;
|
||||
@ -671,7 +671,7 @@ decode_terminal_escape_sequence(struct itrm *itrm, struct term_event *ev)
|
||||
&& itrm->in.queue.data[3] >= 'A'
|
||||
&& itrm->in.queue.data[3] <= 'L') {
|
||||
kbd.key = KBD_F1 + itrm->in.queue.data[3] - 'A';
|
||||
copy_struct(&ev->info.keyboard, &kbd);
|
||||
set_kbd_interlink_event(ev, kbd.key, kbd.modifier);
|
||||
return 4;
|
||||
}
|
||||
|
||||
@ -772,7 +772,7 @@ decode_terminal_escape_sequence(struct itrm *itrm, struct term_event *ev)
|
||||
|
||||
/* KBD_UNDEF here means it was unrecognized or a mouse event. */
|
||||
if (kbd.key != KBD_UNDEF)
|
||||
set_kbd_term_event(ev, kbd.key, kbd.modifier);
|
||||
set_kbd_interlink_event(ev, kbd.key, kbd.modifier);
|
||||
|
||||
return el;
|
||||
}
|
||||
@ -785,10 +785,10 @@ decode_terminal_escape_sequence(struct itrm *itrm, struct term_event *ev)
|
||||
* The length of the escape sequence otherwise.
|
||||
* Returning >0 does not imply this function has altered *ev. */
|
||||
static int
|
||||
decode_terminal_application_key(struct itrm *itrm, struct term_event *ev)
|
||||
decode_terminal_application_key(struct itrm *itrm, struct interlink_event *ev)
|
||||
{
|
||||
unsigned char c;
|
||||
struct term_event_keyboard kbd = { KBD_UNDEF, KBD_MOD_NONE };
|
||||
struct interlink_event_keyboard kbd = { KBD_UNDEF, KBD_MOD_NONE };
|
||||
|
||||
assert(itrm->in.queue.len >= 2);
|
||||
assert(itrm->in.queue.data[0] == ASCII_ESC);
|
||||
@ -834,7 +834,7 @@ decode_terminal_application_key(struct itrm *itrm, struct term_event *ev)
|
||||
|
||||
|
||||
static void
|
||||
set_kbd_event(struct term_event *ev, int key, int modifier)
|
||||
set_kbd_event(struct interlink_event *ev, int key, int modifier)
|
||||
{
|
||||
switch (key) {
|
||||
case ASCII_TAB:
|
||||
@ -869,13 +869,13 @@ set_kbd_event(struct term_event *ev, int key, int modifier)
|
||||
}
|
||||
}
|
||||
|
||||
set_kbd_term_event(ev, key, modifier);
|
||||
set_kbd_interlink_event(ev, key, modifier);
|
||||
}
|
||||
|
||||
static void
|
||||
kbd_timeout(struct itrm *itrm)
|
||||
{
|
||||
struct term_event ev;
|
||||
struct interlink_event ev;
|
||||
int el;
|
||||
|
||||
itrm->timer = TIMER_ID_UNDEF;
|
||||
@ -914,14 +914,14 @@ kbd_timeout(struct itrm *itrm)
|
||||
static int
|
||||
process_queue(struct itrm *itrm)
|
||||
{
|
||||
struct term_event ev;
|
||||
struct interlink_event ev;
|
||||
int el = 0;
|
||||
|
||||
if (!itrm->in.queue.len) goto return_without_event;
|
||||
assert(!itrm->blocked);
|
||||
if_assert_failed return 0; /* unlike goto, don't enable reading */
|
||||
|
||||
set_kbd_term_event(&ev, KBD_UNDEF, KBD_MOD_NONE);
|
||||
set_kbd_interlink_event(&ev, KBD_UNDEF, KBD_MOD_NONE);
|
||||
|
||||
#ifdef DEBUG_ITRM_QUEUE
|
||||
{
|
||||
@ -1002,7 +1002,9 @@ process_queue(struct itrm *itrm)
|
||||
el = -1;
|
||||
else {
|
||||
el = 2;
|
||||
copy_struct(&ev.info.keyboard, &os2xtd[itrm->in.queue.data[1]]);
|
||||
set_kbd_interlink_event(&ev,
|
||||
os2xtd[itrm->in.queue.data[1]].key,
|
||||
os2xtd[itrm->in.queue.data[1]].modifier);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -8,6 +8,11 @@ struct term_event_keyboard {
|
||||
int modifier;
|
||||
};
|
||||
|
||||
struct interlink_event_keyboard {
|
||||
int key;
|
||||
int modifier;
|
||||
};
|
||||
|
||||
#define KBD_UNDEF -1
|
||||
|
||||
#define KBD_ENTER 0x100
|
||||
|
@ -126,11 +126,11 @@ decode_mouse_position(struct itrm *itrm, int from)
|
||||
/* Returns length of the escape sequence or -1 if the caller needs to set up
|
||||
* the ESC delay timer. */
|
||||
int
|
||||
decode_terminal_mouse_escape_sequence(struct itrm *itrm, struct term_event *ev,
|
||||
decode_terminal_mouse_escape_sequence(struct itrm *itrm, struct interlink_event *ev,
|
||||
int el, int v)
|
||||
{
|
||||
static int xterm_button = -1;
|
||||
struct term_event_mouse mouse;
|
||||
struct interlink_event_mouse mouse;
|
||||
|
||||
if (itrm->in.queue.len - el < 3)
|
||||
return -1;
|
||||
@ -203,7 +203,7 @@ decode_terminal_mouse_escape_sequence(struct itrm *itrm, struct term_event *ev,
|
||||
|
||||
/* Postpone changing of the event type until all sanity
|
||||
* checks have been done. */
|
||||
set_mouse_term_event(ev, mouse.x, mouse.y, mouse.button);
|
||||
set_mouse_interlink_event(ev, mouse.x, mouse.y, mouse.button);
|
||||
|
||||
return el;
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
#ifndef EL__TERMINAL_MOUSE_H
|
||||
#define EL__TERMINAL_MOUSE_H
|
||||
|
||||
struct term_event;
|
||||
struct interlink_event;
|
||||
struct itrm;
|
||||
|
||||
/* The mouse reporting button byte looks like:
|
||||
@ -80,6 +80,7 @@ struct term_event_mouse {
|
||||
int x, y;
|
||||
unsigned int button;
|
||||
};
|
||||
#define interlink_event_mouse term_event_mouse
|
||||
|
||||
#define BM_BUTT 7
|
||||
#define B_LEFT 0
|
||||
@ -116,7 +117,7 @@ void send_mouse_done_sequence(int h);
|
||||
void disable_mouse(void);
|
||||
void enable_mouse(void);
|
||||
void toggle_mouse(void);
|
||||
int decode_terminal_mouse_escape_sequence(struct itrm *itrm, struct term_event *ev, int el, int v);
|
||||
int decode_terminal_mouse_escape_sequence(struct itrm *itrm, struct interlink_event *ev, int el, int v);
|
||||
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user