From 9ce9bb70a02867f5fe7fd868e9093cf2c147ce17 Mon Sep 17 00:00:00 2001
From: deuce <>
Date: Thu, 11 Oct 2007 10:45:06 +0000
Subject: [PATCH] Update to use batched flush

---
 src/conio/x_cio.c    | 9 +++++++++
 src/conio/x_cio.h    | 1 +
 src/conio/x_events.c | 7 ++++---
 src/conio/x_events.h | 1 +
 4 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/src/conio/x_cio.c b/src/conio/x_cio.c
index 24251ab6de..01b719cc4d 100644
--- a/src/conio/x_cio.c
+++ b/src/conio/x_cio.c
@@ -432,3 +432,12 @@ void x11_drawrect(int xoffset,int yoffset,int width,int height,unsigned char *da
 		while(write(local_pipe[1], &ev, sizeof(ev))==-1);
 	}
 }
+
+void x11_flush(void)
+{
+	struct x11_local_event ev;
+
+	ev.type=X11_LOCAL_FLUSH;
+	if(x11_initialized)
+		while(write(local_pipe[1], &ev, sizeof(ev))==-1);
+}
diff --git a/src/conio/x_cio.h b/src/conio/x_cio.h
index f46602ab9a..e5011eb980 100644
--- a/src/conio/x_cio.h
+++ b/src/conio/x_cio.h
@@ -70,6 +70,7 @@ int x_getfont(void);
 int x_loadfont(char *filename);
 int x_get_window_info(int *width, int *height, int *xpos, int *ypos);
 void x11_drawrect(int xoffset,int yoffset,int width,int height,unsigned char *data);
+void x11_flush(void);
 #ifdef __cplusplus
 }
 #endif
diff --git a/src/conio/x_events.c b/src/conio/x_events.c
index b36e530878..4ccf88ad1c 100644
--- a/src/conio/x_events.c
+++ b/src/conio/x_events.c
@@ -229,7 +229,6 @@ static int init_window()
     x11.XSelectInput(dpy, win, KeyReleaseMask | KeyPressMask |
 		     ExposureMask | ButtonPressMask
 		     | ButtonReleaseMask | PointerMotionMask | StructureNotifyMask);
-//	x11.XFlush(dpy);
 	x11.XGetWindowAttributes(dpy,win,&attr);
 	memcpy(&visual,attr.visual,sizeof(visual));
 
@@ -302,7 +301,7 @@ static int video_init()
 		return(-1);
 
 	vstat.scaling=1;
-	bitmap_init(x11_drawrect);
+	bitmap_init(x11_drawrect, x11_flush);
 
     /* Initialize mode 3 (text, 80x25, 16 colors) */
     if(init_mode(3)) {
@@ -381,7 +380,6 @@ static void local_draw_rect(struct update_rect *rect)
 	}
 #endif
 #endif
-	x11.XFlush(dpy);
 	free(rect->data);
 }
 
@@ -866,6 +864,9 @@ void x11_event_thread(void *args)
 						case X11_LOCAL_DRAWRECT:
 							local_draw_rect(&lev.data.rect);
 							break;
+						case X11_LOCAL_FLUSH:
+							x11.XFlush(dpy);
+							break;
 						case X11_LOCAL_BEEP:
 							x11.XBell(dpy, 100);
 							break;
diff --git a/src/conio/x_events.h b/src/conio/x_events.h
index 0785a7843c..49cfd4cc04 100644
--- a/src/conio/x_events.h
+++ b/src/conio/x_events.h
@@ -21,6 +21,7 @@ enum x11_local_events {
 	,X11_LOCAL_COPY
 	,X11_LOCAL_PASTE
 	,X11_LOCAL_DRAWRECT
+	,X11_LOCAL_FLUSH
 	,X11_LOCAL_BEEP
 };
 
-- 
GitLab