Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add curses.has_mouse() and curses.window.mouse_trafo() #152325

Description

@serhiy-storchaka

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().

Linked PRs

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    extension-modulesC modules in the Modules dirtype-featureA feature request or enhancement

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions