/****************************************************************************
- * Copyright 2018-2019,2020 Thomas E. Dickey *
+ * Copyright 2018-2023,2024 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.187 2020/05/09 23:24:03 tom Exp $")
+MODULE_ID("$Id: lib_mouse.c,v 1.200 2024/02/17 21:13:01 tom Exp $")
#include <tic.h>
}
#endif /* USE_SYSMOUSE */
-#ifndef USE_TERM_DRIVER
+#if !defined(USE_TERM_DRIVER) || defined(EXP_WIN32_DRIVER)
#define xterm_kmous "\033[M"
static void
} 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
static void
enable_xterm_mouse(SCREEN *sp, int enable)
{
+ TPUTS_TRACE(enable
+ ? "xterm mouse initialization"
+ : "xterm mouse deinitialization");
#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;
}
+#if defined(USE_TERM_DRIVER)
+static void
+enable_win32_mouse(SCREEN *sp, int enable)
+{
+#if defined(EXP_WIN32_DRIVER)
+ enable_xterm_mouse(sp, enable);
+#else
+ sp->_mouse_active = enable;
+#endif
+}
+#endif
+
#if USE_GPM_SUPPORT
static bool
allow_gpm_mouse(SCREEN *sp GCC_UNUSED)
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)
#ifdef USE_TERM_DRIVER
CallDriver(sp, td_initmouse);
-#else
+#endif
+#if !defined(USE_TERM_DRIVER) || defined(EXP_WIN32_DRIVER)
/* we know how to recognize mouse events under "xterm" */
if (NonEmpty(key_mouse)) {
init_xterm_mouse(sp);
{
bool result = FALSE;
+ T((T_CALLED("_nc_mouse_init(%p)"), (void *) sp));
+
if (sp != 0) {
if (!sp->_mouse_initialized) {
int i;
sp->_mouse_initialized = TRUE;
- TR(MY_TRACE, ("_nc_mouse_init() called"));
+ TR(MY_TRACE, ("set _mouse_initialized"));
sp->_mouse_eventp = FirstEV(sp);
for (i = 0; i < EV_MAX; i++)
initialize_mousetype(sp);
- T(("_nc_mouse_init() set mousetype to %d", sp->_mouse_type));
+ T(("set _mouse_type to %d", sp->_mouse_type));
}
result = sp->_mouse_initialized;
}
- return result;
+ returnCode(result);
}
/*
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 = (int) (intro - 152); /* buttons 8-11 */
- } else if (intro >= 96) {
+ } else {
button = (int) (intro - 92); /* buttons 4-7 */
}
} else {
int res;
bool result;
-# if USE_PTHREADS_EINTR
-# if USE_WEAK_SYMBOLS
- if ((pthread_self) && (pthread_kill) && (pthread_equal))
-# endif
- _nc_globals.read_thread = pthread_self();
-# endif
+ _nc_set_read_thread(TRUE);
for (grabbed = 0; grabbed < MAX_KBUF; grabbed += (size_t) res) {
/* For VIO mouse we add extra bit 64 to disambiguate button-up. */
if (res == -1)
break;
}
-#if USE_PTHREADS_EINTR
- _nc_globals.read_thread = 0;
-#endif
+ _nc_set_read_thread(FALSE);
kbuf[MAX_KBUF] = '\0';
TR(TRACE_IEVENT,
coords[0] = 0;
coords[1] = 0;
-# if USE_PTHREADS_EINTR
-# if USE_WEAK_SYMBOLS
- if ((pthread_self) && (pthread_kill) && (pthread_equal))
-# endif
- _nc_globals.read_thread = pthread_self();
-# endif
+ _nc_set_read_thread(TRUE);
for (grabbed = 0; grabbed < limit;) {
int res;
break;
}
}
-#if USE_PTHREADS_EINTR
- _nc_globals.read_thread = 0;
-#endif
+ _nc_set_read_thread(FALSE);
TR(TRACE_IEVENT,
("_nc_mouse_inline sees the following xterm data: %s",
int marker = 1;
memset(result, 0, sizeof(*result));
-# if USE_PTHREADS_EINTR
-# if USE_WEAK_SYMBOLS
- if ((pthread_self) && (pthread_kill) && (pthread_equal))
-# endif
- _nc_globals.read_thread = pthread_self();
-# endif
+ _nc_set_read_thread(TRUE);
do {
int res;
}
++grabbed;
} while (!isFinal(ch));
-#if USE_PTHREADS_EINTR
- _nc_globals.read_thread = 0;
-#endif
+ _nc_set_read_thread(FALSE);
kbuf[++grabbed] = 0;
TR(TRACE_IEVENT,
static void
mouse_activate(SCREEN *sp, int on)
{
+ T((T_CALLED("mouse_activate(%p,%s)"),
+ (void *) SP_PARM, on ? "on" : "off"));
+
if (!on && !sp->_mouse_initialized)
- return;
+ returnVoid;
if (!_nc_mouse_init(sp))
- return;
+ returnVoid;
if (on) {
sp->_mouse_bstate = 0;
#if NCURSES_EXT_FUNCS
NCURSES_SP_NAME(keyok) (NCURSES_SP_ARGx KEY_MOUSE, on);
#endif
- TPUTS_TRACE("xterm mouse initialization");
enable_xterm_mouse(sp, 1);
break;
#if USE_GPM_SUPPORT
#endif
#ifdef USE_TERM_DRIVER
case M_TERM_DRIVER:
- sp->_mouse_active = TRUE;
+ enable_win32_mouse(sp, TRUE);
break;
#endif
case M_NONE:
- return;
+ returnVoid;
+ default:
+ T(("unexpected mouse mode"));
+ break;
}
/* Make runtime binding to cut down on object size of applications that
* do not use the mouse (e.g., 'clear').
*/
- sp->_mouse_event = _nc_mouse_event;
+ /* *INDENT-EQLS* */
+ sp->_mouse_event = _nc_mouse_event;
sp->_mouse_inline = _nc_mouse_inline;
- sp->_mouse_parse = _nc_mouse_parse;
+ sp->_mouse_parse = _nc_mouse_parse;
sp->_mouse_resume = _nc_mouse_resume;
- sp->_mouse_wrap = _nc_mouse_wrap;
+ sp->_mouse_wrap = _nc_mouse_wrap;
} else {
switch (sp->_mouse_type) {
case M_XTERM:
- TPUTS_TRACE("xterm mouse deinitialization");
enable_xterm_mouse(sp, 0);
break;
#if USE_GPM_SUPPORT
#endif
#ifdef USE_TERM_DRIVER
case M_TERM_DRIVER:
- sp->_mouse_active = FALSE;
+ enable_win32_mouse(sp, FALSE);
break;
#endif
case M_NONE:
- return;
+ returnVoid;
+ default:
+ T(("unexpected mouse mode"));
+ break;
}
}
NCURSES_SP_NAME(_nc_flush) (NCURSES_SP_ARG);
+ returnVoid;
}
/**************************************************************************
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
if (win != 0) {
y -= win->_yoffset;
- result = ((win->_begy <= y &&
- win->_begx <= x &&
- (win->_begx + win->_maxx) >= x &&
- (win->_begy + win->_maxy) >= y) ? TRUE : FALSE);
+ if (IS_PAD(win)) {
+ if (win->_pad._pad_y >= 0 &&
+ win->_pad._pad_x >= 0 &&
+ win->_pad._pad_top >= 0 &&
+ win->_pad._pad_left >= 0 &&
+ win->_pad._pad_right >= 0 &&
+ win->_pad._pad_bottom >= 0) {
+ result = ((win->_pad._pad_top <= y &&
+ win->_pad._pad_left <= x &&
+ win->_pad._pad_right >= x &&
+ win->_pad._pad_bottom >= y) ? TRUE : FALSE);
+ }
+ } else {
+ result = ((win->_begy <= y &&
+ win->_begx <= x &&
+ (win->_begx + win->_maxx) >= x &&
+ (win->_begy + win->_maxy) >= y) ? TRUE : FALSE);
+ }
}
returnBool(result);
}
int y = *pY;
int x = *pX;
+ T(("transform input %d,%d", y, x));
if (to_screen) {
y += win->_begy + win->_yoffset;
x += win->_begx;
if (result) {
*pX = x;
*pY = y;
+ T(("output transform %d,%d", y, x));
}
}
returnBool(result);