]> git.eshelyaron.com Git - emacs.git/commitdiff
Synchronize frame placement logic with X
authorPo Lu <luangruo@yahoo.com>
Mon, 17 Feb 2025 03:32:43 +0000 (11:32 +0800)
committerEshel Yaron <me@eshelyaron.com>
Tue, 18 Feb 2025 08:47:18 +0000 (09:47 +0100)
* 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
src/pgtkterm.c

index 3e367b391a8543ebe2381536e70d78f69979a63c..5951135eaa69a2f87f6aac53638a93c948a93390 100644 (file)
@@ -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);
 }
 
index 6840340dec638f1811a4fb28f2bcf5cb67973051..60313ec263707060727bb23d91a43f66994183b7 100644 (file)
@@ -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);