diff --git a/doc/lispref/windows.texi b/doc/lispref/windows.texi index 09d58c17c01..786308dc310 100644 --- a/doc/lispref/windows.texi +++ b/doc/lispref/windows.texi @@ -5927,6 +5927,40 @@ This function returns the cursor type of @var{window}, defaulting to the selected window. @end defun +@defun window-cursor-info &optional window +This function returns information about the cursor of @var{window}, +defaulting to the selected window. + +The value returned by the function is a vector of the form +@w{@code{[@var{type} @var{x} @var{y} @var{width} @var{height} +@var{ascent}]}}. Here's the description of each components of this +vector: + +@table @var +@item type +The type of the cursor, a symbol. This is the same value returned by +@code{window-cursor-type}. + +@item x +@itemx y +The pixel coordinates of the cursor's top-left corner, relative to the +top-left corner of @var{window}'s text area. + +@item width +@itemx height +The pixel dimensions of the cursor. + +@item ascent +The number of pixels the cursor extends above the baseline. +@end table + +If the cursor is not currently displayed for @var{window}, this function +returns @code{nil}. + +Any element except the first one in the returned vector may be +@code{-1}, meaning the actual value is currently unavailable. +@end defun + @node Window Start and End @section The Window Start and End Positions @cindex window start position diff --git a/etc/NEWS b/etc/NEWS index 321ce929cb0..1844eeb7bf5 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -440,6 +440,12 @@ adjacent windows and subsequently operate on that parent. 'uncombine-window' can then be used to restore the window configuration to the state it had before running 'combine-windows'. ++++ +*** New function 'window-cursor-info'. +This function returns a vector of pixel-level information about the +physical cursor in a given window, including its type, coordinates, +dimensions, and ascent. + ** Frames +++ diff --git a/src/window.c b/src/window.c index af8c8dd33d2..dc5444255e6 100644 --- a/src/window.c +++ b/src/window.c @@ -8646,6 +8646,41 @@ WINDOW must be a live window and defaults to the selected one. */) return decode_live_window (window)->cursor_type; } +DEFUN ("window-cursor-info", Fwindow_cursor_info, Swindow_cursor_info, + 0, 1, 0, + doc: /* Return information about the cursor of WINDOW. +WINDOW must be a live window and defaults to the selected one. + +The returned value is a vector of 6 elements: + [TYPE X Y WIDTH HEIGHT ASCENT] +where + TYPE is the symbol representing the type of the cursor. See + `cursor-type' for the meaning of the returned value. + X and Y are pixel coordinates of the cursor's top-left corner, relative + to the top-left corner of WINDOW's text area. + WIDTH and HEIGHT are the pixel dimensions of the cursor. + ASCENT is the number of pixels the cursor extends above the baseline. + +If the cursor is not currently displayed for WINDOW, return nil. + +Note that any element except the first one in the returned vector may be +-1 if the actual value is currently unavailable. */) + (Lisp_Object window) +{ + struct window *w = decode_live_window (window); + + if (!w->phys_cursor_on_p) + return Qnil; + + return CALLN (Fvector, + w->cursor_type, + make_fixnum (w->phys_cursor.x), + make_fixnum (w->phys_cursor.y), + make_fixnum (w->phys_cursor_width), + make_fixnum (w->phys_cursor_height), + make_fixnum (w->phys_cursor_ascent)); +} + /*********************************************************************** Scroll bars @@ -9617,5 +9652,6 @@ name to `'ignore'. */); defsubr (&Sset_window_parameter); defsubr (&Swindow_discard_buffer); defsubr (&Swindow_cursor_type); + defsubr (&Swindow_cursor_info); defsubr (&Sset_window_cursor_type); }