From d42859f6582c088624c7dbd2308bb79f33282329 Mon Sep 17 00:00:00 2001 From: ANSI TV Admin Date: Wed, 11 Nov 2026 12:04:09 -0800 Subject: [PATCH 01/24] SyncTERM: exclusive (captured) mouse, per BBS entry Capture the pointer to the window and report MOTION instead of position, so a game driven over the wire can keep turning: the pointer cannot walk out of the window mid-turn, and the reported position is an accumulator that is deliberately NOT clamped, because a position pinned at the edge of the screen silently swallows the rest of the movement. Off by default and set per entry -- "Exclusive Mouse" in the entry editor, ExclusiveMouse= in syncterm.lst, bbs.exclusiveMouse from Wren -- because it is what a game needs and a nuisance for a BBS. Released unconditionally when the session ends by any path; a terminal that kept the pointer after the session would be one the user cannot get out of. SDL_SetRelativeMouseMode is resolved as an OPTIONAL symbol: a terminal built against an SDL that lacks it still runs, without capture. Files: conio/{ciolib.h,sdlfuncs.h,sdlfuncs.c,sdl_con.c}, syncterm/{bbslist.h,bbslist.c,wren_bind_menu.c,term.c} Ported to master 1.10b (72f4ea56). Also carries the Wren entry-editor row ("Exclusive Mouse", bbs.exclusiveMouse) that the shipped ANSI TV build has. --- src/conio/ciolib.h | 5 +++ src/conio/sdl_con.c | 51 +++++++++++++++++++++++ src/conio/sdlfuncs.c | 4 ++ src/conio/sdlfuncs.h | 4 ++ src/syncterm/bbslist.c | 9 ++++ src/syncterm/bbslist.h | 4 ++ src/syncterm/scripts/menu_bbs_editor.wren | 3 ++ src/syncterm/term.c | 11 +++++ src/syncterm/wren_bind_menu.c | 2 + 9 files changed, 93 insertions(+) diff --git a/src/conio/ciolib.h b/src/conio/ciolib.h index 991c123a..afdb57ae 100644 --- a/src/conio/ciolib.h +++ b/src/conio/ciolib.h @@ -873,4 +873,9 @@ CIOLIBEXPORT int ciokey_wait(void); #define CIO_KEY_LITERAL_E0 0xE0E0 // Literal 0xe0 character #define CIO_KEY_WREN_CONSOLE 0x29E0 // Ctrl-` opens the Wren scripting console (high byte = `'s scancode 0x29) +/* Exclusive mouse: capture the pointer to the window and report motion + * rather than position. Answers non-zero if the backend could do it. + * Set per BBS entry -- see "Exclusive Mouse" in the entry editor. */ +CIOLIBEXPORT int ciolib_set_mouse_exclusive(int on); + #endif /* Do not add anything after this line */ diff --git a/src/conio/sdl_con.c b/src/conio/sdl_con.c index 8513b3e7..95ad6d20 100644 --- a/src/conio/sdl_con.c +++ b/src/conio/sdl_con.c @@ -40,6 +40,24 @@ int bitmap_width,bitmap_height; /* 256 bytes so I can cheat */ unsigned char sdl_keybuf[256]; /* Keyboard buffer */ + +/* + * Exclusive mouse -- see ciolib_set_mouse_exclusive(). + * + * Off, the pointer is the desktop's: it reports where it is, and it can + * walk out of the window in the middle of a turn. On, SDL captures it, + * hides it, and reports MOTION instead of position -- which is what a game + * wants and what a terminal has never been able to give one. + * + * The reported position is then this accumulator rather than the pointer, + * and it is deliberately NOT clamped to the window: a caller who keeps + * turning must keep being told so, and a position pinned at the edge would + * silently swallow the rest of the movement. + */ +static int sdl_mouse_exclusive = 0; +static int sdl_rel_x = 0, sdl_rel_y = 0; +static int sdl_rel_centred = 0; + unsigned char sdl_key=0; /* Index into keybuf for next key in buffer */ unsigned char sdl_keynext=0; /* Index into keybuf for next free position */ @@ -819,6 +837,19 @@ static void setup_surfaces(struct video_stats *vs) } /* Called from event thread only */ +CIOLIBEXPORT int +ciolib_set_mouse_exclusive(int on) +{ + if (sdl.SetRelativeMouseMode == NULL) + return 0; /* SDL too old; caller carries on without */ + if (sdl.SetRelativeMouseMode(on ? SDL_TRUE : SDL_FALSE) != 0) + return 0; + sdl_mouse_exclusive = on ? 1 : 0; + /* Centred on the first motion, where the screen size is in scope. */ + sdl_rel_centred = 0; + return 1; +} + static void sdl_add_key(unsigned int keyval, struct video_stats *vs) { int w, h; @@ -1207,6 +1238,26 @@ void sdl_video_event_thread(void *data) ((km & KMOD_CTRL) ? CIOLIB_KMOD_CTRL : 0) | ((km & KMOD_ALT) ? CIOLIB_KMOD_ALT : 0); pthread_once(&ciolib_mouse_initialized, init_mouse); + if (sdl_mouse_exclusive) { + if (!sdl_rel_centred) { + /* Start from the middle so the + * first report is not a jump. */ + sdl_rel_x = cvstat.scrnwidth / 2; + sdl_rel_y = cvstat.scrnheight / 2; + sdl_rel_centred = 1; + } + /* Captured: report where the movement has + * carried us, not where the pointer is -- + * the pointer is not going anywhere. */ + sdl_rel_x += ev.motion.xrel; + sdl_rel_y += ev.motion.yrel; + ciomouse_gotevent(CIOLIB_MOUSE_MOVE, + win_to_text_xpos(sdl_rel_x, &cvstat), + win_to_text_ypos(sdl_rel_y, &cvstat), + win_to_res_xpos(sdl_rel_x, &cvstat), + win_to_res_ypos(sdl_rel_y, &cvstat), mods); + break; + } ciomouse_gotevent(CIOLIB_MOUSE_MOVE,win_to_text_xpos(ev.motion.x, &cvstat),win_to_text_ypos(ev.motion.y, &cvstat), win_to_res_xpos(ev.motion.x, &cvstat), win_to_res_ypos(ev.motion.y, &cvstat), mods); break; case SDL_MOUSEBUTTONDOWN: diff --git a/src/conio/sdlfuncs.c b/src/conio/sdlfuncs.c index 59bb53e6..2a06f5bd 100644 --- a/src/conio/sdlfuncs.c +++ b/src/conio/sdlfuncs.c @@ -94,6 +94,10 @@ int load_sdl_funcs(struct sdlfuncs *sdlf) xp_dlclose(sdl_dll); return(-1); } + /* Not fatal if missing: every other entry point here is required to + * run at all, but a terminal without pointer capture is still a + * terminal. The caller checks for NULL and does without. */ + sdlf->SetRelativeMouseMode=xp_dlsym(sdl_dll, SDL_SetRelativeMouseMode); if((sdlf->WasInit=xp_dlsym(sdl_dll, SDL_WasInit))==NULL) { xp_dlclose(sdl_dll); return(-1); diff --git a/src/conio/sdlfuncs.h b/src/conio/sdlfuncs.h index 813defc9..e6447949 100644 --- a/src/conio/sdlfuncs.h +++ b/src/conio/sdlfuncs.h @@ -28,6 +28,10 @@ struct sdlfuncs { void (HACK_HACK_HACK *GetWindowSizeInPixels) (SDL_Window *window, int *w, int *h); void (HACK_HACK_HACK *SetWindowIcon) (SDL_Window *win, SDL_Surface *icon); int (HACK_HACK_HACK *ShowCursor) (int toggle); + /* Pointer capture, for the exclusive mouse mode a game wants: + * the cursor is hidden, locked to the window, and motion arrives + * as deltas that do not stop at the edge of the screen. */ + int (HACK_HACK_HACK *SetRelativeMouseMode) (SDL_bool enabled); Uint32 (HACK_HACK_HACK *WasInit) (Uint32 flags); SDL_bool (HACK_HACK_HACK *GetWindowWMInfo) (SDL_Window *window, SDL_SysWMinfo *info); const char *(HACK_HACK_HACK *GetError) (void); diff --git a/src/syncterm/bbslist.c b/src/syncterm/bbslist.c index c871bdd5..63cd2e87 100644 --- a/src/syncterm/bbslist.c +++ b/src/syncterm/bbslist.c @@ -203,6 +203,12 @@ static struct sort_order_info sort_order[] = { offsetof(struct bbslist, yellow_is_yellow), sizeof(((struct bbslist *)NULL)->yellow_is_yellow) }, + { + "Exclusive Mouse", + 0, + offsetof(struct bbslist, exclusive_mouse), + sizeof(((struct bbslist *)NULL)->exclusive_mouse) + }, { "Terminal Type", 0, @@ -920,6 +926,7 @@ read_item(ini_fp_list_t *listfile, struct bbslist *entry, ini_lv_string_t *bbsna entry->rip = iniGetEnum(section, NULL, "RIP", rip_versions, RIP_VERSION_NONE); entry->force_lcf = iniGetBool(section, NULL, "ForceLCF", false); entry->yellow_is_yellow = iniGetBool(section, NULL, "YellowIsYellow", false); + entry->exclusive_mouse = iniGetBool(section, NULL, "ExclusiveMouse", false); iniGetSString(section, NULL, "TerminalType", "", entry->term_name, sizeof(entry->term_name)); entry->ssh_fingerprint_len = 0; entry->lf_expand = iniGetBool(section, NULL, "LFExpand", false); @@ -1452,6 +1459,8 @@ update_bbs_ini(str_list_t *inifile, struct bbslist *bbs, bool new_entry) &ini_style); iniSetBool(inifile, section, "YellowIsYellow", bbs->yellow_is_yellow, &ini_style); + iniSetBool(inifile, section, "ExclusiveMouse", + bbs->exclusive_mouse, &ini_style); iniSetString(inifile, section, "TerminalType", bbs->term_name, &ini_style); iniSetBool(inifile, section, "LFExpand", bbs->lf_expand, diff --git a/src/syncterm/bbslist.h b/src/syncterm/bbslist.h index affadf38..4a18926a 100644 --- a/src/syncterm/bbslist.h +++ b/src/syncterm/bbslist.h @@ -174,6 +174,10 @@ struct bbslist { char wren_scripts[INI_MAX_VALUE_LEN]; bool force_lcf; bool yellow_is_yellow; + /* Capture the pointer to the window and report motion rather than + * position -- what a game needs, and a nuisance for a BBS, so it + * is per entry and off by default. */ + bool exclusive_mouse; /* SSH host-key fingerprint. ssh_fingerprint_len is 0 (no stored approval), 20 (legacy SHA-1 from the Cryptlib era), or 32 (SHA-256). A successful connect against a SHA-1 entry rewrites diff --git a/src/syncterm/scripts/menu_bbs_editor.wren b/src/syncterm/scripts/menu_bbs_editor.wren index 17917399..d80be6c5 100644 --- a/src/syncterm/scripts/menu_bbs_editor.wren +++ b/src/syncterm/scripts/menu_bbs_editor.wren @@ -450,6 +450,7 @@ class BbsEditor { "noStatus": b.noStatus, "hidePopups": b.hidePopups, "yellowIsYellow": b.yellowIsYellow, + "exclusiveMouse": b.exclusiveMouse, "forceLcf": b.forceLcf, "lfExpand": b.lfExpand, "dlDir": b.dlDir, @@ -1259,6 +1260,7 @@ class BbsEditor { rows.add(boolRow_(d, "yellowIsYellow", "Yellow is Yellow")) } rows.add(boolRow_(d, "noStatus", "Hide Status Line")) + rows.add(boolRow_(d, "exclusiveMouse", "Exclusive Mouse")) rows.add(textRow_(app, d, "dlDir", "Download Path", Menu.maxPathLength, false)) rows.add(textRow_(app, d, "ulDir", "Upload Path", @@ -1369,6 +1371,7 @@ class BbsEditor { b.noStatus = d["noStatus"] b.hidePopups = d["hidePopups"] b.yellowIsYellow = d["yellowIsYellow"] + b.exclusiveMouse = d["exclusiveMouse"] b.forceLcf = d["forceLcf"] b.lfExpand = d["lfExpand"] b.dlDir = d["dlDir"] diff --git a/src/syncterm/term.c b/src/syncterm/term.c index 192d77af..7118cddb 100644 --- a/src/syncterm/term.c +++ b/src/syncterm/term.c @@ -5001,6 +5001,13 @@ doterm(struct bbslist *bbs) int ooii_mode = 0; bool ret = false; + + /* Exclusive mouse, if this entry asked for it. The pointer is + * captured to the window and reports motion instead of position -- + * which is what a game needs and what a terminal has never given + * one, and a nuisance everywhere else, so it is per entry. */ + if (bbs != NULL && bbs->exclusive_mouse) + ciolib_set_mouse_exclusive(1); recv_byte_buffer_len = recv_byte_buffer_pos = 0; wire_buffer_len = wire_buffer_pos = 0; recv_replay_buffer_len = recv_replay_buffer_pos = 0; @@ -5553,6 +5560,10 @@ doterm(struct bbslist *bbs) cterm = NULL; ret = false; end: + /* Give the pointer back. Unconditionally: the caller may be leaving + * by any of a dozen paths, and a terminal that keeps the mouse after + * the session has gone is a terminal the user cannot get out of. */ + ciolib_set_mouse_exclusive(0); /* Last chance for scripts to flush per-session state — runs while * the VM is still alive but after every other tear-down step. */ wren_host_dispatch_disconnect(); diff --git a/src/syncterm/wren_bind_menu.c b/src/syncterm/wren_bind_menu.c index 6d208f71..64046825 100644 --- a/src/syncterm/wren_bind_menu.c +++ b/src/syncterm/wren_bind_menu.c @@ -305,6 +305,7 @@ BBS_NUM_PROPERTY(tlsVersionFloor, tls_version_floor, BBS_BOOL_PROPERTY(noStatus, nostatus) BBS_BOOL_PROPERTY(hidePopups, hidepopups) BBS_BOOL_PROPERTY(yellowIsYellow, yellow_is_yellow) +BBS_BOOL_PROPERTY(exclusiveMouse, exclusive_mouse) BBS_BOOL_PROPERTY(forceLcf, force_lcf) BBS_BOOL_PROPERTY(appendLogFile, append_logfile) BBS_BOOL_PROPERTY(telnetNoBinary, telnet_no_binary) @@ -1433,6 +1434,7 @@ static const struct binding bindings[] = { BBS_GETSET(noStatus), BBS_GETSET(hidePopups), BBS_GETSET(yellowIsYellow), + BBS_GETSET(exclusiveMouse), BBS_GETSET(forceLcf), BBS_GETSET(appendLogFile), BBS_GETSET(telnetNoBinary), -- 2.47.3