From c258528cfbc27f1f7e7604425a4c3d3dc78408bb Mon Sep 17 00:00:00 2001 From: Po Lu Date: Wed, 18 May 2022 04:07:31 +0000 Subject: [PATCH] Fix race conditions when calculating Haiku frame geometry * src/haiku_support.cc (be_lock_window, be_unlock_window): New functions. * src/haiku_support.h: Update prototypes. * src/haikufns.c (frame_geometry): Lock window before asking for its dimensions and frame. --- src/haiku_support.cc | 17 +++++++++++++++++ src/haiku_support.h | 2 ++ src/haikufns.c | 13 +++++++++---- 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/haiku_support.cc b/src/haiku_support.cc index 28c86085847..0c126dab3d6 100644 --- a/src/haiku_support.cc +++ b/src/haiku_support.cc @@ -5163,3 +5163,20 @@ be_send_move_frame_event (void *window) msg.SendMessage (SEND_MOVE_FRAME_EVENT); } + +void +be_lock_window (void *window) +{ + BWindow *wnd = (BWindow *) window; + + if (!wnd->LockLooper ()) + gui_abort ("Failed to lock window looper"); +} + +void +be_unlock_window (void *window) +{ + BWindow *wnd = (BWindow *) window; + + wnd->UnlockLooper (); +} diff --git a/src/haiku_support.h b/src/haiku_support.h index 22f13c1ee67..14dd36e275a 100644 --- a/src/haiku_support.h +++ b/src/haiku_support.h @@ -691,6 +691,8 @@ extern void be_get_window_decorator_dimensions (void *, int *, int *, int *, int extern void be_get_window_decorator_frame (void *, int *, int *, int *, int *); extern void be_send_move_frame_event (void *); +extern void be_lock_window (void *); +extern void be_unlock_window (void *); #ifdef __cplusplus } diff --git a/src/haikufns.c b/src/haikufns.c index fa47da73d2c..8b6296e6ae1 100644 --- a/src/haikufns.c +++ b/src/haikufns.c @@ -1394,17 +1394,22 @@ static Lisp_Object frame_geometry (Lisp_Object frame, Lisp_Object attribute) { struct frame *f, *parent; + void *window; int outer_x, outer_y, outer_width, outer_height; int right_off, bottom_off, top_off; int native_x, native_y; f = decode_window_system_frame (frame); parent = FRAME_PARENT_FRAME (f); + window = FRAME_HAIKU_WINDOW (f); + + be_lock_window (window); + be_get_window_decorator_frame (window, &outer_x, &outer_y, + &outer_width, &outer_height); + be_get_window_decorator_dimensions (window, NULL, &top_off, + &right_off, &bottom_off); + be_unlock_window (window); - be_get_window_decorator_frame (FRAME_HAIKU_WINDOW (f), &outer_x, - &outer_y, &outer_width, &outer_height); - be_get_window_decorator_dimensions (FRAME_HAIKU_WINDOW (f), NULL, - &top_off, &right_off, &bottom_off); native_x = FRAME_OUTPUT_DATA (f)->frame_x; native_y = FRAME_OUTPUT_DATA (f)->frame_y; -- 2.39.2