|
27 | 27 |
|
28 | 28 | static int active_trays = 0;
|
29 | 29 |
|
30 |
| -extern void SDL_IncrementTrayCount(void) |
| 30 | +void SDL_RegisterTray(SDL_Tray *tray) |
31 | 31 | {
|
32 |
| - if (++active_trays < 1) { |
33 |
| - SDL_Log("Active tray count corrupted (%d < 1), this is a bug. The app may close or fail to close unexpectedly.", active_trays); |
34 |
| - } |
| 32 | + SDL_SetObjectValid(tray, SDL_OBJECT_TYPE_TRAY, true); |
| 33 | + |
| 34 | + ++active_trays; |
35 | 35 | }
|
36 | 36 |
|
37 |
| -extern void SDL_DecrementTrayCount(void) |
| 37 | +void SDL_UnregisterTray(SDL_Tray *tray) |
38 | 38 | {
|
39 |
| - int toplevel_count = 0; |
40 |
| - SDL_Window *n; |
| 39 | + SDL_assert(SDL_ObjectValid(tray, SDL_OBJECT_TYPE_TRAY)); |
| 40 | + |
| 41 | + SDL_SetObjectValid(tray, SDL_OBJECT_TYPE_TRAY, false); |
41 | 42 |
|
42 |
| - if (--active_trays < 0) { |
43 |
| - SDL_Log("Active tray count corrupted (%d < 0), this is a bug. The app may close or fail to close unexpectedly.", active_trays); |
| 43 | + --active_trays; |
| 44 | + if (active_trays > 0) { |
| 45 | + return; |
44 | 46 | }
|
45 | 47 |
|
46 | 48 | if (!SDL_GetHintBoolean(SDL_HINT_QUIT_ON_LAST_WINDOW_CLOSE, true)) {
|
47 | 49 | return;
|
48 | 50 | }
|
49 | 51 |
|
50 |
| - for (n = SDL_GetVideoDevice()->windows; n; n = n->next) { |
51 |
| - if (!n->parent && !(n->flags & SDL_WINDOW_HIDDEN)) { |
52 |
| - ++toplevel_count; |
| 52 | + int toplevel_count = 0; |
| 53 | + SDL_Window **windows = SDL_GetWindows(NULL); |
| 54 | + if (windows) { |
| 55 | + for (int i = 0; windows[i]; ++i) { |
| 56 | + SDL_Window *window = windows[i]; |
| 57 | + if (!window->parent && !(window->flags & SDL_WINDOW_HIDDEN)) { |
| 58 | + ++toplevel_count; |
| 59 | + } |
53 | 60 | }
|
| 61 | + SDL_free(windows); |
54 | 62 | }
|
55 | 63 |
|
56 |
| - if (toplevel_count < 1) { |
| 64 | + if (toplevel_count == 0) { |
57 | 65 | SDL_SendQuit();
|
58 | 66 | }
|
59 | 67 | }
|
60 | 68 |
|
61 |
| -extern bool SDL_HasNoActiveTrays(void) |
| 69 | +void SDL_CleanupTrays(void) |
| 70 | +{ |
| 71 | + if (active_trays == 0) { |
| 72 | + return; |
| 73 | + } |
| 74 | + |
| 75 | + void **trays = (void **)SDL_malloc(active_trays * sizeof(*trays)); |
| 76 | + if (!trays) { |
| 77 | + return; |
| 78 | + } |
| 79 | + |
| 80 | + int count = SDL_GetObjects(SDL_OBJECT_TYPE_TRAY, trays, active_trays); |
| 81 | + SDL_assert(count == active_trays); |
| 82 | + for (int i = 0; i < count; ++i) { |
| 83 | + SDL_DestroyTray((SDL_Tray *)trays[i]); |
| 84 | + } |
| 85 | + SDL_free(trays); |
| 86 | +} |
| 87 | + |
| 88 | +bool SDL_HasNoActiveTrays(void) |
62 | 89 | {
|
63 |
| - return active_trays < 1; |
| 90 | + return active_trays == 0; |
64 | 91 | }
|
0 commit comments