@@ -17,7 +17,7 @@ struct TrayIconListenerData {
1717
1818// Global maps to store listener data
1919static std::map<native_tray_icon_t , std::vector<std::shared_ptr<TrayIconListenerData>>> g_tray_icon_listeners;
20- static size_t g_next_listener_id = 1 ;
20+ static std::atomic< int > g_tray_icon_next_listener_id{ 1 } ;
2121
2222// TrayIcon C API Implementation
2323
@@ -32,7 +32,7 @@ native_tray_icon_t native_tray_icon_create(void) {
3232
3333native_tray_icon_t native_tray_icon_create_from_native (void * native_tray) {
3434 if (!native_tray) return nullptr ;
35-
35+
3636 try {
3737 auto tray_icon = std::make_shared<TrayIcon>(native_tray);
3838 return static_cast <native_tray_icon_t >(tray_icon.get ());
@@ -49,14 +49,14 @@ void native_tray_icon_destroy(native_tray_icon_t tray_icon) {
4949 if (it != g_tray_icon_listeners.end ()) {
5050 g_tray_icon_listeners.erase (it);
5151 }
52-
52+
5353 // Note: The actual TrayIcon object is managed by shared_ptr
5454 // This just removes our reference to it
5555}
5656
5757native_tray_icon_id_t native_tray_icon_get_id (native_tray_icon_t tray_icon) {
5858 if (!tray_icon) return -1 ;
59-
59+
6060 try {
6161 auto tray_icon_ptr = static_cast <TrayIcon*>(tray_icon);
6262 return tray_icon_ptr->id ;
@@ -67,7 +67,7 @@ native_tray_icon_id_t native_tray_icon_get_id(native_tray_icon_t tray_icon) {
6767
6868void native_tray_icon_set_icon (native_tray_icon_t tray_icon, const char * icon) {
6969 if (!tray_icon || !icon) return ;
70-
70+
7171 try {
7272 auto tray_icon_ptr = static_cast <TrayIcon*>(tray_icon);
7373 tray_icon_ptr->SetIcon (icon);
@@ -78,7 +78,7 @@ void native_tray_icon_set_icon(native_tray_icon_t tray_icon, const char* icon) {
7878
7979void native_tray_icon_set_title (native_tray_icon_t tray_icon, const char * title) {
8080 if (!tray_icon || !title) return ;
81-
81+
8282 try {
8383 auto tray_icon_ptr = static_cast <TrayIcon*>(tray_icon);
8484 tray_icon_ptr->SetTitle (title);
@@ -89,15 +89,15 @@ void native_tray_icon_set_title(native_tray_icon_t tray_icon, const char* title)
8989
9090int native_tray_icon_get_title (native_tray_icon_t tray_icon, char * buffer, size_t buffer_size) {
9191 if (!tray_icon || !buffer || buffer_size == 0 ) return -1 ;
92-
92+
9393 try {
9494 auto tray_icon_ptr = static_cast <TrayIcon*>(tray_icon);
9595 std::string title = tray_icon_ptr->GetTitle ();
96-
96+
9797 if (title.length () >= buffer_size) {
9898 return -1 ;
9999 }
100-
100+
101101 strncpy (buffer, title.c_str (), buffer_size - 1 );
102102 buffer[buffer_size - 1 ] = ' \0 ' ;
103103 return static_cast <int >(title.length ());
@@ -108,7 +108,7 @@ int native_tray_icon_get_title(native_tray_icon_t tray_icon, char* buffer, size_
108108
109109void native_tray_icon_set_tooltip (native_tray_icon_t tray_icon, const char * tooltip) {
110110 if (!tray_icon || !tooltip) return ;
111-
111+
112112 try {
113113 auto tray_icon_ptr = static_cast <TrayIcon*>(tray_icon);
114114 tray_icon_ptr->SetTooltip (tooltip);
@@ -119,15 +119,15 @@ void native_tray_icon_set_tooltip(native_tray_icon_t tray_icon, const char* tool
119119
120120int native_tray_icon_get_tooltip (native_tray_icon_t tray_icon, char * buffer, size_t buffer_size) {
121121 if (!tray_icon || !buffer || buffer_size == 0 ) return -1 ;
122-
122+
123123 try {
124124 auto tray_icon_ptr = static_cast <TrayIcon*>(tray_icon);
125125 std::string tooltip = tray_icon_ptr->GetTooltip ();
126-
126+
127127 if (tooltip.length () >= buffer_size) {
128128 return -1 ;
129129 }
130-
130+
131131 strncpy (buffer, tooltip.c_str (), buffer_size - 1 );
132132 buffer[buffer_size - 1 ] = ' \0 ' ;
133133 return static_cast <int >(tooltip.length ());
@@ -138,7 +138,7 @@ int native_tray_icon_get_tooltip(native_tray_icon_t tray_icon, char* buffer, siz
138138
139139void native_tray_icon_set_context_menu (native_tray_icon_t tray_icon, native_menu_t menu) {
140140 if (!tray_icon) return ;
141-
141+
142142 try {
143143 auto tray_icon_ptr = static_cast <TrayIcon*>(tray_icon);
144144 if (menu) {
@@ -160,7 +160,7 @@ void native_tray_icon_set_context_menu(native_tray_icon_t tray_icon, native_menu
160160
161161native_menu_t native_tray_icon_get_context_menu (native_tray_icon_t tray_icon) {
162162 if (!tray_icon) return nullptr ;
163-
163+
164164 try {
165165 auto tray_icon_ptr = static_cast <TrayIcon*>(tray_icon);
166166 auto menu = tray_icon_ptr->GetContextMenu ();
@@ -172,16 +172,16 @@ native_menu_t native_tray_icon_get_context_menu(native_tray_icon_t tray_icon) {
172172
173173bool native_tray_icon_get_bounds (native_tray_icon_t tray_icon, native_rectangle_t * bounds) {
174174 if (!tray_icon || !bounds) return false ;
175-
175+
176176 try {
177177 auto tray_icon_ptr = static_cast <TrayIcon*>(tray_icon);
178178 Rectangle cpp_bounds = tray_icon_ptr->GetBounds ();
179-
179+
180180 bounds->x = cpp_bounds.x ;
181181 bounds->y = cpp_bounds.y ;
182182 bounds->width = cpp_bounds.width ;
183183 bounds->height = cpp_bounds.height ;
184-
184+
185185 return true ;
186186 } catch (...) {
187187 return false ;
@@ -190,7 +190,7 @@ bool native_tray_icon_get_bounds(native_tray_icon_t tray_icon, native_rectangle_
190190
191191bool native_tray_icon_show (native_tray_icon_t tray_icon) {
192192 if (!tray_icon) return false ;
193-
193+
194194 try {
195195 auto tray_icon_ptr = static_cast <TrayIcon*>(tray_icon);
196196 return tray_icon_ptr->Show ();
@@ -201,7 +201,7 @@ bool native_tray_icon_show(native_tray_icon_t tray_icon) {
201201
202202bool native_tray_icon_hide (native_tray_icon_t tray_icon) {
203203 if (!tray_icon) return false ;
204-
204+
205205 try {
206206 auto tray_icon_ptr = static_cast <TrayIcon*>(tray_icon);
207207 return tray_icon_ptr->Hide ();
@@ -212,7 +212,7 @@ bool native_tray_icon_hide(native_tray_icon_t tray_icon) {
212212
213213bool native_tray_icon_is_visible (native_tray_icon_t tray_icon) {
214214 if (!tray_icon) return false ;
215-
215+
216216 try {
217217 auto tray_icon_ptr = static_cast <TrayIcon*>(tray_icon);
218218 return tray_icon_ptr->IsVisible ();
@@ -232,7 +232,7 @@ int native_tray_icon_add_listener(native_tray_icon_t tray_icon, native_tray_icon
232232 listener_data->event_type = event_type;
233233 listener_data->callback = callback;
234234 listener_data->user_data = user_data;
235- listener_data->listener_id = g_next_listener_id ++;
235+ listener_data->listener_id = g_tray_icon_next_listener_id ++;
236236
237237 // Get or create listener list for this tray icon
238238 auto & listeners = g_tray_icon_listeners[tray_icon];
@@ -315,7 +315,7 @@ bool native_tray_icon_remove_listener(native_tray_icon_t tray_icon, int listener
315315
316316bool native_tray_icon_show_context_menu (native_tray_icon_t tray_icon, double x, double y) {
317317 if (!tray_icon) return false ;
318-
318+
319319 try {
320320 auto tray_icon_ptr = static_cast <TrayIcon*>(tray_icon);
321321 return tray_icon_ptr->ShowContextMenu (x, y);
@@ -326,11 +326,11 @@ bool native_tray_icon_show_context_menu(native_tray_icon_t tray_icon, double x,
326326
327327bool native_tray_icon_show_context_menu_default (native_tray_icon_t tray_icon) {
328328 if (!tray_icon) return false ;
329-
329+
330330 try {
331331 auto tray_icon_ptr = static_cast <TrayIcon*>(tray_icon);
332332 return tray_icon_ptr->ShowContextMenu ();
333333 } catch (...) {
334334 return false ;
335335 }
336- }
336+ }
0 commit comments