/****************************************************************************
- * Copyright 2018-2019,2020 Thomas E. Dickey *
+ * Copyright 2018-2021,2022 Thomas E. Dickey *
* Copyright 1998-2016,2017 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
#define CUR SP_TERMTYPE
#endif
-MODULE_ID("$Id: lib_mouse.c,v 1.186 2020/05/02 21:13:04 tom Exp $")
+MODULE_ID("$Id: lib_mouse.c,v 1.196 2022/04/30 23:21:34 tom Exp $")
#include <tic.h>
} else {
int code = tigetnum("XM");
switch (code) {
+#ifdef EXP_XTERM_1005
+ case 1005:
+ /* see "xterm+sm+1005" */
+ sp->_mouse_xtermcap = "\033[?1005;1000%?%p1%{1}%=%th%el%;";
+ sp->_mouse_format = MF_XTERM_1005;
+ break;
+#endif
case 1006:
+ /* see "xterm+sm+1006" */
+ sp->_mouse_xtermcap = "\033[?1006;1000%?%p1%{1}%=%th%el%;";
+ sp->_mouse_format = MF_SGR1006;
break;
default:
- code = 1000;
+ sp->_mouse_xtermcap = "\033[?1000%?%p1%{1}%=%th%el%;";
break;
}
- sp->_mouse_xtermcap = "\033[?1000%?%p1%{1}%=%th%el%;";
}
}
#endif
#if USE_EMX_MOUSE
sp->_emxmouse_activated = enable;
#else
- NCURSES_PUTP2("xterm-mouse", TPARM_1(sp->_mouse_xtermcap, enable));
+ NCURSES_PUTP2("xterm-mouse", TIPARM_1(sp->_mouse_xtermcap, enable));
#endif
sp->_mouse_active = enable;
}
T(("unload GPM library"));
sp->_mouse_gpm_loaded = FALSE;
sp->_mouse_fd = -1;
- dlclose(sp->_dlopen_gpm);
- sp->_dlopen_gpm = 0;
}
}
load_gpm_library(SCREEN *sp)
{
sp->_mouse_gpm_found = FALSE;
- if ((sp->_dlopen_gpm = dlopen(LIBGPM_SONAME, my_RTLD)) != 0) {
+
+ /*
+ * If we already had a successful dlopen, reuse it.
+ */
+ if (sp->_dlopen_gpm != 0) {
+ sp->_mouse_gpm_found = TRUE;
+ sp->_mouse_gpm_loaded = TRUE;
+ } else if ((sp->_dlopen_gpm = dlopen(LIBGPM_SONAME, my_RTLD)) != 0) {
#if (defined(__GNUC__) && (__GNUC__ >= 5)) || defined(__clang__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wpedantic"
#endif
T(("GPM initialization failed: %s", dlerror()));
unload_gpm_library(sp);
+ dlclose(sp->_dlopen_gpm);
+ sp->_dlopen_gpm = 0;
} else {
sp->_mouse_gpm_found = TRUE;
sp->_mouse_gpm_loaded = TRUE;
}
}
}
-#endif
+#endif /* HAVE_LIBDL */
static bool
enable_gpm_mouse(SCREEN *sp, bool enable)
PRESS_POSITION(3);
break;
default:
+ /*
+ * case 3 is sent when the mouse buttons are released.
+ *
+ * If the terminal uses xterm mode 1003, a continuous series of
+ * button-release events is sent as the mouse moves around the screen,
+ * or as the wheel mouse is rotated.
+ *
+ * Return false in this case, so that when running in X10 mode, we will
+ * recalculate bstate.
+ */
+ eventp->bstate = REPORT_MOUSE_POSITION;
result = FALSE;
break;
}
decode_X10_bstate(SCREEN *sp, MEVENT * eventp, unsigned intro)
{
bool result;
- int button;
+ int button = 0;
int wheel = (intro & 96) == 96;
eventp->bstate = 0;
if (intro >= 96) {
if (intro >= 160) {
- button = (intro - 152); /* buttons 8-11 */
- } else if (intro >= 96) {
- button = (intro - 92); /* buttons 4-7 */
+ button = (int) (intro - 152); /* buttons 8-11 */
+ } else {
+ button = (int) (intro - 92); /* buttons 4-7 */
}
} else {
button = (intro & 3);
if (changed) {
merge = FALSE;
for (b = 1; b <= MAX_BUTTONS; ++b) {
- if ((sp->_mouse_mask & MASK_CLICK(b))
+ if ((sp->_mouse_mask2 & MASK_CLICK(b))
&& (ep->bstate & MASK_PRESS(b))) {
next->bstate &= ~MASK_RELEASE(b);
next->bstate |= MASK_CLICK(b);
&& (next->bstate & BUTTON_CLICKED)) {
merge = FALSE;
for (b = 1; b <= MAX_BUTTONS; ++b) {
- if ((sp->_mouse_mask & MASK_DOUBLE_CLICK(b))
+ if ((sp->_mouse_mask2 & MASK_DOUBLE_CLICK(b))
&& (ep->bstate & MASK_CLICK(b))
&& (next->bstate & MASK_CLICK(b))) {
next->bstate &= ~MASK_CLICK(b);
&& (next->bstate & BUTTON_CLICKED)) {
merge = FALSE;
for (b = 1; b <= MAX_BUTTONS; ++b) {
- if ((sp->_mouse_mask & MASK_TRIPLE_CLICK(b))
+ if ((sp->_mouse_mask2 & MASK_TRIPLE_CLICK(b))
&& (ep->bstate & MASK_DOUBLE_CLICK(b))
&& (next->bstate & MASK_CLICK(b))) {
next->bstate &= ~MASK_CLICK(b);
#endif /* TRACE */
/* after all this, do we have a valid event? */
- return ValidEvent(PREV(first_invalid));
+ ep = PREV(first_invalid);
+ return ValidEvent(ep) && ((ep->bstate & sp->_mouse_mask) != 0);
}
static void