Feature or enhancement
The curses module exposes most of the X/Open mouse interface (getmouse, ungetmouse, mousemask, mouseinterval, and window.enclose), but two functions are missing.
has_mouse() returns whether the mouse driver has been successfully initialized. It complements mousemask()/getmouse() and fits the existing has_colors/has_ic/has_il/has_key family.
wmouse_trafo() transforms a coordinate pair between window-relative and stdscr-relative space (the two differ when lines are reserved on the screen via ripoffline() or slk_init()). It is the companion of window.enclose() for interpreting mouse-event coordinates.
Proposed API:
curses.has_mouse() -> bool
window.mouse_trafo(y, x, to_screen) -> (y, x) or None
to_screen=True converts window-relative coordinates to stdscr-relative, False does the reverse. The method returns the converted coordinates, or None when the point lies outside the window (the failure case of wmouse_trafo()).
A module-level mouse_trafo() is not needed: in ncurses it is just wmouse_trafo(stdscr, ...), so stdscr.mouse_trafo(...) already covers it, consistent with window.enclose() (there is no module-level enclose() either).
Both are guarded by NCURSES_MOUSE_VERSION, like window.enclose().
Feature or enhancement
The
cursesmodule exposes most of the X/Open mouse interface (getmouse,ungetmouse,mousemask,mouseinterval, andwindow.enclose), but two functions are missing.has_mouse()returns whether the mouse driver has been successfully initialized. It complementsmousemask()/getmouse()and fits the existinghas_colors/has_ic/has_il/has_keyfamily.wmouse_trafo()transforms a coordinate pair between window-relative and stdscr-relative space (the two differ when lines are reserved on the screen viaripoffline()orslk_init()). It is the companion ofwindow.enclose()for interpreting mouse-event coordinates.Proposed API:
curses.has_mouse()->boolwindow.mouse_trafo(y, x, to_screen)->(y, x)orNoneto_screen=Trueconverts window-relative coordinates to stdscr-relative,Falsedoes the reverse. The method returns the converted coordinates, orNonewhen the point lies outside the window (the failure case ofwmouse_trafo()).A module-level
mouse_trafo()is not needed: in ncurses it is justwmouse_trafo(stdscr, ...), sostdscr.mouse_trafo(...)already covers it, consistent withwindow.enclose()(there is no module-levelenclose()either).Both are guarded by
NCURSES_MOUSE_VERSION, likewindow.enclose().