Files
kaizen/external/SDL/test/testtray.c
T
iris 00cc9309cb Squashed 'external/ircolib/' changes from ce3cd726c..de6e324bd
de6e324bd separate emu thread
10d3daf86 Roms List improvements
95d202f37 Let's make the rom list process on a separate thread so the emulator doesnt take ages to load.
fc306967f Wow the ROM Header was just completely busted. Game list view works now
bad1691ee fuck this shit
2b59e5f46 game list in progress
d26417b83 remappable inputs in progress
ac4af8106 input
e72abc240 update readme
430139dc9 Qt6 frontend
3080d4d45 Fix this small bug too
08cd13b85 Cop0 unused functions do not actually pose a threat (as per manual). They don't do anything, so shall we.
61bb4fb44 make idle loop detection a little more specific with where the load goes
b037de4c3 SAZDFsdff
12e81e73e need to figure out why n64-systemtest loops indefinitely at some address that appears to be valid (i think it's me not invalidating the cache properly)
204f0e13b idle skipping seems to work!
cb8bb634a sdkfjlasdf
58e5c89c1 Fix compilation issue on my machine (no idea)
24fb2898e attempting more serious idle skipping
214719577 Place rsp.Step inside cached interpreter. Gains about 3 more fps
bb97dcc23 mmmmm
920b77d38 wjkhasdfjhkasdf
430ccdab4 it's a start...
4f42a673a Cached interpreter plays Mario 64. Start looking into RSP as well
c9a030787 idle skipping works!
5fbda03ce new idea
366637aba Idle skipping... maybe?
609fa2fb0 Cache instructions implemented but broken lmao. Commented out for now
e140a6d12 - Stop using inheritance for CPU, instead use composition. - Introduce KAIZEN_JIT_ENABLED optional define instead of relying on __aarch64__ and the like. - More cache work
68e613057 prep cache impl
811b4d809 fix clang format
fda755f7d idk
d5024ebbf small MI refactor in preparation of (eventually) implementing the RDRAM interface properly
694b45341 Merge commit '206dcdedf195fb320913584180edb12c7731e396' as 'external/SDL'
206dcdedf Squashed 'external/SDL/' content from commit 4d17b99d0a
4d16e1cb4 need to update sdl
848b19920 Fix compilation error
db61b5299 Merge commit 'e94a94559f28e49678fbcf72199a5258137b0fe9' as 'external/imgui'
e94a94559 Squashed 'external/imgui/' content from commit 02e9b8cac
52edb3757 need to update imgui
c1a705e86 Emulate weird JALR behaviour
4b4c32f4b Fix exception for "unusable COP1" in 4 instructions i missed accidentally (again)
df5828142 Bug putting 0s in the log everywhere
f8b580048 Make isviewer a sink to file
8241e9735 Fix exception for "unusable COP1" in 4 instructions i missed accidentally
b29715f20 small changes
d9a620bc1 make use of my new small utility library
0d1aa938e Add 'external/ircolib/' from commit 'ce3cd726c8df8388d554abf8bb55d55020eb4450'
e64eb40b3 Fuck git

git-subtree-dir: external/ircolib
git-subtree-split: de6e324bde
2026-06-15 11:56:38 +02:00

731 lines
21 KiB
C

#include "testutils.h"
#include <SDL3/SDL.h>
#include <SDL3/SDL_main.h>
#include <SDL3/SDL_test.h>
/*
* testtray - SDL system tray API test application
*
* This program creates two system tray icons to demonstrate and test the
* SDL tray API:
*
* 1. Control tray (sdl-test_round.png) - Provides a menu to:
* - Quit: Exit the application
* - Destroy trays: Remove both tray icons and show the window
* - Hide/Show window: Toggle the window visibility
* - Change icon: Change the example tray's icon via file dialog
* - Create button/checkbox/submenu/separator: Add menu items to the
* example tray, demonstrating dynamic menu construction
*
* 2. Example tray (speaker.png) - A target tray that can be manipulated
* through the control tray's menu. Menu items created here can be
* enabled, disabled, checked, unchecked, or removed via submenus that
* appear in the control tray. This tray is created with
* SDL_CreateTrayWithProperties to demonstrate click callbacks:
* - Left click: Logs a message and shows the menu (returns true)
* - Right click: Logs a message and suppresses the menu (returns false)
* - Middle click: Logs a message (menu never shows for middle click)
*
* Window behavior:
* - Closing the window (X button) hides it to the tray rather than exiting
* - The "Hide/Show window" menu item toggles visibility and updates its label
* - If trays are destroyed while the window is hidden, it is shown first
* - If trays are destroyed, closing the window exits the application
*/
static void SDLCALL tray_quit(void *ptr, SDL_TrayEntry *entry)
{
SDL_Event e;
e.type = SDL_EVENT_QUIT;
SDL_PushEvent(&e);
}
static bool SDLCALL tray2_leftclick(void *userdata, SDL_Tray *tray)
{
SDL_Log("Left click on example tray - menu shown");
return true;
}
static bool SDLCALL tray2_rightclick(void *userdata, SDL_Tray *tray)
{
SDL_Log("Right click on example tray - menu suppressed");
return false;
}
static bool SDLCALL tray2_middleclick(void *userdata, SDL_Tray *tray)
{
SDL_Log("Middle click on example tray - menu doesn't show for middle click");
return false;
}
static bool trays_destroyed = false;
static SDL_Window *window = NULL;
static SDL_TrayEntry *entry_toggle = NULL;
static void SDLCALL tray_close(void *ptr, SDL_TrayEntry *entry)
{
SDL_Tray **trays = (SDL_Tray **) ptr;
trays_destroyed = true;
if (window) {
SDL_ShowWindow(window);
}
SDL_DestroyTray(trays[0]);
SDL_DestroyTray(trays[1]);
}
static void SDLCALL toggle_window(void *ptr, SDL_TrayEntry *entry)
{
if (SDL_GetWindowFlags(window) & SDL_WINDOW_HIDDEN) {
SDL_ShowWindow(window);
SDL_SetTrayEntryLabel(entry, "Hide window");
} else {
SDL_HideWindow(window);
SDL_SetTrayEntryLabel(entry, "Show window");
}
}
static void SDLCALL apply_icon(void *ptr, const char * const *filelist, int filter)
{
if (!*filelist) {
return;
}
SDL_Surface *icon = SDL_LoadPNG(*filelist);
if (!icon) {
SDL_Log("Couldn't load icon '%s': %s", *filelist, SDL_GetError());
return;
}
SDL_Tray *tray = (SDL_Tray *) ptr;
SDL_SetTrayIcon(tray, icon);
SDL_DestroySurface(icon);
}
static void SDLCALL change_icon(void *ptr, SDL_TrayEntry *entry)
{
SDL_DialogFileFilter filters[] = {
{ "PNG image files", "png" },
{ "All files", "*" },
};
SDL_ShowOpenFileDialog(apply_icon, ptr, NULL, filters, 2, NULL, 0);
}
static void SDLCALL print_entry(void *ptr, SDL_TrayEntry *entry)
{
SDL_Log("Clicked on button '%s'", SDL_GetTrayEntryLabel(entry));
}
static void SDLCALL set_entry_enabled(void *ptr, SDL_TrayEntry *entry)
{
SDL_TrayEntry *target = (SDL_TrayEntry *) ptr;
SDL_SetTrayEntryEnabled(target, true);
}
static void SDLCALL set_entry_disabled(void *ptr, SDL_TrayEntry *entry)
{
SDL_TrayEntry *target = (SDL_TrayEntry *) ptr;
SDL_SetTrayEntryEnabled(target, false);
}
static void SDLCALL set_entry_checked(void *ptr, SDL_TrayEntry *entry)
{
SDL_TrayEntry *target = (SDL_TrayEntry *) ptr;
SDL_SetTrayEntryChecked(target, true);
}
static void SDLCALL set_entry_unchecked(void *ptr, SDL_TrayEntry *entry)
{
SDL_TrayEntry *target = (SDL_TrayEntry *) ptr;
SDL_SetTrayEntryChecked(target, false);
}
static void SDLCALL remove_entry(void *ptr, SDL_TrayEntry *entry)
{
SDL_TrayEntry *target = (SDL_TrayEntry *) ptr;
SDL_RemoveTrayEntry(target);
SDL_TrayMenu *ctrl_submenu = SDL_GetTrayEntryParent(entry);
SDL_TrayEntry *ctrl_entry = SDL_GetTrayMenuParentEntry(ctrl_submenu);
if (!ctrl_entry) {
SDL_Log("Attempt to remove a menu that isn't a submenu. This shouldn't happen.");
return;
}
SDL_RemoveTrayEntry(ctrl_entry);
}
static void SDLCALL append_button_to(void *ptr, SDL_TrayEntry *entry)
{
SDL_TrayMenu *menu = (SDL_TrayMenu *) ptr;
SDL_TrayMenu *submenu;
SDL_TrayEntry *new_ctrl;
SDL_TrayEntry *new_ctrl_remove;
SDL_TrayEntry *new_ctrl_enabled;
SDL_TrayEntry *new_ctrl_disabled;
SDL_TrayEntry *new_example;
new_ctrl = SDL_InsertTrayEntryAt(SDL_GetTrayEntryParent(entry), -1, "New button", SDL_TRAYENTRY_SUBMENU);
if (!new_ctrl) {
SDL_Log("Couldn't insert entry in control tray: %s", SDL_GetError());
return;
}
/* ---------- */
submenu = SDL_CreateTraySubmenu(new_ctrl);
if (!new_ctrl) {
SDL_Log("Couldn't create control tray entry submenu: %s", SDL_GetError());
SDL_RemoveTrayEntry(new_ctrl);
return;
}
/* ---------- */
new_example = SDL_InsertTrayEntryAt(menu, -1, "New button", SDL_TRAYENTRY_BUTTON);
if (new_example == NULL) {
SDL_Log("Couldn't insert entry in example tray: %s", SDL_GetError());
SDL_RemoveTrayEntry(new_ctrl);
return;
}
SDL_SetTrayEntryCallback(new_example, print_entry, NULL);
/* ---------- */
new_ctrl_remove = SDL_InsertTrayEntryAt(submenu, -1, "Remove", SDL_TRAYENTRY_BUTTON);
if (new_ctrl_remove == NULL) {
SDL_Log("Couldn't insert new_ctrl_remove: %s", SDL_GetError());
SDL_RemoveTrayEntry(new_ctrl);
SDL_RemoveTrayEntry(new_example);
return;
}
SDL_SetTrayEntryCallback(new_ctrl_remove, remove_entry, new_example);
/* ---------- */
new_ctrl_enabled = SDL_InsertTrayEntryAt(submenu, -1, "Enable", SDL_TRAYENTRY_BUTTON);
if (new_ctrl_enabled == NULL) {
SDL_Log("Couldn't insert new_ctrl_enabled: %s", SDL_GetError());
SDL_RemoveTrayEntry(new_ctrl);
SDL_RemoveTrayEntry(new_example);
return;
}
SDL_SetTrayEntryCallback(new_ctrl_enabled, set_entry_enabled, new_example);
/* ---------- */
new_ctrl_disabled = SDL_InsertTrayEntryAt(submenu, -1, "Disable", SDL_TRAYENTRY_BUTTON);
if (new_ctrl_disabled == NULL) {
SDL_Log("Couldn't insert new_ctrl_disabled: %s", SDL_GetError());
SDL_RemoveTrayEntry(new_ctrl);
SDL_RemoveTrayEntry(new_example);
return;
}
SDL_SetTrayEntryCallback(new_ctrl_disabled, set_entry_disabled, new_example);
}
static void SDLCALL append_checkbox_to(void *ptr, SDL_TrayEntry *entry)
{
SDL_TrayMenu *menu = (SDL_TrayMenu *) ptr;
SDL_TrayMenu *submenu;
SDL_TrayEntry *new_ctrl;
SDL_TrayEntry *new_ctrl_remove;
SDL_TrayEntry *new_ctrl_enabled;
SDL_TrayEntry *new_ctrl_disabled;
SDL_TrayEntry *new_ctrl_checked;
SDL_TrayEntry *new_ctrl_unchecked;
SDL_TrayEntry *new_example;
new_ctrl = SDL_InsertTrayEntryAt(SDL_GetTrayEntryParent(entry), -1, "New checkbox", SDL_TRAYENTRY_SUBMENU);
if (!new_ctrl) {
SDL_Log("Couldn't insert entry in control tray: %s", SDL_GetError());
return;
}
/* ---------- */
submenu = SDL_CreateTraySubmenu(new_ctrl);
if (!new_ctrl) {
SDL_Log("Couldn't create control tray entry submenu: %s", SDL_GetError());
SDL_RemoveTrayEntry(new_ctrl);
return;
}
/* ---------- */
new_example = SDL_InsertTrayEntryAt(menu, -1, "New checkbox", SDL_TRAYENTRY_CHECKBOX);
if (new_example == NULL) {
SDL_Log("Couldn't insert entry in example tray: %s", SDL_GetError());
SDL_RemoveTrayEntry(new_ctrl);
return;
}
SDL_SetTrayEntryCallback(new_example, print_entry, NULL);
/* ---------- */
new_ctrl_remove = SDL_InsertTrayEntryAt(submenu, -1, "Remove", SDL_TRAYENTRY_BUTTON);
if (new_ctrl_remove == NULL) {
SDL_Log("Couldn't insert new_ctrl_remove: %s", SDL_GetError());
SDL_RemoveTrayEntry(new_ctrl);
SDL_RemoveTrayEntry(new_example);
return;
}
SDL_SetTrayEntryCallback(new_ctrl_remove, remove_entry, new_example);
/* ---------- */
new_ctrl_enabled = SDL_InsertTrayEntryAt(submenu, -1, "Enable", SDL_TRAYENTRY_BUTTON);
if (new_ctrl_enabled == NULL) {
SDL_Log("Couldn't insert new_ctrl_enabled: %s", SDL_GetError());
SDL_RemoveTrayEntry(new_ctrl);
SDL_RemoveTrayEntry(new_example);
return;
}
SDL_SetTrayEntryCallback(new_ctrl_enabled, set_entry_enabled, new_example);
/* ---------- */
new_ctrl_disabled = SDL_InsertTrayEntryAt(submenu, -1, "Disable", SDL_TRAYENTRY_BUTTON);
if (new_ctrl_disabled == NULL) {
SDL_Log("Couldn't insert new_ctrl_disabled: %s", SDL_GetError());
SDL_RemoveTrayEntry(new_ctrl);
SDL_RemoveTrayEntry(new_example);
return;
}
SDL_SetTrayEntryCallback(new_ctrl_disabled, set_entry_disabled, new_example);
/* ---------- */
new_ctrl_checked = SDL_InsertTrayEntryAt(submenu, -1, "Check", SDL_TRAYENTRY_BUTTON);
if (new_ctrl_checked == NULL) {
SDL_Log("Couldn't insert new_ctrl_checked: %s", SDL_GetError());
SDL_RemoveTrayEntry(new_ctrl);
SDL_RemoveTrayEntry(new_example);
return;
}
SDL_SetTrayEntryCallback(new_ctrl_checked, set_entry_checked, new_example);
/* ---------- */
new_ctrl_unchecked = SDL_InsertTrayEntryAt(submenu, -1, "Uncheck", SDL_TRAYENTRY_BUTTON);
if (new_ctrl_unchecked == NULL) {
SDL_Log("Couldn't insert new_ctrl_unchecked: %s", SDL_GetError());
SDL_RemoveTrayEntry(new_ctrl);
SDL_RemoveTrayEntry(new_example);
return;
}
SDL_SetTrayEntryCallback(new_ctrl_unchecked, set_entry_unchecked, new_example);
}
static void SDLCALL append_separator_to(void *ptr, SDL_TrayEntry *entry)
{
SDL_TrayMenu *menu = (SDL_TrayMenu *) ptr;
SDL_TrayMenu *submenu;
SDL_TrayEntry *new_ctrl;
SDL_TrayEntry *new_ctrl_remove;
SDL_TrayEntry *new_example;
new_ctrl = SDL_InsertTrayEntryAt(SDL_GetTrayEntryParent(entry), -1, "[Separator]", SDL_TRAYENTRY_SUBMENU);
if (!new_ctrl) {
SDL_Log("Couldn't insert entry in control tray: %s", SDL_GetError());
return;
}
/* ---------- */
submenu = SDL_CreateTraySubmenu(new_ctrl);
if (!new_ctrl) {
SDL_Log("Couldn't create control tray entry submenu: %s", SDL_GetError());
SDL_RemoveTrayEntry(new_ctrl);
return;
}
/* ---------- */
new_example = SDL_InsertTrayEntryAt(menu, -1, NULL, SDL_TRAYENTRY_BUTTON);
if (new_example == NULL) {
SDL_Log("Couldn't insert separator in example tray: %s", SDL_GetError());
SDL_RemoveTrayEntry(new_ctrl);
return;
}
/* ---------- */
new_ctrl_remove = SDL_InsertTrayEntryAt(submenu, -1, "Remove", SDL_TRAYENTRY_BUTTON);
if (new_ctrl_remove == NULL) {
SDL_Log("Couldn't insert new_ctrl_remove: %s", SDL_GetError());
SDL_RemoveTrayEntry(new_ctrl);
SDL_RemoveTrayEntry(new_example);
return;
}
SDL_SetTrayEntryCallback(new_ctrl_remove, remove_entry, new_example);
}
static void SDLCALL append_submenu_to(void *ptr, SDL_TrayEntry *entry)
{
SDL_TrayMenu *menu = (SDL_TrayMenu *) ptr;
SDL_TrayMenu *submenu;
SDL_TrayMenu *entry_submenu;
SDL_TrayEntry *new_ctrl;
SDL_TrayEntry *new_ctrl_remove;
SDL_TrayEntry *new_ctrl_enabled;
SDL_TrayEntry *new_ctrl_disabled;
SDL_TrayEntry *new_example;
new_ctrl = SDL_InsertTrayEntryAt(SDL_GetTrayEntryParent(entry), -1, "New submenu", SDL_TRAYENTRY_SUBMENU);
if (!new_ctrl) {
SDL_Log("Couldn't insert entry in control tray: %s", SDL_GetError());
return;
}
/* ---------- */
submenu = SDL_CreateTraySubmenu(new_ctrl);
if (!new_ctrl) {
SDL_Log("Couldn't create control tray entry submenu: %s", SDL_GetError());
SDL_RemoveTrayEntry(new_ctrl);
return;
}
/* ---------- */
new_example = SDL_InsertTrayEntryAt(menu, -1, "New submenu", SDL_TRAYENTRY_SUBMENU);
if (new_example == NULL) {
SDL_Log("Couldn't insert entry in example tray: %s", SDL_GetError());
SDL_RemoveTrayEntry(new_ctrl);
return;
}
SDL_SetTrayEntryCallback(new_example, print_entry, NULL);
/* ---------- */
entry_submenu = SDL_CreateTraySubmenu(new_example);
if (entry_submenu == NULL) {
SDL_Log("Couldn't create new entry submenu: %s", SDL_GetError());
SDL_RemoveTrayEntry(new_ctrl);
SDL_RemoveTrayEntry(new_example);
return;
}
/* ---------- */
new_ctrl_remove = SDL_InsertTrayEntryAt(submenu, -1, "Remove", SDL_TRAYENTRY_BUTTON);
if (new_ctrl_remove == NULL) {
SDL_Log("Couldn't insert new_ctrl_remove: %s", SDL_GetError());
SDL_RemoveTrayEntry(new_ctrl);
SDL_RemoveTrayEntry(new_example);
return;
}
SDL_SetTrayEntryCallback(new_ctrl_remove, remove_entry, new_example);
/* ---------- */
new_ctrl_enabled = SDL_InsertTrayEntryAt(submenu, -1, "Enable", SDL_TRAYENTRY_BUTTON);
if (new_ctrl_enabled == NULL) {
SDL_Log("Couldn't insert new_ctrl_enabled: %s", SDL_GetError());
SDL_RemoveTrayEntry(new_ctrl);
SDL_RemoveTrayEntry(new_example);
return;
}
SDL_SetTrayEntryCallback(new_ctrl_enabled, set_entry_enabled, new_example);
/* ---------- */
new_ctrl_disabled = SDL_InsertTrayEntryAt(submenu, -1, "Disable", SDL_TRAYENTRY_BUTTON);
if (new_ctrl_disabled == NULL) {
SDL_Log("Couldn't insert new_ctrl_disabled: %s", SDL_GetError());
SDL_RemoveTrayEntry(new_ctrl);
SDL_RemoveTrayEntry(new_example);
return;
}
SDL_SetTrayEntryCallback(new_ctrl_disabled, set_entry_disabled, new_example);
/* ---------- */
SDL_InsertTrayEntryAt(submenu, -1, NULL, 0);
/* ---------- */
SDL_TrayEntry *entry_newbtn = SDL_InsertTrayEntryAt(submenu, -1, "Create button", SDL_TRAYENTRY_BUTTON);
if (entry_newbtn == NULL) {
SDL_Log("Couldn't insert entry_newbtn: %s", SDL_GetError());
SDL_RemoveTrayEntry(new_ctrl);
SDL_RemoveTrayEntry(new_example);
return;
}
SDL_SetTrayEntryCallback(entry_newbtn, append_button_to, entry_submenu);
/* ---------- */
SDL_TrayEntry *entry_newchk = SDL_InsertTrayEntryAt(submenu, -1, "Create checkbox", SDL_TRAYENTRY_BUTTON);
if (entry_newchk == NULL) {
SDL_Log("Couldn't insert entry_newchk: %s", SDL_GetError());
SDL_RemoveTrayEntry(new_ctrl);
SDL_RemoveTrayEntry(new_example);
return;
}
SDL_SetTrayEntryCallback(entry_newchk, append_checkbox_to, entry_submenu);
/* ---------- */
SDL_TrayEntry *entry_newsub = SDL_InsertTrayEntryAt(submenu, -1, "Create submenu", SDL_TRAYENTRY_BUTTON);
if (entry_newsub == NULL) {
SDL_Log("Couldn't insert entry_newsub: %s", SDL_GetError());
SDL_RemoveTrayEntry(new_ctrl);
SDL_RemoveTrayEntry(new_example);
return;
}
SDL_SetTrayEntryCallback(entry_newsub, append_submenu_to, entry_submenu);
/* ---------- */
SDL_TrayEntry *entry_newsep = SDL_InsertTrayEntryAt(submenu, -1, "Create separator", SDL_TRAYENTRY_BUTTON);
if (entry_newsep == NULL) {
SDL_Log("Couldn't insert entry_newsep: %s", SDL_GetError());
SDL_RemoveTrayEntry(new_ctrl);
SDL_RemoveTrayEntry(new_example);
return;
}
SDL_SetTrayEntryCallback(entry_newsep, append_separator_to, entry_submenu);
/* ---------- */
SDL_InsertTrayEntryAt(submenu, -1, NULL, 0);
}
int main(int argc, char **argv)
{
SDL_Tray **trays = NULL;
SDLTest_CommonState *state;
int i;
/* Initialize test framework */
state = SDLTest_CommonCreateState(argv, 0);
if (state == NULL) {
return 1;
}
/* Parse commandline */
for (i = 1; i < argc;) {
int consumed;
consumed = SDLTest_CommonArg(state, i);
if (consumed <= 0) {
static const char *options[] = { NULL };
SDLTest_CommonLogUsage(state, argv[0], options);
return 1;
}
i += consumed;
}
if (!SDL_Init(SDL_INIT_VIDEO)) {
SDL_Log("SDL_Init failed (%s)", SDL_GetError());
return 1;
}
window = SDL_CreateWindow("testtray", 640, 480, 0);
if (!window) {
SDL_Log("Couldn't create window: %s", SDL_GetError());
goto quit;
}
char *icon1filename = GetResourceFilename(NULL, "sdl-test_round.png");
SDL_Surface *icon = SDL_LoadPNG(icon1filename);
SDL_free(icon1filename);
if (!icon) {
SDL_Log("Couldn't load icon 1, proceeding without: %s", SDL_GetError());
}
char *icon2filename = GetResourceFilename(NULL, "speaker.png");
SDL_Surface *icon2 = SDL_LoadPNG(icon2filename);
SDL_free(icon2filename);
if (!icon2) {
SDL_Log("Couldn't load icon 2, proceeding without: %s", SDL_GetError());
}
SDL_Tray *tray = SDL_CreateTray(icon, "SDL Tray control menu");
if (!tray) {
SDL_Log("Couldn't create control tray: %s", SDL_GetError());
goto clean_window;
}
SDL_PropertiesID tray2_props = SDL_CreateProperties();
SDL_SetPointerProperty(tray2_props, SDL_PROP_TRAY_CREATE_ICON_POINTER, icon2);
SDL_SetStringProperty(tray2_props, SDL_PROP_TRAY_CREATE_TOOLTIP_STRING, "SDL Tray example");
SDL_SetPointerProperty(tray2_props, SDL_PROP_TRAY_CREATE_LEFTCLICK_CALLBACK_POINTER, tray2_leftclick);
SDL_SetPointerProperty(tray2_props, SDL_PROP_TRAY_CREATE_RIGHTCLICK_CALLBACK_POINTER, tray2_rightclick);
SDL_SetPointerProperty(tray2_props, SDL_PROP_TRAY_CREATE_MIDDLECLICK_CALLBACK_POINTER, tray2_middleclick);
SDL_Tray *tray2 = SDL_CreateTrayWithProperties(tray2_props);
SDL_DestroyProperties(tray2_props);
if (!tray2) {
SDL_Log("Couldn't create example tray: %s", SDL_GetError());
goto clean_tray1;
}
SDL_DestroySurface(icon);
SDL_DestroySurface(icon2);
#define CHECK(name) \
if (!name) { \
SDL_Log("Couldn't create " #name ": %s", SDL_GetError()); \
goto clean_all; \
}
SDL_TrayMenu *menu = SDL_CreateTrayMenu(tray);
CHECK(menu);
SDL_TrayMenu *menu2 = SDL_CreateTrayMenu(tray2);
CHECK(menu2);
SDL_TrayEntry *entry_quit = SDL_InsertTrayEntryAt(menu, -1, "Quit", SDL_TRAYENTRY_BUTTON);
CHECK(entry_quit);
SDL_TrayEntry *entry_close = SDL_InsertTrayEntryAt(menu, -1, "Destroy trays", SDL_TRAYENTRY_BUTTON);
CHECK(entry_close);
/* TODO: Track memory! */
trays = SDL_malloc(sizeof(SDL_Tray *) * 2);
if (!trays) {
goto clean_all;
}
trays[0] = tray;
trays[1] = tray2;
SDL_SetTrayEntryCallback(entry_quit, tray_quit, NULL);
SDL_SetTrayEntryCallback(entry_close, tray_close, trays);
SDL_InsertTrayEntryAt(menu, -1, NULL, 0);
entry_toggle = SDL_InsertTrayEntryAt(menu, -1, "Hide window", SDL_TRAYENTRY_BUTTON);
CHECK(entry_toggle);
SDL_SetTrayEntryCallback(entry_toggle, toggle_window, NULL);
SDL_InsertTrayEntryAt(menu, -1, NULL, 0);
SDL_TrayEntry *entry_icon = SDL_InsertTrayEntryAt(menu, -1, "Change icon", SDL_TRAYENTRY_BUTTON);
CHECK(entry_icon);
SDL_SetTrayEntryCallback(entry_icon, change_icon, tray2);
SDL_InsertTrayEntryAt(menu, -1, NULL, 0);
SDL_TrayEntry *entry_newbtn = SDL_InsertTrayEntryAt(menu, -1, "Create button", SDL_TRAYENTRY_BUTTON);
CHECK(entry_newbtn);
SDL_SetTrayEntryCallback(entry_newbtn, append_button_to, menu2);
SDL_TrayEntry *entry_newchk = SDL_InsertTrayEntryAt(menu, -1, "Create checkbox", SDL_TRAYENTRY_BUTTON);
CHECK(entry_newchk);
SDL_SetTrayEntryCallback(entry_newchk, append_checkbox_to, menu2);
SDL_TrayEntry *entry_newsub = SDL_InsertTrayEntryAt(menu, -1, "Create submenu", SDL_TRAYENTRY_BUTTON);
CHECK(entry_newsub);
SDL_SetTrayEntryCallback(entry_newsub, append_submenu_to, menu2);
SDL_TrayEntry *entry_newsep = SDL_InsertTrayEntryAt(menu, -1, "Create separator", SDL_TRAYENTRY_BUTTON);
CHECK(entry_newsep);
SDL_SetTrayEntryCallback(entry_newsep, append_separator_to, menu2);
SDL_InsertTrayEntryAt(menu, -1, NULL, 0);
SDL_Event e;
while (SDL_WaitEvent(&e)) {
if (e.type == SDL_EVENT_QUIT) {
break;
} else if (e.type == SDL_EVENT_WINDOW_CLOSE_REQUESTED) {
if (trays_destroyed) {
break;
}
toggle_window(NULL, entry_toggle);
}
}
clean_all:
if (!trays_destroyed) {
SDL_DestroyTray(tray2);
}
clean_tray1:
if (!trays_destroyed) {
SDL_DestroyTray(tray);
}
SDL_free(trays);
clean_window:
if (window) {
SDL_DestroyWindow(window);
}
quit:
SDL_Quit();
SDLTest_CommonDestroyState(state);
return 0;
}