testtray.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599
  1. #include <SDL3/SDL.h>
  2. #include <SDL3/SDL_main.h>
  3. #include <SDL3/SDL_test.h>
  4. static void SDLCALL tray_quit(void *ptr, SDL_TrayEntry *entry)
  5. {
  6. SDL_Event e;
  7. e.type = SDL_EVENT_QUIT;
  8. SDL_PushEvent(&e);
  9. }
  10. static void SDLCALL apply_icon(void *ptr, const char * const *filelist, int filter)
  11. {
  12. if (!*filelist) {
  13. return;
  14. }
  15. SDL_Surface *icon = SDL_LoadBMP(*filelist);
  16. if (!icon) {
  17. SDL_Log("Couldn't load icon '%s': %s", *filelist, SDL_GetError());
  18. return;
  19. }
  20. SDL_Tray *tray = (SDL_Tray *) ptr;
  21. SDL_SetTrayIcon(tray, icon);
  22. SDL_DestroySurface(icon);
  23. }
  24. static void SDLCALL change_icon(void *ptr, SDL_TrayEntry *entry)
  25. {
  26. SDL_DialogFileFilter filters[] = {
  27. { "BMP image files", "bmp" },
  28. { "All files", "*" },
  29. };
  30. SDL_ShowOpenFileDialog(apply_icon, ptr, NULL, filters, 2, NULL, 0);
  31. }
  32. static void SDLCALL print_entry(void *ptr, SDL_TrayEntry *entry)
  33. {
  34. SDL_Log("Clicked on button '%s'\n", SDL_GetTrayEntryLabel(entry));
  35. }
  36. static void SDLCALL set_entry_enabled(void *ptr, SDL_TrayEntry *entry)
  37. {
  38. SDL_TrayEntry *target = (SDL_TrayEntry *) ptr;
  39. SDL_SetTrayEntryEnabled(target, true);
  40. }
  41. static void SDLCALL set_entry_disabled(void *ptr, SDL_TrayEntry *entry)
  42. {
  43. SDL_TrayEntry *target = (SDL_TrayEntry *) ptr;
  44. SDL_SetTrayEntryEnabled(target, false);
  45. }
  46. static void SDLCALL set_entry_checked(void *ptr, SDL_TrayEntry *entry)
  47. {
  48. SDL_TrayEntry *target = (SDL_TrayEntry *) ptr;
  49. SDL_SetTrayEntryChecked(target, true);
  50. }
  51. static void SDLCALL set_entry_unchecked(void *ptr, SDL_TrayEntry *entry)
  52. {
  53. SDL_TrayEntry *target = (SDL_TrayEntry *) ptr;
  54. SDL_SetTrayEntryChecked(target, false);
  55. }
  56. static void SDLCALL remove_entry(void *ptr, SDL_TrayEntry *entry)
  57. {
  58. SDL_TrayEntry *target = (SDL_TrayEntry *) ptr;
  59. SDL_RemoveTrayEntry(target);
  60. SDL_TrayMenu *ctrl_submenu = SDL_GetTrayEntryParent(entry);
  61. SDL_TrayEntry *ctrl_entry = SDL_GetTrayMenuParentEntry(ctrl_submenu);
  62. if (!ctrl_entry) {
  63. SDL_Log("Attempt to remove a menu that isn't a submenu. This shouldn't happen.\n");
  64. return;
  65. }
  66. SDL_RemoveTrayEntry(ctrl_entry);
  67. }
  68. static void SDLCALL append_button_to(void *ptr, SDL_TrayEntry *entry)
  69. {
  70. SDL_TrayMenu *menu = (SDL_TrayMenu *) ptr;
  71. SDL_TrayMenu *submenu;
  72. SDL_TrayEntry *new_ctrl;
  73. SDL_TrayEntry *new_ctrl_remove;
  74. SDL_TrayEntry *new_ctrl_enabled;
  75. SDL_TrayEntry *new_ctrl_disabled;
  76. SDL_TrayEntry *new_example;
  77. new_ctrl = SDL_InsertTrayEntryAt(SDL_GetTrayEntryParent(entry), -1, "New button", SDL_TRAYENTRY_SUBMENU);
  78. if (!new_ctrl) {
  79. SDL_Log("Couldn't insert entry in control tray: %s\n", SDL_GetError());
  80. return;
  81. }
  82. /* ---------- */
  83. submenu = SDL_CreateTraySubmenu(new_ctrl);
  84. if (!new_ctrl) {
  85. SDL_Log("Couldn't create control tray entry submenu: %s\n", SDL_GetError());
  86. SDL_RemoveTrayEntry(new_ctrl);
  87. return;
  88. }
  89. /* ---------- */
  90. new_example = SDL_InsertTrayEntryAt(menu, -1, "New button", SDL_TRAYENTRY_BUTTON);
  91. if (new_example == NULL) {
  92. SDL_Log("Couldn't insert entry in example tray: %s\n", SDL_GetError());
  93. SDL_RemoveTrayEntry(new_ctrl);
  94. return;
  95. }
  96. SDL_SetTrayEntryCallback(new_example, print_entry, NULL);
  97. /* ---------- */
  98. new_ctrl_remove = SDL_InsertTrayEntryAt(submenu, -1, "Remove", SDL_TRAYENTRY_BUTTON);
  99. if (new_ctrl_remove == NULL) {
  100. SDL_Log("Couldn't insert new_ctrl_remove: %s\n", SDL_GetError());
  101. SDL_RemoveTrayEntry(new_ctrl);
  102. SDL_RemoveTrayEntry(new_example);
  103. return;
  104. }
  105. SDL_SetTrayEntryCallback(new_ctrl_remove, remove_entry, new_example);
  106. /* ---------- */
  107. new_ctrl_enabled = SDL_InsertTrayEntryAt(submenu, -1, "Enable", SDL_TRAYENTRY_BUTTON);
  108. if (new_ctrl_enabled == NULL) {
  109. SDL_Log("Couldn't insert new_ctrl_enabled: %s\n", SDL_GetError());
  110. SDL_RemoveTrayEntry(new_ctrl);
  111. SDL_RemoveTrayEntry(new_example);
  112. return;
  113. }
  114. SDL_SetTrayEntryCallback(new_ctrl_enabled, set_entry_enabled, new_example);
  115. /* ---------- */
  116. new_ctrl_disabled = SDL_InsertTrayEntryAt(submenu, -1, "Disable", SDL_TRAYENTRY_BUTTON);
  117. if (new_ctrl_disabled == NULL) {
  118. SDL_Log("Couldn't insert new_ctrl_disabled: %s\n", SDL_GetError());
  119. SDL_RemoveTrayEntry(new_ctrl);
  120. SDL_RemoveTrayEntry(new_example);
  121. return;
  122. }
  123. SDL_SetTrayEntryCallback(new_ctrl_disabled, set_entry_disabled, new_example);
  124. }
  125. static void SDLCALL append_checkbox_to(void *ptr, SDL_TrayEntry *entry)
  126. {
  127. SDL_TrayMenu *menu = (SDL_TrayMenu *) ptr;
  128. SDL_TrayMenu *submenu;
  129. SDL_TrayEntry *new_ctrl;
  130. SDL_TrayEntry *new_ctrl_remove;
  131. SDL_TrayEntry *new_ctrl_enabled;
  132. SDL_TrayEntry *new_ctrl_disabled;
  133. SDL_TrayEntry *new_ctrl_checked;
  134. SDL_TrayEntry *new_ctrl_unchecked;
  135. SDL_TrayEntry *new_example;
  136. new_ctrl = SDL_InsertTrayEntryAt(SDL_GetTrayEntryParent(entry), -1, "New checkbox", SDL_TRAYENTRY_SUBMENU);
  137. if (!new_ctrl) {
  138. SDL_Log("Couldn't insert entry in control tray: %s\n", SDL_GetError());
  139. return;
  140. }
  141. /* ---------- */
  142. submenu = SDL_CreateTraySubmenu(new_ctrl);
  143. if (!new_ctrl) {
  144. SDL_Log("Couldn't create control tray entry submenu: %s\n", SDL_GetError());
  145. SDL_RemoveTrayEntry(new_ctrl);
  146. return;
  147. }
  148. /* ---------- */
  149. new_example = SDL_InsertTrayEntryAt(menu, -1, "New checkbox", SDL_TRAYENTRY_CHECKBOX);
  150. if (new_example == NULL) {
  151. SDL_Log("Couldn't insert entry in example tray: %s\n", SDL_GetError());
  152. SDL_RemoveTrayEntry(new_ctrl);
  153. return;
  154. }
  155. SDL_SetTrayEntryCallback(new_example, print_entry, NULL);
  156. /* ---------- */
  157. new_ctrl_remove = SDL_InsertTrayEntryAt(submenu, -1, "Remove", SDL_TRAYENTRY_BUTTON);
  158. if (new_ctrl_remove == NULL) {
  159. SDL_Log("Couldn't insert new_ctrl_remove: %s\n", SDL_GetError());
  160. SDL_RemoveTrayEntry(new_ctrl);
  161. SDL_RemoveTrayEntry(new_example);
  162. return;
  163. }
  164. SDL_SetTrayEntryCallback(new_ctrl_remove, remove_entry, new_example);
  165. /* ---------- */
  166. new_ctrl_enabled = SDL_InsertTrayEntryAt(submenu, -1, "Enable", SDL_TRAYENTRY_BUTTON);
  167. if (new_ctrl_enabled == NULL) {
  168. SDL_Log("Couldn't insert new_ctrl_enabled: %s\n", SDL_GetError());
  169. SDL_RemoveTrayEntry(new_ctrl);
  170. SDL_RemoveTrayEntry(new_example);
  171. return;
  172. }
  173. SDL_SetTrayEntryCallback(new_ctrl_enabled, set_entry_enabled, new_example);
  174. /* ---------- */
  175. new_ctrl_disabled = SDL_InsertTrayEntryAt(submenu, -1, "Disable", SDL_TRAYENTRY_BUTTON);
  176. if (new_ctrl_disabled == NULL) {
  177. SDL_Log("Couldn't insert new_ctrl_disabled: %s\n", SDL_GetError());
  178. SDL_RemoveTrayEntry(new_ctrl);
  179. SDL_RemoveTrayEntry(new_example);
  180. return;
  181. }
  182. SDL_SetTrayEntryCallback(new_ctrl_disabled, set_entry_disabled, new_example);
  183. /* ---------- */
  184. new_ctrl_checked = SDL_InsertTrayEntryAt(submenu, -1, "Check", SDL_TRAYENTRY_BUTTON);
  185. if (new_ctrl_checked == NULL) {
  186. SDL_Log("Couldn't insert new_ctrl_checked: %s\n", SDL_GetError());
  187. SDL_RemoveTrayEntry(new_ctrl);
  188. SDL_RemoveTrayEntry(new_example);
  189. return;
  190. }
  191. SDL_SetTrayEntryCallback(new_ctrl_checked, set_entry_checked, new_example);
  192. /* ---------- */
  193. new_ctrl_unchecked = SDL_InsertTrayEntryAt(submenu, -1, "Uncheck", SDL_TRAYENTRY_BUTTON);
  194. if (new_ctrl_unchecked == NULL) {
  195. SDL_Log("Couldn't insert new_ctrl_unchecked: %s\n", SDL_GetError());
  196. SDL_RemoveTrayEntry(new_ctrl);
  197. SDL_RemoveTrayEntry(new_example);
  198. return;
  199. }
  200. SDL_SetTrayEntryCallback(new_ctrl_unchecked, set_entry_unchecked, new_example);
  201. }
  202. static void SDLCALL append_separator_to(void *ptr, SDL_TrayEntry *entry)
  203. {
  204. SDL_TrayMenu *menu = (SDL_TrayMenu *) ptr;
  205. SDL_TrayMenu *submenu;
  206. SDL_TrayEntry *new_ctrl;
  207. SDL_TrayEntry *new_ctrl_remove;
  208. SDL_TrayEntry *new_example;
  209. new_ctrl = SDL_InsertTrayEntryAt(SDL_GetTrayEntryParent(entry), -1, "[Separator]", SDL_TRAYENTRY_SUBMENU);
  210. if (!new_ctrl) {
  211. SDL_Log("Couldn't insert entry in control tray: %s\n", SDL_GetError());
  212. return;
  213. }
  214. /* ---------- */
  215. submenu = SDL_CreateTraySubmenu(new_ctrl);
  216. if (!new_ctrl) {
  217. SDL_Log("Couldn't create control tray entry submenu: %s\n", SDL_GetError());
  218. SDL_RemoveTrayEntry(new_ctrl);
  219. return;
  220. }
  221. /* ---------- */
  222. new_example = SDL_InsertTrayEntryAt(menu, -1, NULL, SDL_TRAYENTRY_BUTTON);
  223. if (new_example == NULL) {
  224. SDL_Log("Couldn't insert separator in example tray: %s\n", SDL_GetError());
  225. SDL_RemoveTrayEntry(new_ctrl);
  226. return;
  227. }
  228. /* ---------- */
  229. new_ctrl_remove = SDL_InsertTrayEntryAt(submenu, -1, "Remove", SDL_TRAYENTRY_BUTTON);
  230. if (new_ctrl_remove == NULL) {
  231. SDL_Log("Couldn't insert new_ctrl_remove: %s\n", SDL_GetError());
  232. SDL_RemoveTrayEntry(new_ctrl);
  233. SDL_RemoveTrayEntry(new_example);
  234. return;
  235. }
  236. SDL_SetTrayEntryCallback(new_ctrl_remove, remove_entry, new_example);
  237. }
  238. static void SDLCALL append_submenu_to(void *ptr, SDL_TrayEntry *entry)
  239. {
  240. SDL_TrayMenu *menu = (SDL_TrayMenu *) ptr;
  241. SDL_TrayMenu *submenu;
  242. SDL_TrayMenu *entry_submenu;
  243. SDL_TrayEntry *new_ctrl;
  244. SDL_TrayEntry *new_ctrl_remove;
  245. SDL_TrayEntry *new_ctrl_enabled;
  246. SDL_TrayEntry *new_ctrl_disabled;
  247. SDL_TrayEntry *new_example;
  248. new_ctrl = SDL_InsertTrayEntryAt(SDL_GetTrayEntryParent(entry), -1, "New submenu", SDL_TRAYENTRY_SUBMENU);
  249. if (!new_ctrl) {
  250. SDL_Log("Couldn't insert entry in control tray: %s\n", SDL_GetError());
  251. return;
  252. }
  253. /* ---------- */
  254. submenu = SDL_CreateTraySubmenu(new_ctrl);
  255. if (!new_ctrl) {
  256. SDL_Log("Couldn't create control tray entry submenu: %s\n", SDL_GetError());
  257. SDL_RemoveTrayEntry(new_ctrl);
  258. return;
  259. }
  260. /* ---------- */
  261. new_example = SDL_InsertTrayEntryAt(menu, -1, "New submenu", SDL_TRAYENTRY_SUBMENU);
  262. if (new_example == NULL) {
  263. SDL_Log("Couldn't insert entry in example tray: %s\n", SDL_GetError());
  264. SDL_RemoveTrayEntry(new_ctrl);
  265. return;
  266. }
  267. SDL_SetTrayEntryCallback(new_example, print_entry, NULL);
  268. /* ---------- */
  269. entry_submenu = SDL_CreateTraySubmenu(new_example);
  270. if (entry_submenu == NULL) {
  271. SDL_Log("Couldn't create new entry submenu: %s\n", SDL_GetError());
  272. SDL_RemoveTrayEntry(new_ctrl);
  273. SDL_RemoveTrayEntry(new_example);
  274. return;
  275. }
  276. /* ---------- */
  277. new_ctrl_remove = SDL_InsertTrayEntryAt(submenu, -1, "Remove", SDL_TRAYENTRY_BUTTON);
  278. if (new_ctrl_remove == NULL) {
  279. SDL_Log("Couldn't insert new_ctrl_remove: %s\n", SDL_GetError());
  280. SDL_RemoveTrayEntry(new_ctrl);
  281. SDL_RemoveTrayEntry(new_example);
  282. return;
  283. }
  284. SDL_SetTrayEntryCallback(new_ctrl_remove, remove_entry, new_example);
  285. /* ---------- */
  286. new_ctrl_enabled = SDL_InsertTrayEntryAt(submenu, -1, "Enable", SDL_TRAYENTRY_BUTTON);
  287. if (new_ctrl_enabled == NULL) {
  288. SDL_Log("Couldn't insert new_ctrl_enabled: %s\n", SDL_GetError());
  289. SDL_RemoveTrayEntry(new_ctrl);
  290. SDL_RemoveTrayEntry(new_example);
  291. return;
  292. }
  293. SDL_SetTrayEntryCallback(new_ctrl_enabled, set_entry_enabled, new_example);
  294. /* ---------- */
  295. new_ctrl_disabled = SDL_InsertTrayEntryAt(submenu, -1, "Disable", SDL_TRAYENTRY_BUTTON);
  296. if (new_ctrl_disabled == NULL) {
  297. SDL_Log("Couldn't insert new_ctrl_disabled: %s\n", SDL_GetError());
  298. SDL_RemoveTrayEntry(new_ctrl);
  299. SDL_RemoveTrayEntry(new_example);
  300. return;
  301. }
  302. SDL_SetTrayEntryCallback(new_ctrl_disabled, set_entry_disabled, new_example);
  303. /* ---------- */
  304. SDL_InsertTrayEntryAt(submenu, -1, NULL, 0);
  305. /* ---------- */
  306. SDL_TrayEntry *entry_newbtn = SDL_InsertTrayEntryAt(submenu, -1, "Create button", SDL_TRAYENTRY_BUTTON);
  307. if (entry_newbtn == NULL) {
  308. SDL_Log("Couldn't insert entry_newbtn: %s\n", SDL_GetError());
  309. SDL_RemoveTrayEntry(new_ctrl);
  310. SDL_RemoveTrayEntry(new_example);
  311. return;
  312. }
  313. SDL_SetTrayEntryCallback(entry_newbtn, append_button_to, entry_submenu);
  314. /* ---------- */
  315. SDL_TrayEntry *entry_newchk = SDL_InsertTrayEntryAt(submenu, -1, "Create checkbox", SDL_TRAYENTRY_BUTTON);
  316. if (entry_newchk == NULL) {
  317. SDL_Log("Couldn't insert entry_newchk: %s\n", SDL_GetError());
  318. SDL_RemoveTrayEntry(new_ctrl);
  319. SDL_RemoveTrayEntry(new_example);
  320. return;
  321. }
  322. SDL_SetTrayEntryCallback(entry_newchk, append_checkbox_to, entry_submenu);
  323. /* ---------- */
  324. SDL_TrayEntry *entry_newsub = SDL_InsertTrayEntryAt(submenu, -1, "Create submenu", SDL_TRAYENTRY_BUTTON);
  325. if (entry_newsub == NULL) {
  326. SDL_Log("Couldn't insert entry_newsub: %s\n", SDL_GetError());
  327. SDL_RemoveTrayEntry(new_ctrl);
  328. SDL_RemoveTrayEntry(new_example);
  329. return;
  330. }
  331. SDL_SetTrayEntryCallback(entry_newsub, append_submenu_to, entry_submenu);
  332. /* ---------- */
  333. SDL_TrayEntry *entry_newsep = SDL_InsertTrayEntryAt(submenu, -1, "Create separator", SDL_TRAYENTRY_BUTTON);
  334. if (entry_newsep == NULL) {
  335. SDL_Log("Couldn't insert entry_newsep: %s\n", SDL_GetError());
  336. SDL_RemoveTrayEntry(new_ctrl);
  337. SDL_RemoveTrayEntry(new_example);
  338. return;
  339. }
  340. SDL_SetTrayEntryCallback(entry_newsep, append_separator_to, entry_submenu);
  341. /* ---------- */
  342. SDL_InsertTrayEntryAt(submenu, -1, NULL, 0);
  343. }
  344. int main(int argc, char **argv)
  345. {
  346. SDLTest_CommonState *state;
  347. int i;
  348. /* Initialize test framework */
  349. state = SDLTest_CommonCreateState(argv, 0);
  350. if (state == NULL) {
  351. return 1;
  352. }
  353. /* Parse commandline */
  354. for (i = 1; i < argc;) {
  355. int consumed;
  356. consumed = SDLTest_CommonArg(state, i);
  357. if (consumed <= 0) {
  358. static const char *options[] = { NULL };
  359. SDLTest_CommonLogUsage(state, argv[0], options);
  360. return 1;
  361. }
  362. i += consumed;
  363. }
  364. if (!SDL_Init(SDL_INIT_VIDEO)) {
  365. SDL_Log("SDL_Init failed (%s)", SDL_GetError());
  366. return 1;
  367. }
  368. /* TODO: Resource paths? */
  369. SDL_Surface *icon = SDL_LoadBMP("../test/sdl-test_round.bmp");
  370. if (!icon) {
  371. SDL_Log("Couldn't load icon 1, proceeding without: %s", SDL_GetError());
  372. }
  373. SDL_Surface *icon2 = SDL_LoadBMP("../test/speaker.bmp");
  374. if (!icon2) {
  375. SDL_Log("Couldn't load icon 2, proceeding without: %s", SDL_GetError());
  376. }
  377. SDL_Tray *tray = SDL_CreateTray(icon, "SDL Tray control menu");
  378. if (!tray) {
  379. SDL_Log("Couldn't create control tray: %s", SDL_GetError());
  380. goto quit;
  381. }
  382. SDL_Tray *tray2 = SDL_CreateTray(icon2, "SDL Tray example");
  383. if (!tray2) {
  384. SDL_Log("Couldn't create example tray: %s", SDL_GetError());
  385. goto clean_tray1;
  386. }
  387. SDL_DestroySurface(icon);
  388. SDL_DestroySurface(icon2);
  389. #define CHECK(name) \
  390. if (!name) { \
  391. SDL_Log("Couldn't create " #name ": %s", SDL_GetError()); \
  392. goto clean_all; \
  393. }
  394. SDL_TrayMenu *menu = SDL_CreateTrayMenu(tray);
  395. CHECK(menu);
  396. SDL_TrayMenu *menu2 = SDL_CreateTrayMenu(tray2);
  397. CHECK(menu2);
  398. SDL_TrayEntry *entry_quit = SDL_InsertTrayEntryAt(menu, -1, "Quit", SDL_TRAYENTRY_BUTTON);
  399. CHECK(entry_quit);
  400. SDL_SetTrayEntryCallback(entry_quit, tray_quit, NULL);
  401. SDL_InsertTrayEntryAt(menu, -1, NULL, 0);
  402. SDL_TrayEntry *entry_icon = SDL_InsertTrayEntryAt(menu, -1, "Change icon", SDL_TRAYENTRY_BUTTON);
  403. CHECK(entry_icon);
  404. SDL_SetTrayEntryCallback(entry_icon, change_icon, tray2);
  405. SDL_InsertTrayEntryAt(menu, -1, NULL, 0);
  406. SDL_TrayEntry *entry_newbtn = SDL_InsertTrayEntryAt(menu, -1, "Create button", SDL_TRAYENTRY_BUTTON);
  407. CHECK(entry_newbtn);
  408. SDL_SetTrayEntryCallback(entry_newbtn, append_button_to, menu2);
  409. SDL_TrayEntry *entry_newchk = SDL_InsertTrayEntryAt(menu, -1, "Create checkbox", SDL_TRAYENTRY_BUTTON);
  410. CHECK(entry_newchk);
  411. SDL_SetTrayEntryCallback(entry_newchk, append_checkbox_to, menu2);
  412. SDL_TrayEntry *entry_newsub = SDL_InsertTrayEntryAt(menu, -1, "Create submenu", SDL_TRAYENTRY_BUTTON);
  413. CHECK(entry_newsub);
  414. SDL_SetTrayEntryCallback(entry_newsub, append_submenu_to, menu2);
  415. SDL_TrayEntry *entry_newsep = SDL_InsertTrayEntryAt(menu, -1, "Create separator", SDL_TRAYENTRY_BUTTON);
  416. CHECK(entry_newsep);
  417. SDL_SetTrayEntryCallback(entry_newsep, append_separator_to, menu2);
  418. SDL_InsertTrayEntryAt(menu, -1, NULL, 0);
  419. SDL_Event e;
  420. while (SDL_WaitEvent(&e)) {
  421. if (e.type == SDL_EVENT_QUIT) {
  422. break;
  423. }
  424. }
  425. clean_all:
  426. SDL_DestroyTray(tray2);
  427. clean_tray1:
  428. SDL_DestroyTray(tray);
  429. quit:
  430. SDL_Quit();
  431. SDLTest_CommonDestroyState(state);
  432. return 0;
  433. }