Subject: bug#51590: follow-mode is broken with header-line and tab-line

From: martin rudalics <[email-masked]>
Date: Mon, 8 Nov 2021 18:32:20 +0100

> (posn-area (posn-at-x-y (1- (window-pixel-width)) 0))
 >
 > currently gives 'nil' regardless of whether it's done with a header or
 > tab line and
 >
 > (posn-area (posn-at-x-y
 >          (1- (window-pixel-width))
 >          (1- (window-pixel-height))))
 >
 > gives 'nil' on the mode line.  Only when I remove _both_ fringes and the
 > vertical scroll bar I get the expected results.  This _is_ a bug and we
 > should fix it.

I think the attached patch should fix that modulo some ">=" and "<"
glitches.

martin
diff --git a/src/keyboard.c b/src/keyboard.c
index a99d14cb4c..d24a0ffe07 100644
--- a/src/keyboard.c
+++ b/src/keyboard.c
@@ -11374,7 +11374,9 @@ DEFUN ("posn-at-x-y", Fposn_at_x_y, Sposn_at_x_y, 2, 4, 0,

       XSETINT (x, (XFIXNUM (x)
 		   + WINDOW_LEFT_EDGE_X (w)
-		   + (NILP (whole)
+		   + ((NILP (whole)
+		       && XFIXNUM (y) >= WINDOW_BOX_TOP_PIXEL_EDGE (w)
+		       && XFIXNUM (y) < WINDOW_BOX_HEIGHT_NO_MODE_LINE (w))
 		      ? window_box_left_offset (w, TEXT_AREA)
 		      : 0)));
       XSETINT (y, WINDOW_TO_FRAME_PIXEL_Y (w, XFIXNUM (y)));
diff --git a/src/window.h b/src/window.h
index 2400c422c1..6420706b5f 100644
--- a/src/window.h
+++ b/src/window.h
@@ -800,6 +800,12 @@ #define WINDOW_BOX_RIGHT_PIXEL_EDGE(W)		\
    - WINDOW_RIGHT_DIVIDER_WIDTH (W)		\
    - WINDOW_RIGHT_SCROLL_BAR_AREA_WIDTH (W))

+/* Return the pixel value where the text in window W starts.  */
+#define WINDOW_BOX_TOP_PIXEL_EDGE(W)		\
+  (WINDOW_TOP_PIXEL_EDGE (W)			\
+   + WINDOW_HEADER_LINE_HEIGHT (W)		\
+   + WINDOW_TAB_LINE_HEIGHT (W))
+
 /* Return the frame x-position at which the text (or left fringe) in
    window W starts.  This does not include a left-hand scroll bar if
    any.  */