]> git.eshelyaron.com Git - emacs.git/commitdiff
Improve Haiku frame restacking logic
authorPo Lu <luangruo@yahoo.com>
Tue, 4 Jan 2022 06:10:25 +0000 (06:10 +0000)
committerPo Lu <luangruo@yahoo.com>
Tue, 4 Jan 2022 06:10:25 +0000 (06:10 +0000)
* src/haiku_support.cc (BWindow_is_active):
* src/haiku_support.h (BWindow_is_active): New functions.

* src/haikufns.c (Fhaiku_frame_restack): Prevent the newly
raised frame from being sent to the back of the display.

src/haiku_support.cc
src/haiku_support.h
src/haikufns.c

index effd4c33a92d8de7c852a31c0dff3b121be59df1..2171b7bf81754324d461caa66209f5558b4daf11 100644 (file)
@@ -3002,3 +3002,10 @@ BWindow_send_behind (void *window, void *other_window)
   w->SendBehind (other);
   w->UnlockLooper ();
 }
+
+bool
+BWindow_is_active (void *window)
+{
+  BWindow *w = (BWindow *) window;
+  return w->IsActive ();
+}
index 2b61ec1ac1ea19989cb62bd55afe86ea184b9693..ef90374f69db5cb84e9904c88dec90e8968e7eb8 100644 (file)
@@ -826,6 +826,9 @@ extern "C"
   extern void
   BWindow_send_behind (void *window, void *other_window);
 
+  extern bool
+  BWindow_is_active (void *window);
+
 #ifdef __cplusplus
   extern void *
   find_appropriate_view_for_draw (void *vw);
index 0b7972f945c31687c0442c4a78fcc59ac98edd1c..f010867fd937f9f6ec19a9dfd8f6663950d0cc6d 100644 (file)
@@ -2341,11 +2341,39 @@ Some window managers may refuse to restack windows.  */)
   block_input ();
 
   if (NILP (above))
-    BWindow_send_behind (FRAME_HAIKU_WINDOW (f1),
-                        FRAME_HAIKU_WINDOW (f2));
+    {
+      /* If the window that is currently active will be sent behind
+        another window, make the window that it is being sent behind
+        active first, to avoid both windows being moved to the back of
+        the display.  */
+
+      if (BWindow_is_active (FRAME_HAIKU_WINDOW (f1))
+         /* But don't do this if any of the frames involved have
+            child frames, since they are guaranteed to be in front of
+            their toplevel parents.  */
+         && !FRAME_PARENT_FRAME (f1)
+         && !FRAME_PARENT_FRAME (f2))
+       {
+         BWindow_activate (FRAME_HAIKU_WINDOW (f2));
+         BWindow_sync (FRAME_HAIKU_WINDOW (f2));
+       }
+
+      BWindow_send_behind (FRAME_HAIKU_WINDOW (f1),
+                          FRAME_HAIKU_WINDOW (f2));
+    }
   else
-    BWindow_send_behind (FRAME_HAIKU_WINDOW (f2),
-                        FRAME_HAIKU_WINDOW (f1));
+    {
+      if (BWindow_is_active (FRAME_HAIKU_WINDOW (f2))
+         && !FRAME_PARENT_FRAME (f1)
+         && !FRAME_PARENT_FRAME (f2))
+       {
+         BWindow_activate (FRAME_HAIKU_WINDOW (f1));
+         BWindow_sync (FRAME_HAIKU_WINDOW (f1));
+       }
+
+      BWindow_send_behind (FRAME_HAIKU_WINDOW (f2),
+                          FRAME_HAIKU_WINDOW (f1));
+    }
   BWindow_sync (FRAME_HAIKU_WINDOW (f1));
   BWindow_sync (FRAME_HAIKU_WINDOW (f2));