terminal: Define separate structs for events passed via the interlink socket.

This way, struct term_event can be changed without any interprocess
compatibility problems.

---
commit 1857d69c9c6b51ceee5ee8611a0fba8fb1f1777b
tree 99ebca8ff1a5e5adea4903b11ffe8fa5f775f0a1
parent 637a41b0a4f69328e4acd6bef723966d44cf2ffa
author Kalle Olavi Niemitalo <[EMAIL PROTECTED]> Sat, 05 Aug 2006 11:49:57 +0300
committer Kalle Olavi Niemitalo <[EMAIL PROTECTED]> Sat, 05 Aug 2006 20:06:33 +0300

 src/osdep/os2/os2.c   |   14 +++++++-------
 src/osdep/unix/bsd.c  |    8 ++++----
 src/osdep/unix/unix.c |    6 +++---
 src/terminal/event.c  |   49 +++++++++++++++++++++++++++++++------------------
 src/terminal/event.h  |   45 ++++++++++++++++++++++++++++++++++++++++++++-
 src/terminal/itrm.h   |    2 +-
 src/terminal/kbd.c    |   34 ++++++++++++++++++----------------
 src/terminal/kbd.h    |    5 +++++
 src/terminal/mouse.c  |    6 +++---
 src/terminal/mouse.h  |    5 +++--
 10 files changed, 119 insertions(+), 55 deletions(-)

diff --git a/src/osdep/os2/os2.c b/src/osdep/os2/os2.c
index 6eb00d6..922e0c9 100644
--- a/src/osdep/os2/os2.c
+++ b/src/osdep/os2/os2.c
@@ -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 @@ #endif
 			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));
 	}
 }
 
diff --git a/src/osdep/unix/bsd.c b/src/osdep/unix/bsd.c
index 42ff9bf..bac3a6c 100644
--- a/src/osdep/unix/bsd.c
+++ b/src/osdep/unix/bsd.c
@@ -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 @@ #endif
 	}
 
 	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));
 }
 
diff --git a/src/osdep/unix/unix.c b/src/osdep/unix/unix.c
index 0f78740..122d334 100644
--- a/src/osdep/unix/unix.c
+++ b/src/osdep/unix/unix.c
@@ -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));
 }
 
diff --git a/src/terminal/event.c b/src/terminal/event.c
index 2032e0e..b69f7e8 100644
--- a/src/terminal/event.c
+++ b/src/terminal/event.c
@@ -192,17 +192,18 @@ ignore_mouse_event(struct terminal *term
 #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 *
 		 * 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 *
 			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 @@ #endif /* CONFIG_UTF_8 */
 
 					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 @@ #endif /* CONFIG_UTF_8 */
 			break;
 		}
 
-		term_send_ucs(term, ev, UCS_NO_CHAR);
+		term_send_ucs(term, &tev, UCS_NO_CHAR);
 		break;
 	}
 
@@ -318,12 +331,12 @@ #endif /* CONFIG_UTF_8 */
 		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
diff --git a/src/terminal/event.h b/src/terminal/event.h
index ffd3590..c83b454 100644
--- a/src/terminal/event.h
+++ b/src/terminal/event.h
@@ -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)
 {
@@ -47,6 +63,14 @@ set_mouse_term_event(struct term_event *
 }
 
 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)
 {
 	memset(ev, 0, sizeof(*ev));
@@ -55,6 +79,14 @@ set_kbd_term_event(struct term_event *ev
 }
 
 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)
 {
 	memset(ev, 0, sizeof(*ev));
@@ -74,6 +106,17 @@ #define set_init_term_event(ev, w, h) se
 #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 @@ #define set_redraw_term_event(ev, w, h) 
  * 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) */
diff --git a/src/terminal/itrm.h b/src/terminal/itrm.h
index f2033c1..441ab04 100644
--- a/src/terminal/itrm.h
+++ b/src/terminal/itrm.h
@@ -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;
diff --git a/src/terminal/kbd.c b/src/terminal/kbd.c
index 6aeb297..3d8d673 100644
--- a/src/terminal/kbd.c
+++ b/src/terminal/kbd.c
@@ -135,10 +135,10 @@ itrm_queue_event(struct itrm *itrm, unsi
 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 @@ #undef write_sequence
 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 
 {
 	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 @@ #endif
 /* 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 i
 		    && 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 @@ #endif /* CONFIG_MOUSE */
 
 	/* 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 @@ #endif /* CONFIG_MOUSE */
  *   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 i
 
 
 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 @@ #endif
 		}
 	}
 
-	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 @@ #include "terminal/key.inc"
 			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);
 		}
 	}
 
diff --git a/src/terminal/kbd.h b/src/terminal/kbd.h
index 958e1b3..d8d5462 100644
--- a/src/terminal/kbd.h
+++ b/src/terminal/kbd.h
@@ -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
diff --git a/src/terminal/mouse.c b/src/terminal/mouse.c
index 2cf2f83..7af40ee 100644
--- a/src/terminal/mouse.c
+++ b/src/terminal/mouse.c
@@ -126,11 +126,11 @@ #define TW_BUTT_RIGHT	4
 /* 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(st
 
 	/* 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;
 }
diff --git a/src/terminal/mouse.h b/src/terminal/mouse.h
index 068e6ae..3e65012 100644
--- a/src/terminal/mouse.h
+++ b/src/terminal/mouse.h
@@ -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

Attachment: pgpgQ6qKtPIyy.pgp
Description: PGP signature

_______________________________________________
elinks-dev mailing list
[email protected]
http://linuxfromscratch.org/mailman/listinfo/elinks-dev

Reply via email to