From ceec7fb41c22e20c51f1bc55f9ba30405c2d4ed2 Mon Sep 17 00:00:00 2001
From: deuce <>
Date: Fri, 5 May 2006 21:01:33 +0000
Subject: [PATCH] If the keyboard buffer is full, and you're attempting to add
 a mouse event, don't beep, and keep count of the number of pending mouse
 events. These will be added as the buffer is drained.

---
 src/conio/console.c | 17 ++++++++++++++---
 src/conio/sdl_con.c | 14 ++++++++++++--
 2 files changed, 26 insertions(+), 5 deletions(-)

diff --git a/src/conio/console.c b/src/conio/console.c
index 75973bc848..f2a5dff851 100644
--- a/src/conio/console.c
+++ b/src/conio/console.c
@@ -166,6 +166,7 @@ typedef struct TextLine {
 	u_char	*exposed;
 } TextLine;
 TextLine *lines = NULL;
+unsigned int	x_pending_mousekeys=0;
 
 /* X Variables */
 Display *dpy=NULL;
@@ -572,8 +573,12 @@ KbdWrite(WORD code)
 		kf = K_BUFSTARTP;
 
 	if (kf == K_NEXT) {
-		x11.XBell(dpy, 0);
-		return;
+		if(code==CIO_KEY_MOUSE)
+			x_pending_mousekeys++;
+		else {
+			x11.XBell(dpy, 0);
+			return;
+		}
 	}
 	K_BUF(K_FREE) = code;
 	K_FREE = kf;
@@ -1799,12 +1804,18 @@ WORD
 KbdRead()
 {
 	int kf = K_NEXT;
+	WORD	ret;
 
 	K_NEXT = K_NEXT + 2;
 	if (K_NEXT == K_BUFENDP)
 		K_NEXT = K_BUFSTARTP;
 
-	return(K_BUF(kf));
+	ret=K_BUF(kf);
+	if(x_pending_mousekeys) {
+		KbdWrite(CIO_KEY_MOUSE);
+		x_pending_mousekeys--;
+	}
+	return(ret);
 }
 
 int
diff --git a/src/conio/sdl_con.c b/src/conio/sdl_con.c
index fdf714e64b..3b5ee51497 100644
--- a/src/conio/sdl_con.c
+++ b/src/conio/sdl_con.c
@@ -67,7 +67,7 @@ static int lastcursor_y=0;
 static int sdl_current_font=-99;
 static int lastfg=-1;
 static int lastbg=-1;
-
+static unsigned int sdl_pending_mousekeys=0;
 
 struct video_stats vstat;
 int fullscreen=0;
@@ -818,6 +818,13 @@ int sdl_getch(void)
 	sdl.SemWait(sdl_key_pending);
 	sdl.mutexP(sdl_keylock);
 	ch=sdl_keybuf[sdl_key++];
+	if(sdl_pending_mousekeys) {
+        sdl_keybuf[sdl_keynext++]=CIO_KEY_MOUSE & 0xff;
+        sdl.SemPost(sdl_key_pending);
+        sdl_keybuf[sdl_keynext++]=CIO_KEY_MOUSE >> 8;
+        sdl.SemPost(sdl_key_pending);
+		sdl_pending_mousekeys--;
+	}
 	sdl.mutexV(sdl_keylock);
 	return(ch);
 }
@@ -950,7 +957,10 @@ void sdl_add_key(unsigned int keyval)
 			return;
 		}
 		if((sdl_keynext+2==sdl_key) && keyval > 0xff) {
-			sdl_beep();
+			if(keyval==CIO_KEY_MOUSE)
+				sdl_pending_mousekeys++;
+			else
+				sdl_beep();
 			sdl.mutexV(sdl_keylock);
 			return;
 		}
-- 
GitLab