From 4be39852a84faaf727aa4efa1c125584dce1e768 Mon Sep 17 00:00:00 2001 From: Andreas Just Date: Tue, 28 Jul 2026 08:02:24 +0200 Subject: [PATCH] Fix BView detach callback dispatch Dispatch DetachedFromWindow and AllDetached to their matching Python overrides instead of AllAttached. Add a regression test that exercises both C++ trampoline paths and verifies the callbacks received by a Python BView subclass. --- bindings/interface/View.cpp | 4 +-- tests/viewDetachCallbacks.py | 53 ++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 tests/viewDetachCallbacks.py diff --git a/bindings/interface/View.cpp b/bindings/interface/View.cpp index d9bbb46..3551ee9 100644 --- a/bindings/interface/View.cpp +++ b/bindings/interface/View.cpp @@ -49,10 +49,10 @@ class PyBView : public BView{ PYBIND11_OVERLOAD(void, BView, AllAttached); } void DetachedFromWindow() override { - PYBIND11_OVERLOAD(void, BView, AllAttached); + PYBIND11_OVERLOAD(void, BView, DetachedFromWindow); } void AllDetached() override { - PYBIND11_OVERLOAD(void, BView, AllAttached); + PYBIND11_OVERLOAD(void, BView, AllDetached); } void MessageReceived(BMessage* message) override { PYBIND11_OVERLOAD(void, BView, MessageReceived, message); diff --git a/tests/viewDetachCallbacks.py b/tests/viewDetachCallbacks.py new file mode 100644 index 0000000..772918b --- /dev/null +++ b/tests/viewDetachCallbacks.py @@ -0,0 +1,53 @@ +from Be import BApplication, BView + + +EXPECTED_CALLBACKS = [ + "DetachedFromWindow", + "AllDetached", +] + + +class CallbackProbe(BView): + def __init__(self): + BView.__init__( + self, + "callback-probe", + 0, + None, + ) + self.calls = [] + + def AllAttached(self): + self.calls.append("AllAttached") + + def DetachedFromWindow(self): + self.calls.append("DetachedFromWindow") + + def AllDetached(self): + self.calls.append("AllDetached") + + +def main(): + application = BApplication( + "application/x-vnd.haiku-pyapi-view-detach-callback-test" + ) + view = CallbackProbe() + + BView.DetachedFromWindow(view) + BView.AllDetached(view) + + if view.calls != EXPECTED_CALLBACKS: + raise SystemExit( + "FAIL: incorrect detach callback dispatch: " + f"{view.calls!r}" + ) + + print("callbacks =", view.calls) + print("VIEW DETACH CALLBACK REGRESSION TEST: PASS") + + # Keep the BApplication alive until the probe has completed. + del application + + +if __name__ == "__main__": + main()