[3.14] gh-152502: Detect the curses mouse interface portably (GH-152705) by serhiy-storchaka · Pull Request #152734 · python/cpython · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Include/py_curses.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Detect the :mod:`curses` mouse interface (:func:`~curses.getmouse`, the
``BUTTON*`` constants, and others) with a configure capability probe or library
macros instead of gating it on ncurses-specific macros. It is now also
available with other curses implementations that provide it, such as NetBSD
curses and PDCurses (the latter underpins ``windows-curses``).
10 changes: 5 additions & 5 deletions Modules/_cursesmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -1502,7 +1502,7 @@ _curses_window_echochar_impl(PyCursesWindowObject *self, PyObject *ch,
"echochar");
}

#ifdef NCURSES_MOUSE_VERSION
#if defined(HAVE_CURSES_GETMOUSE) || defined(PDCURSES)
/*[clinic input]
_curses.window.enclose

Expand Down Expand Up @@ -3244,7 +3244,7 @@ _curses_getsyx_impl(PyObject *module)
}
#endif

#ifdef NCURSES_MOUSE_VERSION
#if defined(HAVE_CURSES_GETMOUSE) || defined(PDCURSES)
/*[clinic input]
_curses.getmouse

Expand Down Expand Up @@ -3961,7 +3961,7 @@ _curses_meta_impl(PyObject *module, int yes)
return PyCursesCheckERR(module, meta(stdscr, yes), "meta");
}

#ifdef NCURSES_MOUSE_VERSION
#if defined(HAVE_CURSES_GETMOUSE) || defined(PDCURSES)
/*[clinic input]
_curses.mouseinterval

Expand Down Expand Up @@ -5385,7 +5385,7 @@ cursesmodule_exec(PyObject *module)
SetDictInt("COLOR_CYAN", COLOR_CYAN);
SetDictInt("COLOR_WHITE", COLOR_WHITE);

#ifdef NCURSES_MOUSE_VERSION
#if defined(HAVE_CURSES_GETMOUSE) || defined(PDCURSES)
/* Mouse-related constants */
SetDictInt("BUTTON1_PRESSED", BUTTON1_PRESSED);
SetDictInt("BUTTON1_RELEASED", BUTTON1_RELEASED);
Expand All @@ -5411,7 +5411,7 @@ cursesmodule_exec(PyObject *module)
SetDictInt("BUTTON4_DOUBLE_CLICKED", BUTTON4_DOUBLE_CLICKED);
SetDictInt("BUTTON4_TRIPLE_CLICKED", BUTTON4_TRIPLE_CLICKED);

#if NCURSES_MOUSE_VERSION > 1
#ifdef BUTTON5_PRESSED
SetDictInt("BUTTON5_PRESSED", BUTTON5_PRESSED);
SetDictInt("BUTTON5_RELEASED", BUTTON5_RELEASED);
SetDictInt("BUTTON5_CLICKED", BUTTON5_CLICKED);
Expand Down
22 changes: 11 additions & 11 deletions Modules/clinic/_cursesmodule.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

51 changes: 51 additions & 0 deletions configure

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -7086,6 +7086,18 @@ PY_CHECK_CURSES_FUNC([set_escdelay])
PY_CHECK_CURSES_FUNC([set_tabsize])
PY_CHECK_CURSES_VAR([ESCDELAY])
PY_CHECK_CURSES_VAR([TABSIZE])

dnl Probe for the X/Open getmouse(MEVENT *) signature specifically: PDCurses
dnl declares an incompatible getmouse(void) unless built for the ncurses mouse API.
AC_CACHE_CHECK([for ncurses-style curses function getmouse],
[ac_cv_lib_curses_getmouse],
[AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM(_CURSES_INCLUDES, [MEVENT event; (void)getmouse(&event);])],
[ac_cv_lib_curses_getmouse=yes],
[ac_cv_lib_curses_getmouse=no])])
AS_VAR_IF([ac_cv_lib_curses_getmouse], [yes],
[AC_DEFINE([HAVE_CURSES_GETMOUSE], [1],
[Define if you have the 'getmouse' function with the X/Open signature.])])
CPPFLAGS=$ac_save_cppflags
])dnl have_curses != no
])dnl save env
Expand Down
3 changes: 3 additions & 0 deletions pyconfig.h.in
Loading