testtray.c 18 KB

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