Atlas - SDL_tray.c

Home / ext / SDL / src / tray / unix Lines: 1 | Size: 7793 bytes [Download] [Show on GitHub] [Search similar files] [Raw] [Raw (proxy)]
[FILE BEGIN]
1/* 2 Simple DirectMedia Layer 3 Copyright (C) 1997-2026 Sam Lantinga <[email protected]> 4 5 This software is provided 'as-is', without any express or implied 6 warranty. In no event will the authors be held liable for any damages 7 arising from the use of this software. 8 9 Permission is granted to anyone to use this software for any purpose, 10 including commercial applications, and to alter it and redistribute it 11 freely, subject to the following restrictions: 12 13 1. The origin of this software must not be misrepresented; you must not 14 claim that you wrote the original software. If you use this software 15 in a product, an acknowledgment in the product documentation would be 16 appreciated but is not required. 17 2. Altered source versions must be plainly marked as such, and must not be 18 misrepresented as being the original software. 19 3. This notice may not be removed or altered from any source distribution. 20*/ 21 22#include "SDL_internal.h" 23 24#include "../SDL_tray_utils.h" 25#include "SDL_unixtray.h" 26 27static SDL_TrayDriver *driver = NULL; 28 29void SDL_UpdateTrays(void) 30{ 31 SDL_Tray **trays; 32 int active_trays; 33 int count; 34 int i; 35 36 active_trays = SDL_GetActiveTrayCount(); 37 if (!active_trays) { 38 return; 39 } 40 41 trays = SDL_calloc(active_trays, sizeof(SDL_Tray *)); 42 if (!trays) { 43 return; 44 } 45 46 count = SDL_GetObjects(SDL_OBJECT_TYPE_TRAY, (void **)trays, active_trays); 47 SDL_assert(count == active_trays); 48 for (i = 0; i < count; i++) { 49 if (trays[i]) { 50 if (SDL_ObjectValid(trays[i], SDL_OBJECT_TYPE_TRAY)) { 51 trays[i]->driver->UpdateTray(trays[i]); 52 } 53 } 54 } 55 56 SDL_free(trays); 57} 58 59SDL_Tray *SDL_CreateTrayWithProperties(SDL_PropertiesID props) 60{ 61 SDL_Tray *tray; 62 63 if (!SDL_IsMainThread()) { 64 SDL_SetError("This function should be called on the main thread"); 65 return NULL; 66 } 67 68 if (!driver) { 69#ifdef SDL_USE_LIBDBUS 70 driver = SDL_Tray_CreateDBusDriver(); 71#endif 72 } 73 74 if (driver) { 75 tray = driver->CreateTray(driver, props); 76 77 if (tray) { 78 SDL_RegisterTray(tray); 79 } 80 } else { 81 tray = NULL; 82 } 83 84 return tray; 85} 86 87SDL_Tray *SDL_CreateTray(SDL_Surface *icon, const char *tooltip) 88{ 89 SDL_Tray *tray; 90 SDL_PropertiesID props; 91 92 props = SDL_CreateProperties(); 93 94 if (!props) { 95 return NULL; 96 } 97 98 if (icon) { 99 SDL_SetPointerProperty(props, SDL_PROP_TRAY_CREATE_ICON_POINTER, icon); 100 } 101 102 if (tooltip) { 103 SDL_SetStringProperty(props, SDL_PROP_TRAY_CREATE_TOOLTIP_STRING, tooltip); 104 } 105 106 tray = SDL_CreateTrayWithProperties(props); 107 SDL_DestroyProperties(props); 108 return tray; 109} 110 111void SDL_SetTrayIcon(SDL_Tray *tray, SDL_Surface *icon) 112{ 113 CHECK_PARAM (!SDL_ObjectValid(tray, SDL_OBJECT_TYPE_TRAY)) { 114 SDL_InvalidParamError("tray"); 115 return; 116 } 117 118 tray->driver->SetTrayIcon(tray, icon); 119} 120 121void SDL_SetTrayTooltip(SDL_Tray *tray, const char *tooltip) 122{ 123 CHECK_PARAM (!SDL_ObjectValid(tray, SDL_OBJECT_TYPE_TRAY)) { 124 SDL_InvalidParamError("tray"); 125 return; 126 } 127 128 tray->driver->SetTrayTooltip(tray, tooltip); 129} 130 131SDL_TrayMenu *SDL_CreateTrayMenu(SDL_Tray *tray) 132{ 133 CHECK_PARAM (!SDL_ObjectValid(tray, SDL_OBJECT_TYPE_TRAY)) { 134 SDL_InvalidParamError("tray"); 135 return NULL; 136 } 137 138 return tray->driver->CreateTrayMenu(tray); 139} 140 141SDL_TrayMenu *SDL_GetTrayMenu(SDL_Tray *tray) 142{ 143 CHECK_PARAM (!SDL_ObjectValid(tray, SDL_OBJECT_TYPE_TRAY)) { 144 SDL_InvalidParamError("tray"); 145 return NULL; 146 } 147 148 return tray->menu; 149} 150 151SDL_TrayMenu *SDL_CreateTraySubmenu(SDL_TrayEntry *entry) 152{ 153 CHECK_PARAM (!entry) { 154 SDL_InvalidParamError("entry"); 155 return NULL; 156 } 157 158 return entry->parent->parent_tray->driver->CreateTraySubmenu(entry); 159} 160 161SDL_TrayMenu *SDL_GetTraySubmenu(SDL_TrayEntry *entry) 162{ 163 CHECK_PARAM (!entry) { 164 SDL_InvalidParamError("entry"); 165 return NULL; 166 } 167 168 return entry->parent->parent_tray->driver->GetTraySubmenu(entry); 169} 170 171const SDL_TrayEntry **SDL_GetTrayEntries(SDL_TrayMenu *menu, int *count) 172{ 173 CHECK_PARAM (!menu) { 174 SDL_InvalidParamError("menu"); 175 return NULL; 176 } 177 178 CHECK_PARAM (!count) { 179 SDL_InvalidParamError("count"); 180 return NULL; 181 } 182 183 return (const SDL_TrayEntry **)menu->parent_tray->driver->GetTrayEntries(menu, count); 184} 185 186void SDL_RemoveTrayEntry(SDL_TrayEntry *entry) 187{ 188 CHECK_PARAM (!entry) { 189 SDL_InvalidParamError("entry"); 190 return; 191 } 192 193 entry->parent->parent_tray->driver->RemoveTrayEntry(entry); 194} 195 196SDL_TrayEntry *SDL_InsertTrayEntryAt(SDL_TrayMenu *menu, int pos, const char *label, SDL_TrayEntryFlags flags) 197{ 198 CHECK_PARAM (!menu) { 199 SDL_InvalidParamError("menu"); 200 return NULL; 201 } 202 203 return menu->parent_tray->driver->InsertTrayEntryAt(menu, pos, label, flags); 204} 205 206void SDL_SetTrayEntryLabel(SDL_TrayEntry *entry, const char *label) 207{ 208 CHECK_PARAM (!entry) { 209 SDL_InvalidParamError("entry"); 210 return; 211 } 212 213 entry->parent->parent_tray->driver->SetTrayEntryLabel(entry, label); 214} 215 216const char *SDL_GetTrayEntryLabel(SDL_TrayEntry *entry) 217{ 218 CHECK_PARAM (!entry) { 219 SDL_InvalidParamError("entry"); 220 return NULL; 221 } 222 223 return entry->parent->parent_tray->driver->GetTrayEntryLabel(entry); 224} 225 226void SDL_SetTrayEntryChecked(SDL_TrayEntry *entry, bool checked) 227{ 228 CHECK_PARAM (!entry) { 229 SDL_InvalidParamError("entry"); 230 return; 231 } 232 233 entry->parent->parent_tray->driver->SetTrayEntryChecked(entry, checked); 234} 235 236bool SDL_GetTrayEntryChecked(SDL_TrayEntry *entry) 237{ 238 CHECK_PARAM (!entry) { 239 SDL_InvalidParamError("entry"); 240 return NULL; 241 } 242 243 return entry->parent->parent_tray->driver->GetTrayEntryChecked(entry); 244} 245 246void SDL_SetTrayEntryEnabled(SDL_TrayEntry *entry, bool enabled) 247{ 248 CHECK_PARAM (!entry) { 249 SDL_InvalidParamError("entry"); 250 return; 251 } 252 253 entry->parent->parent_tray->driver->SetTrayEntryEnabled(entry, enabled); 254} 255 256bool SDL_GetTrayEntryEnabled(SDL_TrayEntry *entry) 257{ 258 CHECK_PARAM (!entry) { 259 SDL_InvalidParamError("entry"); 260 return NULL; 261 } 262 263 return entry->parent->parent_tray->driver->GetTrayEntryEnabled(entry); 264} 265 266void SDL_SetTrayEntryCallback(SDL_TrayEntry *entry, SDL_TrayCallback callback, void *userdata) 267{ 268 CHECK_PARAM (!entry) { 269 SDL_InvalidParamError("entry"); 270 return; 271 } 272 273 CHECK_PARAM (!callback) { 274 SDL_InvalidParamError("callback"); 275 return; 276 } 277 278 entry->parent->parent_tray->driver->SetTrayEntryCallback(entry, callback, userdata); 279} 280 281void SDL_ClickTrayEntry(SDL_TrayEntry *entry) 282{ 283 CHECK_PARAM (!entry) { 284 SDL_InvalidParamError("entry"); 285 return; 286 } 287 288 entry->parent->parent_tray->driver->GetTrayEntryEnabled(entry); 289} 290 291SDL_TrayMenu *SDL_GetTrayEntryParent(SDL_TrayEntry *entry) 292{ 293 CHECK_PARAM (!entry) { 294 SDL_InvalidParamError("entry"); 295 return NULL; 296 } 297 298 return entry->parent; 299} 300 301SDL_TrayEntry *SDL_GetTrayMenuParentEntry(SDL_TrayMenu *menu) 302{ 303 CHECK_PARAM (!menu) { 304 SDL_InvalidParamError("menu"); 305 return NULL; 306 } 307 308 return menu->parent_entry; 309} 310 311SDL_Tray *SDL_GetTrayMenuParentTray(SDL_TrayMenu *menu) 312{ 313 CHECK_PARAM (!menu) { 314 SDL_InvalidParamError("menu"); 315 return NULL; 316 } 317 318 return menu->parent_tray; 319} 320 321void SDL_DestroyTray(SDL_Tray *tray) 322{ 323 if (!SDL_ObjectValid(tray, SDL_OBJECT_TYPE_TRAY)) { 324 return; 325 } 326 327 SDL_UnregisterTray(tray); 328 tray->driver->DestroyTray(tray); 329 330 if (!SDL_GetActiveTrayCount()) { 331 driver->DestroyDriver(driver); 332 driver = NULL; 333 } 334} 335
[FILE END]
(C) 2025 0x4248 (C) 2025 4248 Media and 4248 Systems, All part of 0x4248 See LICENCE files for more information. Not all files are by 0x4248 always check Licencing.