From ab65e050ae79def1777c16fb4af07d109d873fb2 Mon Sep 17 00:00:00 2001 From: ANSI TV Admin Date: Wed, 11 Nov 2026 12:04:09 -0800 Subject: [PATCH 11/24] SyncTERM: left-drag selects text while the host tracks the mouse Applies after `right-click-paste.patch`. With host mouse reporting on, stock SyncTERM sends every drag to the host, so text selection is gone. Now, in the tracking modes (unless the host hid the pointer with `CSI = 30 h`), a left press is held back: released in the same cell, the host gets press + release as before; moved to another cell, ciolib's drag events are armed for that one press and the next movement starts the normal selection, which the host never sees. Tracking is restored after. Verified under Xvfb: drag copies the line and the host sees no press; a click still arrives as `<0;x;yM` + `m`; a game drag still reaches the host; after a selection, clicks and right-click paste work as before. --- src/syncterm/term.c | 53 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/src/syncterm/term.c b/src/syncterm/term.c index e17b3070..5bde0344 100644 --- a/src/syncterm/term.c +++ b/src/syncterm/term.c @@ -4775,6 +4775,59 @@ handle_mouse_event(struct mouse_state *ms) getmouse(&mevent); if (wren_host_dispatch_mouse(&mevent)) return; + /* A left DRAG selects text even while the host has mouse reporting + * on (and has not hidden our pointer -- a game keeps its drags). + * The press is held back: released in the same cell, the host gets + * press + release exactly as before; moved to another cell with the + * button down, it becomes a text selection the host never sees. + * Moving arms ciolib's drag events for this one press, and the next + * movement arrives as BUTTON_1_DRAG_START, which the switch below + * already hands to mousedrag_terminal(). */ + { + static int sel_pending; /* 0 none, 1 held, 2 armed */ + static struct mouse_event sel_press; + bool tracking = (ms->mode == MM_NORMAL_TRACKING + || ms->mode == MM_BUTTON_EVENT_TRACKING + || ms->mode == MM_ANY_EVENT_TRACKING) + && !(cterm != NULL && cterm->pointer_hidden); + + if (!tracking) + sel_pending = 0; + else if (mevent.event == CIOLIB_BUTTON_1_PRESS + && !(mevent.kbmodifiers & CIOLIB_KMOD_CTRL)) { + sel_press = mevent; + sel_pending = 1; + return; + } + else if (sel_pending && mevent.event == CIOLIB_MOUSE_MOVE) { + if (sel_pending == 1 && (mevent.endx != sel_press.endx + || mevent.endy != sel_press.endy)) { + ciomouse_addevent(CIOLIB_BUTTON_1_DRAG_START); + ciomouse_addevent(CIOLIB_BUTTON_1_DRAG_MOVE); + ciomouse_addevent(CIOLIB_BUTTON_1_DRAG_END); + sel_pending = 2; + } + return; /* no motion reports mid-press */ + } + else if (sel_pending && mevent.event == CIOLIB_BUTTON_1_RELEASE) { + if (sel_pending == 1) { + conn_send(mouse_buf, fill_mevent(mouse_buf, + sizeof(mouse_buf), &sel_press, ms), 0); + conn_send(mouse_buf, fill_mevent(mouse_buf, + sizeof(mouse_buf), &mevent, ms), 0); + } + else + setup_mouse_events(ms); + sel_pending = 0; + return; + } + else if (sel_pending && mevent.event == CIOLIB_BUTTON_1_DRAG_START) { + sel_pending = 0; + mousedrag_terminal(false); + setup_mouse_events(ms); + return; + } + } /* Right-click pastes from the OS clipboard even while the host has * mouse reporting on -- a board that tracks the mouse for its menus * would otherwise take the right button and paste would be gone. -- 2.47.3