Patch backported from branch-5-4-stable.
https://bugs.gentoo.org/690014

--- gnuplot-5.2.8-orig/term/caca.trm
+++ gnuplot-5.2.8/term/caca.trm
@@ -1909,8 +1909,11 @@
 	CACA_result loop = CACA_loop;
 	caca_event_t ev;
 	const int event_mask =
-		CACA_EVENT_KEY_PRESS | CACA_EVENT_RESIZE |  CACA_EVENT_QUIT |
-		CACA_EVENT_MOUSE_MOTION | CACA_EVENT_MOUSE_PRESS | CACA_EVENT_MOUSE_RELEASE;
+		CACA_EVENT_KEY_PRESS | CACA_EVENT_RESIZE |  CACA_EVENT_QUIT
+#ifdef USE_MOUSE
+		| CACA_EVENT_MOUSE_MOTION | CACA_EVENT_MOUSE_PRESS | CACA_EVENT_MOUSE_RELEASE
+#endif
+		;
 	static int mx = 0, my = 0; /* current mouse position */
 	static unsigned long last_event_time = 0;
 
@@ -2577,11 +2580,13 @@
 		}
 	}
 
+#ifdef USE_MOUSE
 	if (changed) {
 		/* Replot only if something changed. */
 		CACA_zoom_or_replot = TRUE;
 		process_event(GE_replot, 0, 0, 0, 0, 0);
 	}
+#endif
 }
 
 
