From 8cc704b897f33d6150156c77202a29222b9ee667 Mon Sep 17 00:00:00 2001 From: Robin Haberkorn Date: Sun, 13 Apr 2025 04:37:57 +0300 Subject: PDCurses/Win: more or less fixed mouse support * Both the WinGUI and Wincon variants have their own idiosyncrasies: * WinGUI ignores `mouseinterval(0)` and may report BUTTONX_CLICKED for very quick clicks. Therefore we now emulate separate PRESSED/RELEASED events. * Wincon does not report BUTTONX_RELEASED at all. Therefore we still enable click detection, so that fnkeys.tes will work at least partially. Therefore we also enable REPORT_MOUSE_POSITION, so that right-click-dragging will work. This should still be fixed in PDCurses upstream, though. * See also https://github.com/Bill-Gray/PDCursesMod/issues/330 --- src/interface-curses/interface.c | 43 ++++++++++++++++++++++++++++++++++------ 1 file changed, 37 insertions(+), 6 deletions(-) diff --git a/src/interface-curses/interface.c b/src/interface-curses/interface.c index 031ba61..95fe8b8 100644 --- a/src/interface-curses/interface.c +++ b/src/interface-curses/interface.c @@ -716,8 +716,12 @@ teco_interface_init_interactive(GError **error) * Disables click-detection. * If we'd want to discern PRESSED and CLICKED events, * we'd have to emulate the same feature on GTK. + * + * On PDCurses/Wincon we currently rely on click detection + * since it does not report BUTTONX_RELEASED unless also + * moving the mouse cursor. */ -#if NCURSES_MOUSE_VERSION >= 2 +#if NCURSES_MOUSE_VERSION >= 2 && !defined(PDCURSES_WINCON) mouseinterval(0); #endif @@ -1822,8 +1826,9 @@ teco_interface_getmouse(GError **error) * NOTE: Not all curses variants report the RELEASED event, * but may also return REPORT_MOUSE_POSITION. * So we might react to all button presses as well. + * Others will still report CLICKED. */ - if (event.bstate & (BUTTON1_RELEASED | REPORT_MOUSE_POSITION)) { + if (event.bstate & (BUTTON1_RELEASED | BUTTON1_CLICKED | REPORT_MOUSE_POSITION)) { teco_machine_t *machine = &teco_cmdline.machine.parent; const teco_string_t *insert = teco_curses_info_popup_getentry(&teco_interface.popup, event.y, event.x); @@ -1906,6 +1911,22 @@ teco_interface_getmouse(GError **error) if (event.bstate & BUTTON_ALT) teco_mouse.mods |= TECO_MOUSE_ALT; + if (event.bstate & BUTTON_EVENT(CLICKED)) { + /* + * Click detection __should__ be disabled, + * but some Curses implementations report them anyway. + * This has been observed on PDCurses/WinGUI. + * On PDCurses/Wincon we especially did not disable + * click detection since it doesn't report + * BUTTONX_RELEASED at all. + * We emulate separate PRESSED/RELEASE events on those + * platforms. + */ + teco_mouse.type = TECO_MOUSE_PRESSED; + if (!teco_cmdline_keymacro("MOUSE", -1, error)) + return FALSE; + teco_mouse.type = TECO_MOUSE_RELEASED; + } return teco_cmdline_keymacro("MOUSE", -1, error); } @@ -1915,15 +1936,25 @@ static gint teco_interface_blocking_getch(void) { #if NCURSES_MOUSE_VERSION >= 2 +#if defined(NCURSES_VERSION) || defined(PDCURSES_WINCON) /* - * FIXME: REPORT_MOUSE_POSITION is necessary at least on + * REPORT_MOUSE_POSITION is necessary at least on * ncurses, so that BUTTONX_RELEASED events are reported. + * At least we interpret REPORT_MOUSE_POSITION + * like BUTTONX_RELEASED. * It does NOT report every cursor movement, though. - * What does PDCurses do? + * + * FIXME: On PDCurses/Wincon we enable it, so we at least + * receive something that will be interpreted as + * BUTTONX_RELEASED, although it really just reports + * cursor movements. */ - mousemask(teco_ed & TECO_ED_MOUSEKEY - ? ALL_MOUSE_EVENTS | REPORT_MOUSE_POSITION : 0, NULL); + static const mmask_t mmask = ALL_MOUSE_EVENTS | REPORT_MOUSE_POSITION; +#else + static const mmask_t mmask = ALL_MOUSE_EVENTS; #endif + mousemask(teco_ed & TECO_ED_MOUSEKEY ? mmask : 0, NULL); +#endif /* NCURSES_MOUSE_VERSION >= 2 */ /* no special handling */ raw(); -- cgit v1.2.3