Skip to content
Snippets Groups Projects
Commit 8da60139 authored by Rob Swindell's avatar Rob Swindell :speech_balloon:
Browse files

Use Synchronet's built-in mouse tracking support

Synchronet uses "extended normal" mouse reporting for mouse support
(e.g. menu/display file clickable "hot spots"). Many of the JS scripts
that predated Synchronet's own internal mouse support would send their
own mouse-reporting enablement and disablement ANSI sequences and the
terminal could become out of sync with the expectations of the script
(i.e. it would not necessarily disable the mouse modes that had been
set by SBBS before enabling its own preferred mode).

And some scripts (e.g. Synchronet Minesweeper) use a mixture of Synchronet
hotspot support and direct mouse click coordinate reporting, so it was a
mess going between different mouse reporting modes at different times in the
same script.

This all came to light as a result of the fix for issue #412: using mouse
button releases rather than presses to trigger a hotspot.

So mouse_getkey() now has as a separate "release" property it sets in the
return value. Right now its always the opposite of "press", but I can imagine
some mouse tracking modes where movement might be reported with neither a
button press nor release event.

Anyway, Nelgin, give this a try and see if it resolves the issues you were
reporting in IRC with avatar chooser mouse support.
parent bca6eb52
Branches
Tags
1 merge request!463MRC mods by Codefenix (2024-10-20)
Pipeline #3156 passed
......@@ -95,9 +95,12 @@ Frame.prototype.blit = function (bin, w, h, x, y, str, sc) {
}
function mouse_enable(enable) {
if (!console.term_supports(USER_ANSI | USER_MOUSE)) return;
console.mouse_mode = MOUSE_MODE_OFF; // While we're not using Synchronet internal mouse support in this script
ansiterm.send('mouse', enable ? 'set' : 'clear', 'normal_tracking');
const mouse_passthru = (CON_MOUSE_CLK_PASSTHRU | CON_MOUSE_REL_PASSTHRU);
if(enable)
console.status |= mouse_passthru;
else
console.status &= ~mouse_passthru;
console.mouse_mode = enable;
}
function bury_cursor() {
......@@ -124,8 +127,11 @@ function download_avatar() {
comment : ['']
};
sauce_lib.write(fn, sauce);
mouse_enable(false);
bbs.send_file(fn);
file_remove(fn);
console.clear_hotspots();
mouse_enable(true);
return true;
} else {
return false;
......@@ -134,9 +140,11 @@ function download_avatar() {
function upload_avatar() {
const fn = system.temp_dir + format('avatar-%04d.bin', user.number);
mouse_enable(false);
bbs.receive_file(fn);
const success = avatar_lib.import_file(user.number, fn, 0);
file_remove(fn);
console.clear_hotspots();
mouse_enable(true);
return success;
}
......@@ -248,7 +256,7 @@ function CollectionBrowser(filename, parent_frame) {
this.getcmd = function (cmd) {
var ret = null;
if (cmd.mouse !== null && cmd.mouse.press && cmd.mouse.x >= frames.container.x && cmd.mouse.x < frames.container.x + frames.container.width && cmd.mouse.y >= frames.container.y && cmd.mouse.y < frames.container.y + frames.container.height) {
if (cmd.mouse !== null && cmd.mouse.release && cmd.mouse.x >= frames.container.x && cmd.mouse.x < frames.container.x + frames.container.width && cmd.mouse.y >= frames.container.y && cmd.mouse.y < frames.container.y + frames.container.height) {
if (cmd.mouse.button == 0) {
var mx = cmd.mouse.x - frames.container.x;
var my = cmd.mouse.y - frames.container.y;
......@@ -838,7 +846,7 @@ function MainMenu(parent_frame) {
function clicked_quit(i, frame) {
if (i.mouse === null) return false;
if (!i.mouse.press) return false;
if (!i.mouse.release) return false;
if (i.mouse.button != 0) return false;
if (i.mouse.y != frame.y + frame.height - 1) return false;
var sx = frame.x + frame.width - 20;
......@@ -857,6 +865,7 @@ function init() {
js.on_exit("ansiterm.send('ext_mode', 'set', 'cursor')");
js.on_exit("mouse_enable(false);");
js.on_exit("bbs.sys_status = " + bbs.sys_status + ";");
js.on_exit("console.status = " + console.status);
js.on_exit("console.attributes = " + console.attributes + ";");
js.on_exit("console.clear();");
console.ctrlkey_passthru|=(1<<11); // Disable Ctrl-K handling in sbbs
......@@ -880,8 +889,8 @@ function main() {
const menu = new MainMenu(frame);
menu.open();
while (true) {
var i = mouse_getkey(K_NONE, 5, true); //console.inkey(K_NONE);
if ((i.key != '' || (i.mouse && i.mouse.press)) && !menu.getcmd(i)) break;
var i = mouse_getkey(K_NONE, 5, /* Mouse already enabled: */true);
if ((i.key != '' || (i.mouse && i.mouse.release)) && !menu.getcmd(i)) break;
menu.cycle();
if (frame.cycle()) bury_cursor();
}
......
......@@ -7,17 +7,10 @@ const fidoaddr = load({}, 'fidoaddr.js');
require("mouse_getkey.js", "mouse_getkey");
const ansiterm = load({}, 'ansiterm_lib.js');
function mouse_enable(enable) {
if (!console.term_supports(USER_ANSI)) return;
ansiterm.send('mouse', enable ? 'set' : 'clear', 'normal_tracking');
}
js.on_exit('console.attributes = ' + console.attributes);
js.on_exit('bbs.sys_status = ' + bbs.sys_status);
js.on_exit('mouse_enable(false);');
bbs.sys_status|=SS_MOFF;
mouse_enable(true);
const addrs = {};
system.fido_addr_list.forEach(function (e) {
......@@ -74,7 +67,7 @@ var key;
var zone;
console.ungetstr(KEY_UP);
while (!js.terminated) {
key = mouse_getkey(K_NOSPIN, undefined, true);
key = mouse_getkey(K_NOSPIN, undefined, false);
//key = console.getkey();
if (key.key.toLowerCase() == 'q') break;
if (key.mouse && key.mouse.press && key.mouse.button == 0 && key.mouse.y == frame.y + frame.height - 1 && key.mouse.x >= 52 && key.mouse.x <= 65) break;
......
......@@ -10,6 +10,7 @@ function mouse_getkey(mode, timeout, enabled)
var motion;
var mods;
var press;
var release;
var ansiterm = bbs.mods.ansiterm_lib;
if(!ansiterm)
ansiterm = bbs.mods.ansiterm_lib = load({}, "ansiterm_lib.js");
......@@ -23,10 +24,12 @@ function mouse_getkey(mode, timeout, enabled)
function mouse_enable(enable)
{
if(console.term_supports(USER_ANSI)) {
ansiterm.send('mouse', enable ? 'set' : 'clear', 'x10_compatible');
ansiterm.send('mouse', enable ? 'set' : 'clear', 'extended_coord');
}
const mouse_passthru = (CON_MOUSE_CLK_PASSTHRU | CON_MOUSE_REL_PASSTHRU);
if(enable)
console.status |= mouse_passthru;
else
console.status &= ~mouse_passthru;
console.mouse_mode = enable;
}
function restuff()
......@@ -121,6 +124,7 @@ function mouse_getkey(mode, timeout, enabled)
x = parseInt(m[2], 10);
y = parseInt(m[3], 10);
press = (m[4] === 'M');
release = !press;
key = 'Mouse';
}
}
......@@ -139,7 +143,7 @@ function mouse_getkey(mode, timeout, enabled)
}
} while(key === undefined);
if (key === 'Mouse') {
return {key:'', mouse:{button:button, press:press, x:x, y:y, mods:mods, motion:motion, ansi:ansi}};
return {key:'', mouse:{button:button, press:press, release:release, x:x, y:y, mods:mods, motion:motion, ansi:ansi}};
}
// TODO: Fake modes...
return {key:key, mouse:null};
......
......@@ -349,7 +349,7 @@ Tree.prototype.getcmd = function(cmd) {
/* if the submenu did not handle it, let this menu handle the command */
if(retval === this.__values__.NOT_HANDLED) {
if (cmd.mouse !== null && cmd.mouse.press && cmd.mouse.x >= this.frame.x && cmd.mouse.x < this.frame.x + this.frame.width && cmd.mouse.y >= this.frame.y && cmd.mouse.y < this.frame.y + this.frame.height) {
if (cmd.mouse !== null && cmd.mouse.release && cmd.mouse.x >= this.frame.x && cmd.mouse.x < this.frame.x + this.frame.width && cmd.mouse.y >= this.frame.y && cmd.mouse.y < this.frame.y + this.frame.height) {
var my = cmd.mouse.y - this.frame.y;
switch (cmd.mouse.button) {
case 0: // left click
......
......@@ -4,6 +4,7 @@
// Locate/copy 3rd party door installer files
{
var lib = load({}, 'install-3rdp-xtrn.js');
console.print("Scanning for installable 3rd-party programs...");
var out = lib.scan();
for(var i in out) {
alert(out[i]);
......@@ -17,17 +18,10 @@ load('tree.js');
require("mouse_getkey.js", "mouse_getkey");
const ansiterm = load({}, 'ansiterm_lib.js');
function mouse_enable(enable) {
if (!console.term_supports(USER_ANSI)) return;
ansiterm.send('mouse', enable ? 'set' : 'clear', 'normal_tracking');
}
js.on_exit('console.attributes = ' + console.attributes);
js.on_exit('bbs.sys_status = ' + bbs.sys_status);
js.on_exit('mouse_enable(false);');
bbs.sys_status|=SS_MOFF;
mouse_enable(true);
const frame = new Frame(1, 1, console.screen_columns, console.screen_rows, BG_BLUE|WHITE);
const main_frame = new Frame(1, 2, frame.width, frame.height - 2, BG_BLACK|LIGHTGRAY, frame);
......@@ -107,7 +101,7 @@ var key;
var xtrn;
console.ungetstr(KEY_UP);
while (!js.terminated) {
key = mouse_getkey(K_NOSPIN, undefined, true);//console.getkey();
key = mouse_getkey(K_NOSPIN, undefined, false);
if (key.key.toLowerCase() == 'q') break;
if (key.mouse && key.mouse.press && key.mouse.button == 0 && key.mouse.y == frame.y + frame.height - 1 && key.mouse.x >= 52 && key.mouse.x <= 65) break;
t = tree.getcmd(key);
......
......@@ -90,10 +90,11 @@ if(!ansiterm)
function mouse_enable(enable)
{
if(console.term_supports(USER_ANSI|USER_MOUSE)) {
ansiterm.send('mouse', enable ? 'set' : 'clear', 'x10_compatible');
ansiterm.send('mouse', enable ? 'set' : 'clear', 'extended_coord');
}
const mouse_passthru = (CON_MOUSE_CLK_PASSTHRU | CON_MOUSE_REL_PASSTHRU);
if(enable)
console.status |= mouse_passthru;
else
console.status &= ~mouse_passthru;
}
function show_image(filename, fx, delay)
......@@ -804,6 +805,7 @@ function get_difficulty(all)
draw_border();
console.attributes = WHITE;
console.clear_hotspots();
mouse_enable(false);
var lvls = "";
for(var i = 1; i <= max_difficulty; i++)
lvls += "\x01~" + i;
......@@ -819,7 +821,9 @@ function get_difficulty(all)
}
console.right((console.screen_columns - 24) / 2);
console.print(format("Difficulty Level (%s): ", lvls));
return console.getnum(max_difficulty);
var result = console.getnum(max_difficulty);
mouse_enable(true);
return result;
}
function target_height(difficulty)
......@@ -948,7 +952,7 @@ function play()
var mk = mouse_getkey(K_NONE, 1000, true);
var key = mk.key;
if (mk.mouse !== null) {
if ((!mk.mouse.press) || mk.mouse.motion || !screen_to_board(mk.mouse)) {
if ((!mk.mouse.release) || mk.mouse.motion || !screen_to_board(mk.mouse)) {
key = null;
}
else {
......@@ -1224,7 +1228,6 @@ try {
js.on_exit("console.line_counter = 0");
js.on_exit("console.status = " + console.status);
console.status |= CON_MOUSE_CLK_PASSTHRU;
js.on_exit("console.ctrlkey_passthru = " + console.ctrlkey_passthru);
console.ctrlkey_passthru = "KOPTUZ";
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment