From 693815e90f90d977405dc9cd2857505a375caf96 Mon Sep 17 00:00:00 2001 From: Po Lu Date: Tue, 4 Jan 2022 06:10:25 +0000 Subject: [PATCH] Improve Haiku frame restacking logic * 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 | 7 +++++++ src/haiku_support.h | 3 +++ src/haikufns.c | 36 ++++++++++++++++++++++++++++++++---- 3 files changed, 42 insertions(+), 4 deletions(-) diff --git a/src/haiku_support.cc b/src/haiku_support.cc index effd4c33a92..2171b7bf817 100644 --- a/src/haiku_support.cc +++ b/src/haiku_support.cc @@ -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 (); +} diff --git a/src/haiku_support.h b/src/haiku_support.h index 2b61ec1ac1e..ef90374f69d 100644 --- a/src/haiku_support.h +++ b/src/haiku_support.h @@ -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); diff --git a/src/haikufns.c b/src/haikufns.c index 0b7972f945c..f010867fd93 100644 --- a/src/haikufns.c +++ b/src/haikufns.c @@ -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)); -- 2.39.2