From bca6eb52e53f58705ac9fb5d0b894b6a432afe96 Mon Sep 17 00:00:00 2001
From: Rob Swindell <rob@synchro.net>
Date: Sun, 3 Jul 2022 20:49:16 -0700
Subject: [PATCH] Setting console.mouse_mode to true  enables default
 mouse=enabled mode

A single source of truth is now used for SBBS's mouse mode (MOUSE_MODE_ON). A JS script doesn't need to know what SBBS's preferred/default mouse-enabled mode flags are, just set to this property to "true". Setting to "false" is the same as setting to MOUSE_MODE_OFF (0).
---
 src/sbbs3/inkey.cpp      | 9 +++++++--
 src/sbbs3/js_console.cpp | 5 ++++-
 src/sbbs3/sbbs.h         | 1 +
 3 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/src/sbbs3/inkey.cpp b/src/sbbs3/inkey.cpp
index 6471efbbc2..4073a5bfc5 100644
--- a/src/sbbs3/inkey.cpp
+++ b/src/sbbs3/inkey.cpp
@@ -567,7 +567,12 @@ void sbbs_t::set_mouse(long flags)
 		if(mode & MOUSE_MODE_ANY)	ansi_mouse(ANSI_MOUSE_ANY, true);
 		if(mode & MOUSE_MODE_EXT)	ansi_mouse(ANSI_MOUSE_EXT, true);
 
-		mouse_mode = flags;
+		if(mouse_mode != flags) {
+#if 0
+			lprintf(LOG_DEBUG, "New mouse mode: %X (was: %X)", flags, mouse_mode);
+#endif
+			mouse_mode = flags;
+		}
 	}
 }
 
@@ -589,7 +594,7 @@ struct mouse_hotspot* sbbs_t::add_hotspot(struct mouse_hotspot* spot)
 	list_node_t* node = listInsertNodeData(&mouse_hotspots, spot, sizeof(*spot));
 	if(node == NULL)
 		return NULL;
-	set_mouse(MOUSE_MODE_NORM | MOUSE_MODE_EXT);
+	set_mouse(MOUSE_MODE_ON);
 	return (struct mouse_hotspot*)node->data;
 }
 
diff --git a/src/sbbs3/js_console.cpp b/src/sbbs3/js_console.cpp
index 4296177e11..118f636d03 100644
--- a/src/sbbs3/js_console.cpp
+++ b/src/sbbs3/js_console.cpp
@@ -231,6 +231,8 @@ static JSBool js_console_set(JSContext *cx, JSObject *obj, jsid id, JSBool stric
 			sbbs->console=val;
 			break;
 		case CON_PROP_MOUSE_MODE:
+			if(*vp == JSVAL_TRUE)
+				val = MOUSE_MODE_ON;
 			sbbs->set_mouse(val);
 			break;
 		case CON_PROP_LNCNTR:
@@ -387,7 +389,8 @@ static jsSyncPropertySpec js_console_properties[] = {
 #ifdef BUILD_JSDOCS
 static const char* con_prop_desc[] = {
 	 "status bit-field (see <tt>CON_*</tt> in <tt>sbbsdefs.js</tt> for bit definitions)"
-	,"mouse mode bit-field (see <tt>MOUSE_MODE_*</tt> in <tt>sbbsdefs.js</tt> for bit definitions)"
+	,"mouse mode bit-field (see <tt>MOUSE_MODE_*</tt> in <tt>sbbsdefs.js</tt> for bit definitions, "
+		"set to <tt>true</tt> for default enabled mode, <tt>false</tt> to disable)"
 	,"current 0-based line counter (used for automatic screen pause)"
 	,"current 0-based row counter"
 	,"current 0-based column counter (used to auto-increment <i>line_counter</i> when screen wraps)"
diff --git a/src/sbbs3/sbbs.h b/src/sbbs3/sbbs.h
index 67a03dffd2..cd0508edce 100644
--- a/src/sbbs3/sbbs.h
+++ b/src/sbbs3/sbbs.h
@@ -903,6 +903,7 @@ public:
 #define MOUSE_MODE_BTN		(1<<2)	// Button-event tracking mode mouse reporting
 #define MOUSE_MODE_ANY		(1<<3)	// Any-event tracking mode mouse reporting
 #define MOUSE_MODE_EXT		(1<<4)	// SGR-encoded extended coordinate mouse reporting
+#define MOUSE_MODE_ON		(MOUSE_MODE_NORM | MOUSE_MODE_EXT) // Default mouse "enabled" mode flags
 
 	long	mouse_mode;			// Mouse reporting mode flags
 	uint	hot_attr;			// Auto-Mouse hot-spot attribute (when non-zero)
-- 
GitLab