From 750ef4b5bbe2d2ecf14b355344f93a13d5ac0249 Mon Sep 17 00:00:00 2001 From: Po Lu Date: Mon, 17 Feb 2025 11:32:43 +0800 Subject: [PATCH] Synchronize frame placement logic with X * src/androidterm.c (android_calc_absolute_position): New function. (android_set_offset): Call android_calc_absolute_position. * src/pgtkterm.c (pgtk_calc_absolute_position): Synchronize with X. (cherry picked from commit 0a6997b58d417043406dadf3d40e6f9de9ded6a8) --- src/androidterm.c | 76 +++++++++++++++++++++++++++++++++++++++++++++++ src/pgtkterm.c | 6 ++-- 2 files changed, 79 insertions(+), 3 deletions(-) diff --git a/src/androidterm.c b/src/androidterm.c index 3e367b391a8..5951135eaa6 100644 --- a/src/androidterm.c +++ b/src/androidterm.c @@ -2291,6 +2291,81 @@ android_set_window_size (struct frame *f, bool change_gravity, do_pending_window_change (false); } +/* Calculate the absolute position in frame F + from its current recorded position values and gravity. */ + +static void +android_calc_absolute_position (struct frame *f) +{ + int flags = f->size_hint_flags; + struct frame *p = FRAME_PARENT_FRAME (f); + + /* We have nothing to do if the current position + is already for the top-left corner. */ + if (!((flags & XNegative) || (flags & YNegative))) + return; + + /* Treat negative positions as relative to the leftmost bottommost + position that fits on the screen. */ + if (flags & XNegative) + { + int width = FRAME_PIXEL_WIDTH (f); + + /* A frame that has been visible at least once should have outer + edges. */ + if (f->output_data.android->has_been_visible && !p) + { + Lisp_Object frame; + Lisp_Object edges = Qnil; + + XSETFRAME (frame, f); + edges = Fandroid_frame_edges (frame, Qouter_edges); + if (!NILP (edges)) + width = (XFIXNUM (Fnth (make_fixnum (2), edges)) + - XFIXNUM (Fnth (make_fixnum (0), edges))); + } + + if (p) + f->left_pos = (FRAME_PIXEL_WIDTH (p) - width - 2 * f->border_width + + f->left_pos); + else + /* Not that this is of much significance, for Android programs + cannot position their windows at absolute positions in the + screen. */ + f->left_pos = (android_get_screen_width () - width + f->left_pos); + + } + + if (flags & YNegative) + { + int height = FRAME_PIXEL_HEIGHT (f); + + if (f->output_data.android->has_been_visible && !p) + { + Lisp_Object frame; + Lisp_Object edges = Qnil; + + XSETFRAME (frame, f); + if (NILP (edges)) + edges = Fandroid_frame_edges (frame, Qouter_edges); + if (!NILP (edges)) + height = (XFIXNUM (Fnth (make_fixnum (3), edges)) + - XFIXNUM (Fnth (make_fixnum (1), edges))); + } + + if (p) + f->top_pos = (FRAME_PIXEL_HEIGHT (p) - height - 2 * f->border_width + + f->top_pos); + else + f->top_pos = (android_get_screen_height () - height + f->top_pos); + } + + /* The left_pos and top_pos + are now relative to the top and left screen edges, + so the flags should correspond. */ + f->size_hint_flags &= ~(XNegative | YNegative); +} + static void android_set_offset (struct frame *f, int xoff, int yoff, int change_gravity) @@ -2307,6 +2382,7 @@ android_set_offset (struct frame *f, int xoff, int yoff, f->win_gravity = NorthWestGravity; } + android_calc_absolute_position (f); android_move_window (FRAME_ANDROID_WINDOW (f), xoff, yoff); } diff --git a/src/pgtkterm.c b/src/pgtkterm.c index 6840340dec6..60313ec2637 100644 --- a/src/pgtkterm.c +++ b/src/pgtkterm.c @@ -569,12 +569,12 @@ pgtk_calc_absolute_position (struct frame *f) /* We have nothing to do if the current position is already for the top-left corner. */ - if (! ((flags & XNegative) || (flags & YNegative))) + if (!((flags & XNegative) || (flags & YNegative))) return; /* Treat negative positions as relative to the leftmost bottommost position that fits on the screen. */ - if ((flags & XNegative) && (f->left_pos <= 0)) + if (flags & XNegative) { int width = FRAME_PIXEL_WIDTH (f); @@ -601,7 +601,7 @@ pgtk_calc_absolute_position (struct frame *f) } - if ((flags & YNegative) && (f->top_pos <= 0)) + if (flags & YNegative) { int height = FRAME_PIXEL_HEIGHT (f); -- 2.39.5