Skip to content

Commit 24560cf

Browse files
committed
Refactor window handle to use WindowManager lookup
Updated GetWindowFromHandle to retrieve the shared_ptr<Window> from WindowManager using the Window pointer's ID, instead of casting the handle to a struct. This improves safety and consistency with window management.
1 parent 032ca47 commit 24560cf

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/capi/app_runner_c.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <memory>
44

55
#include "../app_runner.h"
6+
#include "../window_manager.h"
67

78
using namespace nativeapi;
89

@@ -17,13 +18,14 @@ static std::shared_ptr<Window> GetWindowFromHandle(
1718
return nullptr;
1819
}
1920

20-
// Assuming native_window_handle structure from window_c.cpp
21-
struct native_window_handle {
22-
std::shared_ptr<Window> window;
23-
};
24-
25-
auto* handle = reinterpret_cast<native_window_handle*>(window_handle);
26-
return handle->window;
21+
// The window_handle is a raw pointer to Window (as returned by window.get())
22+
// We need to get the shared_ptr from WindowManager
23+
auto* window_ptr = static_cast<Window*>(window_handle);
24+
WindowID window_id = window_ptr->GetId();
25+
26+
// Retrieve the shared_ptr from WindowManager
27+
auto& manager = WindowManager::GetInstance();
28+
return manager.Get(window_id);
2729
}
2830

2931
extern "C" {

0 commit comments

Comments
 (0)