summaryrefslogtreecommitdiff
path: root/src/contrib/SDL-3.2.20/test/testtray.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/contrib/SDL-3.2.20/test/testtray.c')
-rw-r--r--src/contrib/SDL-3.2.20/test/testtray.c649
1 files changed, 649 insertions, 0 deletions
diff --git a/src/contrib/SDL-3.2.20/test/testtray.c b/src/contrib/SDL-3.2.20/test/testtray.c
new file mode 100644
index 0000000..8046d60
--- /dev/null
+++ b/src/contrib/SDL-3.2.20/test/testtray.c
@@ -0,0 +1,649 @@
1#include "testutils.h"
2#include <SDL3/SDL.h>
3#include <SDL3/SDL_main.h>
4#include <SDL3/SDL_test.h>
5
6static void SDLCALL tray_quit(void *ptr, SDL_TrayEntry *entry)
7{
8 SDL_Event e;
9 e.type = SDL_EVENT_QUIT;
10 SDL_PushEvent(&e);
11}
12
13static bool trays_destroyed = false;
14
15static void SDLCALL tray_close(void *ptr, SDL_TrayEntry *entry)
16{
17 SDL_Tray **trays = (SDL_Tray **) ptr;
18
19 trays_destroyed = true;
20
21 SDL_DestroyTray(trays[0]);
22 SDL_DestroyTray(trays[1]);
23}
24
25static void SDLCALL apply_icon(void *ptr, const char * const *filelist, int filter)
26{
27 if (!*filelist) {
28 return;
29 }
30
31 SDL_Surface *icon = SDL_LoadBMP(*filelist);
32
33 if (!icon) {
34 SDL_Log("Couldn't load icon '%s': %s", *filelist, SDL_GetError());
35 return;
36 }
37
38 SDL_Tray *tray = (SDL_Tray *) ptr;
39 SDL_SetTrayIcon(tray, icon);
40
41 SDL_DestroySurface(icon);
42}
43
44static void SDLCALL change_icon(void *ptr, SDL_TrayEntry *entry)
45{
46 SDL_DialogFileFilter filters[] = {
47 { "BMP image files", "bmp" },
48 { "All files", "*" },
49 };
50
51 SDL_ShowOpenFileDialog(apply_icon, ptr, NULL, filters, 2, NULL, 0);
52}
53
54static void SDLCALL print_entry(void *ptr, SDL_TrayEntry *entry)
55{
56 SDL_Log("Clicked on button '%s'", SDL_GetTrayEntryLabel(entry));
57}
58
59static void SDLCALL set_entry_enabled(void *ptr, SDL_TrayEntry *entry)
60{
61 SDL_TrayEntry *target = (SDL_TrayEntry *) ptr;
62 SDL_SetTrayEntryEnabled(target, true);
63}
64
65static void SDLCALL set_entry_disabled(void *ptr, SDL_TrayEntry *entry)
66{
67 SDL_TrayEntry *target = (SDL_TrayEntry *) ptr;
68 SDL_SetTrayEntryEnabled(target, false);
69}
70
71static void SDLCALL set_entry_checked(void *ptr, SDL_TrayEntry *entry)
72{
73 SDL_TrayEntry *target = (SDL_TrayEntry *) ptr;
74 SDL_SetTrayEntryChecked(target, true);
75}
76
77static void SDLCALL set_entry_unchecked(void *ptr, SDL_TrayEntry *entry)
78{
79 SDL_TrayEntry *target = (SDL_TrayEntry *) ptr;
80 SDL_SetTrayEntryChecked(target, false);
81}
82
83static void SDLCALL remove_entry(void *ptr, SDL_TrayEntry *entry)
84{
85 SDL_TrayEntry *target = (SDL_TrayEntry *) ptr;
86 SDL_RemoveTrayEntry(target);
87
88 SDL_TrayMenu *ctrl_submenu = SDL_GetTrayEntryParent(entry);
89 SDL_TrayEntry *ctrl_entry = SDL_GetTrayMenuParentEntry(ctrl_submenu);
90
91 if (!ctrl_entry) {
92 SDL_Log("Attempt to remove a menu that isn't a submenu. This shouldn't happen.");
93 return;
94 }
95
96 SDL_RemoveTrayEntry(ctrl_entry);
97}
98
99static void SDLCALL append_button_to(void *ptr, SDL_TrayEntry *entry)
100{
101 SDL_TrayMenu *menu = (SDL_TrayMenu *) ptr;
102 SDL_TrayMenu *submenu;
103 SDL_TrayEntry *new_ctrl;
104 SDL_TrayEntry *new_ctrl_remove;
105 SDL_TrayEntry *new_ctrl_enabled;
106 SDL_TrayEntry *new_ctrl_disabled;
107 SDL_TrayEntry *new_example;
108
109 new_ctrl = SDL_InsertTrayEntryAt(SDL_GetTrayEntryParent(entry), -1, "New button", SDL_TRAYENTRY_SUBMENU);
110
111 if (!new_ctrl) {
112 SDL_Log("Couldn't insert entry in control tray: %s", SDL_GetError());
113 return;
114 }
115
116 /* ---------- */
117
118 submenu = SDL_CreateTraySubmenu(new_ctrl);
119
120 if (!new_ctrl) {
121 SDL_Log("Couldn't create control tray entry submenu: %s", SDL_GetError());
122 SDL_RemoveTrayEntry(new_ctrl);
123 return;
124 }
125
126 /* ---------- */
127
128 new_example = SDL_InsertTrayEntryAt(menu, -1, "New button", SDL_TRAYENTRY_BUTTON);
129
130 if (new_example == NULL) {
131 SDL_Log("Couldn't insert entry in example tray: %s", SDL_GetError());
132 SDL_RemoveTrayEntry(new_ctrl);
133 return;
134 }
135
136 SDL_SetTrayEntryCallback(new_example, print_entry, NULL);
137
138 /* ---------- */
139
140 new_ctrl_remove = SDL_InsertTrayEntryAt(submenu, -1, "Remove", SDL_TRAYENTRY_BUTTON);
141
142 if (new_ctrl_remove == NULL) {
143 SDL_Log("Couldn't insert new_ctrl_remove: %s", SDL_GetError());
144 SDL_RemoveTrayEntry(new_ctrl);
145 SDL_RemoveTrayEntry(new_example);
146 return;
147 }
148
149 SDL_SetTrayEntryCallback(new_ctrl_remove, remove_entry, new_example);
150
151 /* ---------- */
152
153 new_ctrl_enabled = SDL_InsertTrayEntryAt(submenu, -1, "Enable", SDL_TRAYENTRY_BUTTON);
154
155 if (new_ctrl_enabled == NULL) {
156 SDL_Log("Couldn't insert new_ctrl_enabled: %s", SDL_GetError());
157 SDL_RemoveTrayEntry(new_ctrl);
158 SDL_RemoveTrayEntry(new_example);
159 return;
160 }
161
162 SDL_SetTrayEntryCallback(new_ctrl_enabled, set_entry_enabled, new_example);
163
164 /* ---------- */
165
166 new_ctrl_disabled = SDL_InsertTrayEntryAt(submenu, -1, "Disable", SDL_TRAYENTRY_BUTTON);
167
168 if (new_ctrl_disabled == NULL) {
169 SDL_Log("Couldn't insert new_ctrl_disabled: %s", SDL_GetError());
170 SDL_RemoveTrayEntry(new_ctrl);
171 SDL_RemoveTrayEntry(new_example);
172 return;
173 }
174
175 SDL_SetTrayEntryCallback(new_ctrl_disabled, set_entry_disabled, new_example);
176}
177
178static void SDLCALL append_checkbox_to(void *ptr, SDL_TrayEntry *entry)
179{
180 SDL_TrayMenu *menu = (SDL_TrayMenu *) ptr;
181 SDL_TrayMenu *submenu;
182 SDL_TrayEntry *new_ctrl;
183 SDL_TrayEntry *new_ctrl_remove;
184 SDL_TrayEntry *new_ctrl_enabled;
185 SDL_TrayEntry *new_ctrl_disabled;
186 SDL_TrayEntry *new_ctrl_checked;
187 SDL_TrayEntry *new_ctrl_unchecked;
188 SDL_TrayEntry *new_example;
189
190 new_ctrl = SDL_InsertTrayEntryAt(SDL_GetTrayEntryParent(entry), -1, "New checkbox", SDL_TRAYENTRY_SUBMENU);
191
192 if (!new_ctrl) {
193 SDL_Log("Couldn't insert entry in control tray: %s", SDL_GetError());
194 return;
195 }
196
197 /* ---------- */
198
199 submenu = SDL_CreateTraySubmenu(new_ctrl);
200
201 if (!new_ctrl) {
202 SDL_Log("Couldn't create control tray entry submenu: %s", SDL_GetError());
203 SDL_RemoveTrayEntry(new_ctrl);
204 return;
205 }
206
207 /* ---------- */
208
209 new_example = SDL_InsertTrayEntryAt(menu, -1, "New checkbox", SDL_TRAYENTRY_CHECKBOX);
210
211 if (new_example == NULL) {
212 SDL_Log("Couldn't insert entry in example tray: %s", SDL_GetError());
213 SDL_RemoveTrayEntry(new_ctrl);
214 return;
215 }
216
217 SDL_SetTrayEntryCallback(new_example, print_entry, NULL);
218
219 /* ---------- */
220
221 new_ctrl_remove = SDL_InsertTrayEntryAt(submenu, -1, "Remove", SDL_TRAYENTRY_BUTTON);
222
223 if (new_ctrl_remove == NULL) {
224 SDL_Log("Couldn't insert new_ctrl_remove: %s", SDL_GetError());
225 SDL_RemoveTrayEntry(new_ctrl);
226 SDL_RemoveTrayEntry(new_example);
227 return;
228 }
229
230 SDL_SetTrayEntryCallback(new_ctrl_remove, remove_entry, new_example);
231
232 /* ---------- */
233
234 new_ctrl_enabled = SDL_InsertTrayEntryAt(submenu, -1, "Enable", SDL_TRAYENTRY_BUTTON);
235
236 if (new_ctrl_enabled == NULL) {
237 SDL_Log("Couldn't insert new_ctrl_enabled: %s", SDL_GetError());
238 SDL_RemoveTrayEntry(new_ctrl);
239 SDL_RemoveTrayEntry(new_example);
240 return;
241 }
242
243 SDL_SetTrayEntryCallback(new_ctrl_enabled, set_entry_enabled, new_example);
244
245 /* ---------- */
246
247 new_ctrl_disabled = SDL_InsertTrayEntryAt(submenu, -1, "Disable", SDL_TRAYENTRY_BUTTON);
248
249 if (new_ctrl_disabled == NULL) {
250 SDL_Log("Couldn't insert new_ctrl_disabled: %s", SDL_GetError());
251 SDL_RemoveTrayEntry(new_ctrl);
252 SDL_RemoveTrayEntry(new_example);
253 return;
254 }
255
256 SDL_SetTrayEntryCallback(new_ctrl_disabled, set_entry_disabled, new_example);
257
258 /* ---------- */
259
260 new_ctrl_checked = SDL_InsertTrayEntryAt(submenu, -1, "Check", SDL_TRAYENTRY_BUTTON);
261
262 if (new_ctrl_checked == NULL) {
263 SDL_Log("Couldn't insert new_ctrl_checked: %s", SDL_GetError());
264 SDL_RemoveTrayEntry(new_ctrl);
265 SDL_RemoveTrayEntry(new_example);
266 return;
267 }
268
269 SDL_SetTrayEntryCallback(new_ctrl_checked, set_entry_checked, new_example);
270
271 /* ---------- */
272
273 new_ctrl_unchecked = SDL_InsertTrayEntryAt(submenu, -1, "Uncheck", SDL_TRAYENTRY_BUTTON);
274
275 if (new_ctrl_unchecked == NULL) {
276 SDL_Log("Couldn't insert new_ctrl_unchecked: %s", SDL_GetError());
277 SDL_RemoveTrayEntry(new_ctrl);
278 SDL_RemoveTrayEntry(new_example);
279 return;
280 }
281
282 SDL_SetTrayEntryCallback(new_ctrl_unchecked, set_entry_unchecked, new_example);
283}
284
285static void SDLCALL append_separator_to(void *ptr, SDL_TrayEntry *entry)
286{
287 SDL_TrayMenu *menu = (SDL_TrayMenu *) ptr;
288 SDL_TrayMenu *submenu;
289 SDL_TrayEntry *new_ctrl;
290 SDL_TrayEntry *new_ctrl_remove;
291 SDL_TrayEntry *new_example;
292
293 new_ctrl = SDL_InsertTrayEntryAt(SDL_GetTrayEntryParent(entry), -1, "[Separator]", SDL_TRAYENTRY_SUBMENU);
294
295 if (!new_ctrl) {
296 SDL_Log("Couldn't insert entry in control tray: %s", SDL_GetError());
297 return;
298 }
299
300 /* ---------- */
301
302 submenu = SDL_CreateTraySubmenu(new_ctrl);
303
304 if (!new_ctrl) {
305 SDL_Log("Couldn't create control tray entry submenu: %s", SDL_GetError());
306 SDL_RemoveTrayEntry(new_ctrl);
307 return;
308 }
309
310 /* ---------- */
311
312 new_example = SDL_InsertTrayEntryAt(menu, -1, NULL, SDL_TRAYENTRY_BUTTON);
313
314 if (new_example == NULL) {
315 SDL_Log("Couldn't insert separator in example tray: %s", SDL_GetError());
316 SDL_RemoveTrayEntry(new_ctrl);
317 return;
318 }
319
320 /* ---------- */
321
322 new_ctrl_remove = SDL_InsertTrayEntryAt(submenu, -1, "Remove", SDL_TRAYENTRY_BUTTON);
323
324 if (new_ctrl_remove == NULL) {
325 SDL_Log("Couldn't insert new_ctrl_remove: %s", SDL_GetError());
326 SDL_RemoveTrayEntry(new_ctrl);
327 SDL_RemoveTrayEntry(new_example);
328 return;
329 }
330
331 SDL_SetTrayEntryCallback(new_ctrl_remove, remove_entry, new_example);
332}
333
334static void SDLCALL append_submenu_to(void *ptr, SDL_TrayEntry *entry)
335{
336 SDL_TrayMenu *menu = (SDL_TrayMenu *) ptr;
337 SDL_TrayMenu *submenu;
338 SDL_TrayMenu *entry_submenu;
339 SDL_TrayEntry *new_ctrl;
340 SDL_TrayEntry *new_ctrl_remove;
341 SDL_TrayEntry *new_ctrl_enabled;
342 SDL_TrayEntry *new_ctrl_disabled;
343 SDL_TrayEntry *new_example;
344
345 new_ctrl = SDL_InsertTrayEntryAt(SDL_GetTrayEntryParent(entry), -1, "New submenu", SDL_TRAYENTRY_SUBMENU);
346
347 if (!new_ctrl) {
348 SDL_Log("Couldn't insert entry in control tray: %s", SDL_GetError());
349 return;
350 }
351
352 /* ---------- */
353
354 submenu = SDL_CreateTraySubmenu(new_ctrl);
355
356 if (!new_ctrl) {
357 SDL_Log("Couldn't create control tray entry submenu: %s", SDL_GetError());
358 SDL_RemoveTrayEntry(new_ctrl);
359 return;
360 }
361
362 /* ---------- */
363
364 new_example = SDL_InsertTrayEntryAt(menu, -1, "New submenu", SDL_TRAYENTRY_SUBMENU);
365
366 if (new_example == NULL) {
367 SDL_Log("Couldn't insert entry in example tray: %s", SDL_GetError());
368 SDL_RemoveTrayEntry(new_ctrl);
369 return;
370 }
371
372 SDL_SetTrayEntryCallback(new_example, print_entry, NULL);
373
374 /* ---------- */
375
376 entry_submenu = SDL_CreateTraySubmenu(new_example);
377
378 if (entry_submenu == NULL) {
379 SDL_Log("Couldn't create new entry submenu: %s", SDL_GetError());
380 SDL_RemoveTrayEntry(new_ctrl);
381 SDL_RemoveTrayEntry(new_example);
382 return;
383 }
384
385 /* ---------- */
386
387 new_ctrl_remove = SDL_InsertTrayEntryAt(submenu, -1, "Remove", SDL_TRAYENTRY_BUTTON);
388
389 if (new_ctrl_remove == NULL) {
390 SDL_Log("Couldn't insert new_ctrl_remove: %s", SDL_GetError());
391 SDL_RemoveTrayEntry(new_ctrl);
392 SDL_RemoveTrayEntry(new_example);
393 return;
394 }
395
396 SDL_SetTrayEntryCallback(new_ctrl_remove, remove_entry, new_example);
397
398 /* ---------- */
399
400 new_ctrl_enabled = SDL_InsertTrayEntryAt(submenu, -1, "Enable", SDL_TRAYENTRY_BUTTON);
401
402 if (new_ctrl_enabled == NULL) {
403 SDL_Log("Couldn't insert new_ctrl_enabled: %s", SDL_GetError());
404 SDL_RemoveTrayEntry(new_ctrl);
405 SDL_RemoveTrayEntry(new_example);
406 return;
407 }
408
409 SDL_SetTrayEntryCallback(new_ctrl_enabled, set_entry_enabled, new_example);
410
411 /* ---------- */
412
413 new_ctrl_disabled = SDL_InsertTrayEntryAt(submenu, -1, "Disable", SDL_TRAYENTRY_BUTTON);
414
415 if (new_ctrl_disabled == NULL) {
416 SDL_Log("Couldn't insert new_ctrl_disabled: %s", SDL_GetError());
417 SDL_RemoveTrayEntry(new_ctrl);
418 SDL_RemoveTrayEntry(new_example);
419 return;
420 }
421
422 SDL_SetTrayEntryCallback(new_ctrl_disabled, set_entry_disabled, new_example);
423
424 /* ---------- */
425
426 SDL_InsertTrayEntryAt(submenu, -1, NULL, 0);
427
428 /* ---------- */
429
430 SDL_TrayEntry *entry_newbtn = SDL_InsertTrayEntryAt(submenu, -1, "Create button", SDL_TRAYENTRY_BUTTON);
431
432 if (entry_newbtn == NULL) {
433 SDL_Log("Couldn't insert entry_newbtn: %s", SDL_GetError());
434 SDL_RemoveTrayEntry(new_ctrl);
435 SDL_RemoveTrayEntry(new_example);
436 return;
437 }
438
439 SDL_SetTrayEntryCallback(entry_newbtn, append_button_to, entry_submenu);
440
441 /* ---------- */
442
443 SDL_TrayEntry *entry_newchk = SDL_InsertTrayEntryAt(submenu, -1, "Create checkbox", SDL_TRAYENTRY_BUTTON);
444
445 if (entry_newchk == NULL) {
446 SDL_Log("Couldn't insert entry_newchk: %s", SDL_GetError());
447 SDL_RemoveTrayEntry(new_ctrl);
448 SDL_RemoveTrayEntry(new_example);
449 return;
450 }
451
452 SDL_SetTrayEntryCallback(entry_newchk, append_checkbox_to, entry_submenu);
453
454 /* ---------- */
455
456 SDL_TrayEntry *entry_newsub = SDL_InsertTrayEntryAt(submenu, -1, "Create submenu", SDL_TRAYENTRY_BUTTON);
457
458 if (entry_newsub == NULL) {
459 SDL_Log("Couldn't insert entry_newsub: %s", SDL_GetError());
460 SDL_RemoveTrayEntry(new_ctrl);
461 SDL_RemoveTrayEntry(new_example);
462 return;
463 }
464
465 SDL_SetTrayEntryCallback(entry_newsub, append_submenu_to, entry_submenu);
466
467 /* ---------- */
468
469 SDL_TrayEntry *entry_newsep = SDL_InsertTrayEntryAt(submenu, -1, "Create separator", SDL_TRAYENTRY_BUTTON);
470
471 if (entry_newsep == NULL) {
472 SDL_Log("Couldn't insert entry_newsep: %s", SDL_GetError());
473 SDL_RemoveTrayEntry(new_ctrl);
474 SDL_RemoveTrayEntry(new_example);
475 return;
476 }
477
478 SDL_SetTrayEntryCallback(entry_newsep, append_separator_to, entry_submenu);
479
480 /* ---------- */
481
482 SDL_InsertTrayEntryAt(submenu, -1, NULL, 0);
483}
484
485int main(int argc, char **argv)
486{
487 SDL_Tray **trays = NULL;
488 SDLTest_CommonState *state;
489 int i;
490
491 /* Initialize test framework */
492 state = SDLTest_CommonCreateState(argv, 0);
493 if (state == NULL) {
494 return 1;
495 }
496
497 /* Parse commandline */
498 for (i = 1; i < argc;) {
499 int consumed;
500
501 consumed = SDLTest_CommonArg(state, i);
502
503 if (consumed <= 0) {
504 static const char *options[] = { NULL };
505 SDLTest_CommonLogUsage(state, argv[0], options);
506 return 1;
507 }
508
509 i += consumed;
510 }
511
512 if (!SDL_Init(SDL_INIT_VIDEO)) {
513 SDL_Log("SDL_Init failed (%s)", SDL_GetError());
514 return 1;
515 }
516
517 SDL_Window *w = SDL_CreateWindow("testtray", 640, 480, 0);
518
519 if (!w) {
520 SDL_Log("Couldn't create window: %s", SDL_GetError());
521 goto quit;
522 }
523
524 char *icon1filename = GetResourceFilename(NULL, "sdl-test_round.bmp");
525 SDL_Surface *icon = SDL_LoadBMP(icon1filename);
526 SDL_free(icon1filename);
527
528 if (!icon) {
529 SDL_Log("Couldn't load icon 1, proceeding without: %s", SDL_GetError());
530 }
531
532 char *icon2filename = GetResourceFilename(NULL, "speaker.bmp");
533 SDL_Surface *icon2 = SDL_LoadBMP(icon2filename);
534 SDL_free(icon2filename);
535
536 if (!icon2) {
537 SDL_Log("Couldn't load icon 2, proceeding without: %s", SDL_GetError());
538 }
539
540 SDL_Tray *tray = SDL_CreateTray(icon, "SDL Tray control menu");
541
542 if (!tray) {
543 SDL_Log("Couldn't create control tray: %s", SDL_GetError());
544 goto clean_window;
545 }
546
547 SDL_Tray *tray2 = SDL_CreateTray(icon2, "SDL Tray example");
548
549 if (!tray2) {
550 SDL_Log("Couldn't create example tray: %s", SDL_GetError());
551 goto clean_tray1;
552 }
553
554 SDL_DestroySurface(icon);
555 SDL_DestroySurface(icon2);
556
557#define CHECK(name) \
558 if (!name) { \
559 SDL_Log("Couldn't create " #name ": %s", SDL_GetError()); \
560 goto clean_all; \
561 }
562
563 SDL_TrayMenu *menu = SDL_CreateTrayMenu(tray);
564 CHECK(menu);
565
566 SDL_TrayMenu *menu2 = SDL_CreateTrayMenu(tray2);
567 CHECK(menu2);
568
569 SDL_TrayEntry *entry_quit = SDL_InsertTrayEntryAt(menu, -1, "Quit", SDL_TRAYENTRY_BUTTON);
570 CHECK(entry_quit);
571
572 SDL_TrayEntry *entry_close = SDL_InsertTrayEntryAt(menu, -1, "Close", SDL_TRAYENTRY_BUTTON);
573 CHECK(entry_close);
574
575 /* TODO: Track memory! */
576 trays = SDL_malloc(sizeof(SDL_Tray *) * 2);
577 if (!trays) {
578 goto clean_all;
579 }
580
581 trays[0] = tray;
582 trays[1] = tray2;
583
584 SDL_SetTrayEntryCallback(entry_quit, tray_quit, NULL);
585 SDL_SetTrayEntryCallback(entry_close, tray_close, trays);
586
587 SDL_InsertTrayEntryAt(menu, -1, NULL, 0);
588
589 SDL_TrayEntry *entry_icon = SDL_InsertTrayEntryAt(menu, -1, "Change icon", SDL_TRAYENTRY_BUTTON);
590 CHECK(entry_icon);
591
592 SDL_SetTrayEntryCallback(entry_icon, change_icon, tray2);
593
594 SDL_InsertTrayEntryAt(menu, -1, NULL, 0);
595
596 SDL_TrayEntry *entry_newbtn = SDL_InsertTrayEntryAt(menu, -1, "Create button", SDL_TRAYENTRY_BUTTON);
597 CHECK(entry_newbtn);
598
599 SDL_SetTrayEntryCallback(entry_newbtn, append_button_to, menu2);
600
601 SDL_TrayEntry *entry_newchk = SDL_InsertTrayEntryAt(menu, -1, "Create checkbox", SDL_TRAYENTRY_BUTTON);
602 CHECK(entry_newchk);
603
604 SDL_SetTrayEntryCallback(entry_newchk, append_checkbox_to, menu2);
605
606 SDL_TrayEntry *entry_newsub = SDL_InsertTrayEntryAt(menu, -1, "Create submenu", SDL_TRAYENTRY_BUTTON);
607 CHECK(entry_newsub);
608
609 SDL_SetTrayEntryCallback(entry_newsub, append_submenu_to, menu2);
610
611 SDL_TrayEntry *entry_newsep = SDL_InsertTrayEntryAt(menu, -1, "Create separator", SDL_TRAYENTRY_BUTTON);
612 CHECK(entry_newsep);
613
614 SDL_SetTrayEntryCallback(entry_newsep, append_separator_to, menu2);
615
616 SDL_InsertTrayEntryAt(menu, -1, NULL, 0);
617
618 SDL_Event e;
619 while (SDL_WaitEvent(&e)) {
620 if (e.type == SDL_EVENT_QUIT) {
621 break;
622 } else if (e.type == SDL_EVENT_WINDOW_CLOSE_REQUESTED) {
623 SDL_DestroyWindow(w);
624 w = NULL;
625 }
626 }
627
628clean_all:
629 if (!trays_destroyed) {
630 SDL_DestroyTray(tray2);
631 }
632
633clean_tray1:
634 if (!trays_destroyed) {
635 SDL_DestroyTray(tray);
636 }
637 SDL_free(trays);
638
639clean_window:
640 if (w) {
641 SDL_DestroyWindow(w);
642 }
643
644quit:
645 SDL_Quit();
646 SDLTest_CommonDestroyState(state);
647
648 return 0;
649}