Subject: Re: bug#76321: 31.0.50; Moving nested child frames out of their child parents

From: Gerd Möllmann <[email-masked]>
Date: Mon, 17 Feb 2025 10:52:22 +0100

martin rudalics <[email-masked]> writes:

>> Thanks. This frame parameter stuff is sooo over-engineered :-/.
>
> Don't ask me how much time I spent on it.  The most important thing
> would be to make values more characteristic - instead of 40 use 39 ...
>
>> Does it work with your changes, or is it still crashing?
>
> I found the crash when I tried to drag a child frame's child with the
> mouse.  So yes, it's crashing with my changes.
>
> martin

I've found the reason, please see the attached patch. If it works for
you, I'll put in master.

With your latest diff, and nothing additional on top of it, and with

(defun tty-3 ()
  (interactive)
  (setq tty-3
	(make-frame
	 `((parent-frame . ,tty-2)
	   (left . (- 10)) (top . 5)
                   ^^^^^^^

the placement of tty-3 seems wrong. Just saying, I think you mentioned
that you fixed that already.

>From 088582524380c626310b0ab0bbd15ff17607b00e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Gerd=20M=C3=B6llmann?= <gerd,[email-masked]>
Date: Mon, 17 Feb 2025 10:42:02 +0100
Subject: [PATCH] Fix child coordinate calculation (bug#76321)

* src/dispnew.c (rect_intersect): Simplify.
(copy_child_glyphs): Compute child coordinates using child_xy.
---
 src/dispnew.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/src/dispnew.c b/src/dispnew.c
index a952f7623c0..bb480f88537 100644
--- a/src/dispnew.c
+++ b/src/dispnew.c
@@ -3288,15 +3288,15 @@ DEFUN ("redraw-display", Fredraw_display, Sredraw_display, 0, 0, "",
 static bool
 rect_intersect (struct rect *r, struct rect r1, struct rect r2)
 {
-  int x1 = max (r1.x, r2.x);
-  int x2 = min (r1.x + r1.w, r2.x + r2.w);
-  if (x2 < x1)
-    return false;
-  int y1 = max (r1.y, r2.y);
-  int y2 = min (r1.y + r1.h, r2.y + r2.h);
-  if (y2 < y1)
+  int x = max (r1.x, r2.x);
+  int y = max (r1.y, r2.y);
+  int w = min (r1.x + r1.w, r2.x + r2.w) - x;
+  int h = min (r1.y + r1.h, r2.y + r2.h) - y;
+
+  if (w == 0 || h == 0)
     return false;
-  *r = (struct rect) { .x = x1, .y = y1, .w = x2 - x1, .h = y2 - y1 };
+
+  *r = (struct rect) { .x = x, .y = y, .w = w, .h = h };
   return true;
 }
 
@@ -3720,8 +3720,8 @@ copy_child_glyphs (struct frame *root, struct frame *child)
     }
 
   /* First visible row/col, relative to the child frame.  */
-  int child_x = child->left_pos < 0 ? - child->left_pos : 0;
-  int child_y = child->top_pos < 0 ? - child->top_pos : 0;
+  int child_x, child_y;
+  child_xy (child, r.x, r.y, &child_x, &child_y);
 
   /* For all rows in the intersection, copy glyphs from the child's
      current matrix to the root's desired matrix, enabling those rows
-- 
2.48.1