55
66using namespace nativeapi ;
77
8- // Internal structure to hold the actual Display pointer
9- struct native_display_handle {
10- std::shared_ptr<Display> display;
11- explicit native_display_handle (std::shared_ptr<Display> d)
12- : display(std::move(d)) {}
13- };
8+ // Helper to cast opaque handle to C++ Display pointer
9+ static inline Display* to_display (native_display_t handle) {
10+ return static_cast <Display*>(handle);
11+ }
1412
1513// Helper function to safely copy C++ string to C string
1614static char * copy_string (const std::string& str) {
@@ -28,26 +26,26 @@ static char* copy_string(const std::string& str) {
2826// Basic identification getters
2927FFI_PLUGIN_EXPORT
3028char * native_display_get_id (native_display_t display) {
31- if (!display || !display-> display )
29+ if (!display)
3230 return nullptr ;
33- return copy_string (display-> display ->GetId ());
31+ return copy_string (to_display ( display) ->GetId ());
3432}
3533
3634FFI_PLUGIN_EXPORT
3735char * native_display_get_name (native_display_t display) {
38- if (!display || !display-> display )
36+ if (!display)
3937 return nullptr ;
40- return copy_string (display-> display ->GetName ());
38+ return copy_string (to_display ( display) ->GetName ());
4139}
4240
4341// Physical properties getters
4442FFI_PLUGIN_EXPORT
4543native_point_t native_display_get_position (native_display_t display) {
4644 native_point_t result = {0.0 , 0.0 };
47- if (!display || !display-> display )
45+ if (!display)
4846 return result;
4947
50- auto pos = display-> display ->GetPosition ();
48+ auto pos = to_display ( display) ->GetPosition ();
5149 result.x = pos.x ;
5250 result.y = pos.y ;
5351 return result;
@@ -56,10 +54,10 @@ native_point_t native_display_get_position(native_display_t display) {
5654FFI_PLUGIN_EXPORT
5755native_size_t native_display_get_size (native_display_t display) {
5856 native_size_t result = {0.0 , 0.0 };
59- if (!display || !display-> display )
57+ if (!display)
6058 return result;
6159
62- auto size = display-> display ->GetSize ();
60+ auto size = to_display ( display) ->GetSize ();
6361 result.width = size.width ;
6462 result.height = size.height ;
6563 return result;
@@ -68,10 +66,10 @@ native_size_t native_display_get_size(native_display_t display) {
6866FFI_PLUGIN_EXPORT
6967native_rectangle_t native_display_get_work_area (native_display_t display) {
7068 native_rectangle_t result = {0.0 , 0.0 , 0.0 , 0.0 };
71- if (!display || !display-> display )
69+ if (!display)
7270 return result;
7371
74- Rectangle work_area = display-> display ->GetWorkArea ();
72+ Rectangle work_area = to_display ( display) ->GetWorkArea ();
7573 result.x = work_area.x ;
7674 result.y = work_area.y ;
7775 result.width = work_area.width ;
@@ -81,26 +79,26 @@ native_rectangle_t native_display_get_work_area(native_display_t display) {
8179
8280FFI_PLUGIN_EXPORT
8381double native_display_get_scale_factor (native_display_t display) {
84- if (!display || !display-> display )
82+ if (!display)
8583 return 1.0 ;
86- return display-> display ->GetScaleFactor ();
84+ return to_display ( display) ->GetScaleFactor ();
8785}
8886
8987// Additional properties getters
9088FFI_PLUGIN_EXPORT
9189bool native_display_is_primary (native_display_t display) {
92- if (!display || !display-> display )
90+ if (!display)
9391 return false ;
94- return display-> display ->IsPrimary ();
92+ return to_display ( display) ->IsPrimary ();
9593}
9694
9795FFI_PLUGIN_EXPORT
9896native_display_orientation_t native_display_get_orientation (
9997 native_display_t display) {
100- if (!display || !display-> display )
98+ if (!display)
10199 return NATIVE_DISPLAY_ORIENTATION_PORTRAIT;
102100
103- DisplayOrientation orientation = display-> display ->GetOrientation ();
101+ DisplayOrientation orientation = to_display ( display) ->GetOrientation ();
104102 switch (orientation) {
105103 case DisplayOrientation::kPortrait :
106104 return NATIVE_DISPLAY_ORIENTATION_PORTRAIT;
@@ -117,46 +115,46 @@ native_display_orientation_t native_display_get_orientation(
117115
118116FFI_PLUGIN_EXPORT
119117int native_display_get_refresh_rate (native_display_t display) {
120- if (!display || !display-> display )
118+ if (!display)
121119 return 0 ;
122- return display-> display ->GetRefreshRate ();
120+ return to_display ( display) ->GetRefreshRate ();
123121}
124122
125123FFI_PLUGIN_EXPORT
126124int native_display_get_bit_depth (native_display_t display) {
127- if (!display || !display-> display )
125+ if (!display)
128126 return 0 ;
129- return display-> display ->GetBitDepth ();
127+ return to_display ( display) ->GetBitDepth ();
130128}
131129
132130// Hardware information getters
133131FFI_PLUGIN_EXPORT
134132char * native_display_get_manufacturer (native_display_t display) {
135- if (!display || !display-> display )
133+ if (!display)
136134 return nullptr ;
137- return copy_string (display-> display ->GetManufacturer ());
135+ return copy_string (to_display ( display) ->GetManufacturer ());
138136}
139137
140138FFI_PLUGIN_EXPORT
141139char * native_display_get_model (native_display_t display) {
142- if (!display || !display-> display )
140+ if (!display)
143141 return nullptr ;
144- return copy_string (display-> display ->GetModel ());
142+ return copy_string (to_display ( display) ->GetModel ());
145143}
146144
147145FFI_PLUGIN_EXPORT
148146char * native_display_get_serial_number (native_display_t display) {
149- if (!display || !display-> display )
147+ if (!display)
150148 return nullptr ;
151- return copy_string (display-> display ->GetSerialNumber ());
149+ return copy_string (to_display ( display) ->GetSerialNumber ());
152150}
153151
154152// Platform-specific functions
155153FFI_PLUGIN_EXPORT
156154void * native_display_get_native_object (native_display_t display) {
157- if (!display || !display-> display )
155+ if (!display)
158156 return nullptr ;
159- return display-> display ->GetNativeObject ();
157+ return to_display ( display) ->GetNativeObject ();
160158}
161159
162160// Memory management
@@ -170,7 +168,7 @@ void native_display_free_string(char* str) {
170168FFI_PLUGIN_EXPORT
171169void native_display_free (native_display_t display) {
172170 if (display) {
173- delete display;
171+ delete to_display ( display) ;
174172 }
175173}
176174
@@ -182,7 +180,7 @@ void native_display_list_free(native_display_list_t* list) {
182180 // Free individual display handles
183181 for (long i = 0 ; i < list->count ; i++) {
184182 if (list->displays [i]) {
185- delete list->displays [i];
183+ delete to_display ( list->displays [i]) ;
186184 }
187185 }
188186
@@ -196,11 +194,7 @@ void native_display_list_free(native_display_list_t* list) {
196194native_display_t native_display_create_handle (
197195 const nativeapi::Display& cpp_display) {
198196 try {
199- // Create a shared_ptr from the Display object (copy constructor)
200- auto display_ptr = std::make_shared<Display>(cpp_display);
201-
202- // Create the native handle
203- auto * handle = new (std::nothrow) native_display_handle (display_ptr);
197+ auto * handle = new (std::nothrow) Display (cpp_display);
204198 return handle;
205199 } catch (const std::exception&) {
206200 return nullptr ;
0 commit comments