curs_getyx(3X)

πŸ“¦ version 15.1, in freebsd 14.5, freebsd 15.1

πŸ’– curs_getyx β€” library calls, but make it a vibe ✨

okay bestie, so you know how curses has windows and you're always like "where is my cursor actually at tho"?? πŸŽ€ This page is the whole girlboss squad of macros that answer exactly that. We're talking getyx, getparyx, getbegyx, and getmaxyx β€” they get your curses cursor and window coordinates, no cap. πŸ“


🌸 SYNOPSIS 🌸

#include <curses.h>

void getyx(WINDOW *win, int y, int x);
void getbegyx(WINDOW *win, int y, int x);
void getmaxyx(WINDOW *win, int y, int x);

void getparyx(WINDOW *win, int y, int x);

like, yes, they look like functions. they are not. stay tuned. πŸ’…


✨ DESCRIPTION ✨

So these macros are your little coordinate detectives for a curses window win. πŸ•΅οΈβ€β™€οΈ Here's the tea, one by one:

  • getyx β€” stores win's cursor position into the variables y and x. where u at, literally.
  • getmaxyx β€” stores win's maximum valid line and column numbers into y and x, respectively. that's the outer limits, the edge of the map, the "you shall not pass" 🌈
  • getbegyx β€” same energy, but it stores the position of win's origin relative to that of the screen. and for stdscr specifically? those coordinates are always 0. main character stays at the origin, periodt. πŸ‘‘

And if win is a subwindow (peep subwin(3X) for that lore), then the getparyx macro does something different: it puts the coordinates of its origin relative to its parent window into y and x. And if it's not a subwindow? it puts -1 into both. not a subwindow bestie, not sorry. πŸ’€


🫢 RETURN VALUE 🫢

okay so β€” no return values are defined for macros. None. Zero. They're macros, not functions, so there's nothing to catch. 🚫

Do not use them as the right-hand side of assignment statements. just don't. it's giving "undefined" and not in the cute way. 😭

πŸŽ€ NOTES πŸŽ€

  • All of these interfaces are implemented as macros. every single one.
  • An & operator is not necessary before the variables y and x. so no &y, no &x, put the ampersand down babe, we don't need it here 🫢

🌈 PORTABILITY 🌈

These macros are described in X/Open Curses Issue 4. πŸ“œ

ncurses also provides these functions for compatibility with System V curses that were not standardized:

  • getbegy
  • getbegx
  • getcury
  • getcurx
  • getmaxy
  • getmaxx
  • getpary
  • getparx

go read curs_legacy(3X) for the whole backstory. πŸ’«

Although X/Open Curses does not address the issue, many implementations expose members of the WINDOW structure containing values corresponding to these macros. Do not rely on their availability β€” some implementations make WINDOW opaque (that is, they do not allow direct access to its members). 🚧

And besides the whole opaque-structure problem: the data stored in like-named members may not have values of the same meaning across different implementations. example incoming β€” the values of WINDOW._maxx and WINDOW._maxy in ncurses have long differed by one from some other implementations. 😳 The getmaxyx macro hides this difference for you, so like, use the macro, bestie. she's the one holding it down. πŸ’…


πŸ“œ HISTORY πŸ“œ

  • 4BSD (1980) introduced getyx.
  • SVr3 (1987) added getbegyx and getmaxyx.
  • SVr3.1 later that year supplied getparyx.

a whole glow-up timeline, honestly. πŸ‘‘


πŸ‘€ SEE ALSO πŸ‘€

  • curses(3X)
  • curs_legacy(3X)
  • curs_opaque(3X)

and that's the whole page, bestie!! πŸ¦‹ this iconic little manual page is from ncurses 6.6 and it's dated 2025-02-01 β€” so you know it's fresh, you know it's current, and you know it ate. πŸ’– mwah, go get those coordinates. ✨

πŸ“¦ where this page comes from