SDL_tray.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
  4. This software is provided 'as-is', without any express or implied
  5. warranty. In no event will the authors be held liable for any damages
  6. arising from the use of this software.
  7. Permission is granted to anyone to use this software for any purpose,
  8. including commercial applications, and to alter it and redistribute it
  9. freely, subject to the following restrictions:
  10. 1. The origin of this software must not be misrepresented; you must not
  11. claim that you wrote the original software. If you use this software
  12. in a product, an acknowledgment in the product documentation would be
  13. appreciated but is not required.
  14. 2. Altered source versions must be plainly marked as such, and must not be
  15. misrepresented as being the original software.
  16. 3. This notice may not be removed or altered from any source distribution.
  17. */
  18. /**
  19. * # CategoryTray
  20. *
  21. * System tray menu support.
  22. */
  23. #ifndef SDL_tray_h_
  24. #define SDL_tray_h_
  25. #include <SDL3/SDL_stdinc.h>
  26. #include <SDL3/SDL_error.h>
  27. #include <SDL3/SDL_surface.h>
  28. #include <SDL3/SDL_video.h>
  29. #include <SDL3/SDL_begin_code.h>
  30. /* Set up for C function definitions, even when using C++ */
  31. #ifdef __cplusplus
  32. extern "C" {
  33. #endif
  34. /**
  35. * An opaque handle representing a toplevel system tray object.
  36. *
  37. * \since This struct is available since SDL 3.2.0.
  38. */
  39. typedef struct SDL_Tray SDL_Tray;
  40. /**
  41. * An opaque handle representing a menu/submenu on a system tray object.
  42. *
  43. * \since This struct is available since SDL 3.2.0.
  44. */
  45. typedef struct SDL_TrayMenu SDL_TrayMenu;
  46. /**
  47. * An opaque handle representing an entry on a system tray object.
  48. *
  49. * \since This struct is available since SDL 3.2.0.
  50. */
  51. typedef struct SDL_TrayEntry SDL_TrayEntry;
  52. /**
  53. * Flags that control the creation of system tray entries.
  54. *
  55. * Some of these flags are required; exactly one of them must be specified at
  56. * the time a tray entry is created. Other flags are optional; zero or more of
  57. * those can be OR'ed together with the required flag.
  58. *
  59. * \since This datatype is available since SDL 3.2.0.
  60. *
  61. * \sa SDL_InsertTrayEntryAt
  62. */
  63. typedef Uint32 SDL_TrayEntryFlags;
  64. #define SDL_TRAYENTRY_BUTTON 0x00000001u /**< Make the entry a simple button. Required. */
  65. #define SDL_TRAYENTRY_CHECKBOX 0x00000002u /**< Make the entry a checkbox. Required. */
  66. #define SDL_TRAYENTRY_SUBMENU 0x00000004u /**< Prepare the entry to have a submenu. Required */
  67. #define SDL_TRAYENTRY_DISABLED 0x80000000u /**< Make the entry disabled. Optional. */
  68. #define SDL_TRAYENTRY_CHECKED 0x40000000u /**< Make the entry checked. This is valid only for checkboxes. Optional. */
  69. /**
  70. * A callback that is invoked when a tray entry is selected.
  71. *
  72. * \param userdata an optional pointer to pass extra data to the callback when
  73. * it will be invoked.
  74. * \param entry the tray entry that was selected.
  75. *
  76. * \since This datatype is available since SDL 3.2.0.
  77. *
  78. * \sa SDL_SetTrayEntryCallback
  79. */
  80. typedef void (SDLCALL *SDL_TrayCallback)(void *userdata, SDL_TrayEntry *entry);
  81. /**
  82. * Create an icon to be placed in the operating system's tray, or equivalent.
  83. *
  84. * Many platforms advise not using a system tray unless persistence is a
  85. * necessary feature. Avoid needlessly creating a tray icon, as the user may
  86. * feel like it clutters their interface.
  87. *
  88. * Using tray icons require the video subsystem.
  89. *
  90. * \param icon a surface to be used as icon. May be NULL.
  91. * \param tooltip a tooltip to be displayed when the mouse hovers the icon in
  92. * UTF-8 encoding. Not supported on all platforms. May be NULL.
  93. * \returns The newly created system tray icon.
  94. *
  95. * \since This function is available since SDL 3.1.8.
  96. *
  97. * \sa SDL_CreateTrayMenu
  98. * \sa SDL_GetTrayMenu
  99. * \sa SDL_DestroyTray
  100. */
  101. extern SDL_DECLSPEC SDL_Tray *SDLCALL SDL_CreateTray(SDL_Surface *icon, const char *tooltip);
  102. /**
  103. * Updates the system tray icon's icon.
  104. *
  105. * \param tray the tray icon to be updated.
  106. * \param icon the new icon. May be NULL.
  107. *
  108. * \since This function is available since SDL 3.1.8.
  109. *
  110. * \sa SDL_CreateTray
  111. */
  112. extern SDL_DECLSPEC void SDLCALL SDL_SetTrayIcon(SDL_Tray *tray, SDL_Surface *icon);
  113. /**
  114. * Updates the system tray icon's tooltip.
  115. *
  116. * \param tray the tray icon to be updated.
  117. * \param tooltip the new tooltip in UTF-8 encoding. May be NULL.
  118. *
  119. * \since This function is available since SDL 3.1.8.
  120. *
  121. * \sa SDL_CreateTray
  122. */
  123. extern SDL_DECLSPEC void SDLCALL SDL_SetTrayTooltip(SDL_Tray *tray, const char *tooltip);
  124. /**
  125. * Create a menu for a system tray.
  126. *
  127. * This should be called at most once per tray icon.
  128. *
  129. * This function does the same thing as SDL_CreateTraySubmenu(), except that
  130. * it takes a SDL_Tray instead of a SDL_TrayEntry.
  131. *
  132. * A menu does not need to be destroyed; it will be destroyed with the tray.
  133. *
  134. * \param tray the tray to bind the menu to.
  135. * \returns the newly created menu.
  136. *
  137. * \since This function is available since SDL 3.1.8.
  138. *
  139. * \sa SDL_CreateTray
  140. * \sa SDL_GetTrayMenu
  141. * \sa SDL_GetTrayMenuParentTray
  142. */
  143. extern SDL_DECLSPEC SDL_TrayMenu *SDLCALL SDL_CreateTrayMenu(SDL_Tray *tray);
  144. /**
  145. * Create a submenu for a system tray entry.
  146. *
  147. * This should be called at most once per tray entry.
  148. *
  149. * This function does the same thing as SDL_CreateTrayMenu, except that it
  150. * takes a SDL_TrayEntry instead of a SDL_Tray.
  151. *
  152. * A menu does not need to be destroyed; it will be destroyed with the tray.
  153. *
  154. * \param entry the tray entry to bind the menu to.
  155. * \returns the newly created menu.
  156. *
  157. * \since This function is available since SDL 3.1.8.
  158. *
  159. * \sa SDL_InsertTrayEntryAt
  160. * \sa SDL_GetTraySubmenu
  161. * \sa SDL_GetTrayMenuParentEntry
  162. */
  163. extern SDL_DECLSPEC SDL_TrayMenu *SDLCALL SDL_CreateTraySubmenu(SDL_TrayEntry *entry);
  164. /**
  165. * Gets a previously created tray menu.
  166. *
  167. * You should have called SDL_CreateTrayMenu() on the tray object. This
  168. * function allows you to fetch it again later.
  169. *
  170. * This function does the same thing as SDL_GetTraySubmenu(), except that it
  171. * takes a SDL_Tray instead of a SDL_TrayEntry.
  172. *
  173. * A menu does not need to be destroyed; it will be destroyed with the tray.
  174. *
  175. * \param tray the tray entry to bind the menu to.
  176. * \returns the newly created menu.
  177. *
  178. * \since This function is available since SDL 3.1.8.
  179. *
  180. * \sa SDL_CreateTray
  181. * \sa SDL_CreateTrayMenu
  182. */
  183. extern SDL_DECLSPEC SDL_TrayMenu *SDLCALL SDL_GetTrayMenu(SDL_Tray *tray);
  184. /**
  185. * Gets a previously created tray entry submenu.
  186. *
  187. * You should have called SDL_CreateTraySubmenu() on the entry object. This
  188. * function allows you to fetch it again later.
  189. *
  190. * This function does the same thing as SDL_GetTrayMenu(), except that it
  191. * takes a SDL_TrayEntry instead of a SDL_Tray.
  192. *
  193. * A menu does not need to be destroyed; it will be destroyed with the tray.
  194. *
  195. * \param entry the tray entry to bind the menu to.
  196. * \returns the newly created menu.
  197. *
  198. * \since This function is available since SDL 3.1.8.
  199. *
  200. * \sa SDL_InsertTrayEntryAt
  201. * \sa SDL_CreateTraySubmenu
  202. */
  203. extern SDL_DECLSPEC SDL_TrayMenu *SDLCALL SDL_GetTraySubmenu(SDL_TrayEntry *entry);
  204. /**
  205. * Returns a list of entries in the menu, in order.
  206. *
  207. * \param menu The menu to get entries from.
  208. * \param size An optional pointer to obtain the number of entries in the
  209. * menu.
  210. * \returns a NULL-terminated list of entries within the given menu. The
  211. * pointer becomes invalid when any function that inserts or deletes
  212. * entries in the menu is called.
  213. *
  214. * \since This function is available since SDL 3.1.8.
  215. *
  216. * \sa SDL_RemoveTrayEntry
  217. * \sa SDL_InsertTrayEntryAt
  218. */
  219. extern SDL_DECLSPEC const SDL_TrayEntry **SDLCALL SDL_GetTrayEntries(SDL_TrayMenu *menu, int *size);
  220. /**
  221. * Removes a tray entry.
  222. *
  223. * \param entry The entry to be deleted.
  224. *
  225. * \since This function is available since SDL 3.1.8.
  226. *
  227. * \sa SDL_GetTrayEntries
  228. * \sa SDL_InsertTrayEntryAt
  229. */
  230. extern SDL_DECLSPEC void SDLCALL SDL_RemoveTrayEntry(SDL_TrayEntry *entry);
  231. /**
  232. * Insert a tray entry at a given position.
  233. *
  234. * If label is NULL, the entry will be a separator. Many functions won't work
  235. * for an entry that is a separator.
  236. *
  237. * An entry does not need to be destroyed; it will be destroyed with the tray.
  238. *
  239. * \param menu the menu to append the entry to.
  240. * \param pos the desired position for the new entry. Entries at or following
  241. * this place will be moved. If pos is -1, the entry is appended.
  242. * \param label the text to be displayed on the entry, in UTF-8 encoding, or
  243. * NULL for a separator.
  244. * \param flags a combination of flags, some of which are mandatory.
  245. * \returns the newly created entry, or NULL if pos is out of bounds.
  246. *
  247. * \since This function is available since SDL 3.1.8.
  248. *
  249. * \sa SDL_TrayEntryFlags
  250. * \sa SDL_GetTrayEntries
  251. * \sa SDL_RemoveTrayEntry
  252. * \sa SDL_GetTrayEntryParent
  253. */
  254. extern SDL_DECLSPEC SDL_TrayEntry *SDLCALL SDL_InsertTrayEntryAt(SDL_TrayMenu *menu, int pos, const char *label, SDL_TrayEntryFlags flags);
  255. /**
  256. * Sets the label of an entry.
  257. *
  258. * An entry cannot change between a separator and an ordinary entry; that is,
  259. * it is not possible to set a non-NULL label on an entry that has a NULL
  260. * label (separators), or to set a NULL label to an entry that has a non-NULL
  261. * label. The function will silently fail if that happens.
  262. *
  263. * \param entry the entry to be updated.
  264. * \param label the new label for the entry in UTF-8 encoding.
  265. *
  266. * \since This function is available since SDL 3.1.8.
  267. *
  268. * \sa SDL_GetTrayEntries
  269. * \sa SDL_InsertTrayEntryAt
  270. * \sa SDL_GetTrayEntryLabel
  271. */
  272. extern SDL_DECLSPEC void SDLCALL SDL_SetTrayEntryLabel(SDL_TrayEntry *entry, const char *label);
  273. /**
  274. * Gets the label of an entry.
  275. *
  276. * If the returned value is NULL, the entry is a separator.
  277. *
  278. * \param entry the entry to be read.
  279. * \returns the label of the entry in UTF-8 encoding.
  280. *
  281. * \since This function is available since SDL 3.1.8.
  282. *
  283. * \sa SDL_GetTrayEntries
  284. * \sa SDL_InsertTrayEntryAt
  285. * \sa SDL_SetTrayEntryLabel
  286. */
  287. extern SDL_DECLSPEC const char *SDLCALL SDL_GetTrayEntryLabel(SDL_TrayEntry *entry);
  288. /**
  289. * Sets whether or not an entry is checked.
  290. *
  291. * The entry must have been created with the SDL_TRAYENTRY_CHECKBOX flag.
  292. *
  293. * \param entry the entry to be updated.
  294. * \param checked true if the entry should be checked; false otherwise.
  295. *
  296. * \since This function is available since SDL 3.1.8.
  297. *
  298. * \sa SDL_GetTrayEntries
  299. * \sa SDL_InsertTrayEntryAt
  300. * \sa SDL_GetTrayEntryChecked
  301. */
  302. extern SDL_DECLSPEC void SDLCALL SDL_SetTrayEntryChecked(SDL_TrayEntry *entry, bool checked);
  303. /**
  304. * Gets whether or not an entry is checked.
  305. *
  306. * The entry must have been created with the SDL_TRAYENTRY_CHECKBOX flag.
  307. *
  308. * \param entry the entry to be read.
  309. * \returns true if the entry is checked; false otherwise.
  310. *
  311. * \since This function is available since SDL 3.1.8.
  312. *
  313. * \sa SDL_GetTrayEntries
  314. * \sa SDL_InsertTrayEntryAt
  315. * \sa SDL_SetTrayEntryChecked
  316. */
  317. extern SDL_DECLSPEC bool SDLCALL SDL_GetTrayEntryChecked(SDL_TrayEntry *entry);
  318. /**
  319. * Sets whether or not an entry is enabled.
  320. *
  321. * \param entry the entry to be updated.
  322. * \param enabled true if the entry should be enabled; false otherwise.
  323. *
  324. * \since This function is available since SDL 3.1.8.
  325. *
  326. * \sa SDL_GetTrayEntries
  327. * \sa SDL_InsertTrayEntryAt
  328. * \sa SDL_GetTrayEntryEnabled
  329. */
  330. extern SDL_DECLSPEC void SDLCALL SDL_SetTrayEntryEnabled(SDL_TrayEntry *entry, bool enabled);
  331. /**
  332. * Gets whether or not an entry is enabled.
  333. *
  334. * \param entry the entry to be read.
  335. * \returns true if the entry is enabled; false otherwise.
  336. *
  337. * \since This function is available since SDL 3.1.8.
  338. *
  339. * \sa SDL_GetTrayEntries
  340. * \sa SDL_InsertTrayEntryAt
  341. * \sa SDL_SetTrayEntryEnabled
  342. */
  343. extern SDL_DECLSPEC bool SDLCALL SDL_GetTrayEntryEnabled(SDL_TrayEntry *entry);
  344. /**
  345. * Sets a callback to be invoked when the entry is selected.
  346. *
  347. * \param entry the entry to be updated.
  348. * \param callback a callback to be invoked when the entry is selected.
  349. * \param userdata an optional pointer to pass extra data to the callback when
  350. * it will be invoked.
  351. *
  352. * \since This function is available since SDL 3.1.8.
  353. *
  354. * \sa SDL_GetTrayEntries
  355. * \sa SDL_InsertTrayEntryAt
  356. */
  357. extern SDL_DECLSPEC void SDLCALL SDL_SetTrayEntryCallback(SDL_TrayEntry *entry, SDL_TrayCallback callback, void *userdata);
  358. /**
  359. * Simulate a click on a tray entry.
  360. *
  361. * \param entry The entry to activate.
  362. *
  363. * \since This function is available since SDL 3.2.0.
  364. */
  365. extern SDL_DECLSPEC void SDLCALL SDL_ClickTrayEntry(SDL_TrayEntry *entry);
  366. /**
  367. * Destroys a tray object.
  368. *
  369. * This also destroys all associated menus and entries.
  370. *
  371. * \param tray the tray icon to be destroyed.
  372. *
  373. * \since This function is available since SDL 3.1.8.
  374. *
  375. * \sa SDL_CreateTray
  376. */
  377. extern SDL_DECLSPEC void SDLCALL SDL_DestroyTray(SDL_Tray *tray);
  378. /**
  379. * Gets the menu contianing a certain tray entry.
  380. *
  381. * \param entry the entry for which to get the parent menu.
  382. * \returns the parent menu.
  383. *
  384. * \since This function is available since SDL 3.1.8.
  385. *
  386. * \sa SDL_InsertTrayEntryAt
  387. */
  388. extern SDL_DECLSPEC SDL_TrayMenu *SDLCALL SDL_GetTrayEntryParent(SDL_TrayEntry *entry);
  389. /**
  390. * Gets the entry for which the menu is a submenu, if the current menu is a
  391. * submenu.
  392. *
  393. * Either this function or SDL_GetTrayMenuParentTray() will return non-NULL
  394. * for any given menu.
  395. *
  396. * \param menu the menu for which to get the parent entry.
  397. * \returns the parent entry, or NULL if this menu is not a submenu.
  398. *
  399. * \since This function is available since SDL 3.1.8.
  400. *
  401. * \sa SDL_CreateTraySubmenu
  402. * \sa SDL_GetTrayMenuParentTray
  403. */
  404. extern SDL_DECLSPEC SDL_TrayEntry *SDLCALL SDL_GetTrayMenuParentEntry(SDL_TrayMenu *menu);
  405. /**
  406. * Gets the tray for which this menu is the first-level menu, if the current
  407. * menu isn't a submenu.
  408. *
  409. * Either this function or SDL_GetTrayMenuParentEntry() will return non-NULL
  410. * for any given menu.
  411. *
  412. * \param menu the menu for which to get the parent enttrayry.
  413. * \returns the parent tray, or NULL if this menu is a submenu.
  414. *
  415. * \since This function is available since SDL 3.1.8.
  416. *
  417. * \sa SDL_CreateTrayMenu
  418. * \sa SDL_GetTrayMenuParentEntry
  419. */
  420. extern SDL_DECLSPEC SDL_Tray *SDLCALL SDL_GetTrayMenuParentTray(SDL_TrayMenu *menu);
  421. /* Ends C function definitions when using C++ */
  422. #ifdef __cplusplus
  423. }
  424. #endif
  425. #include <SDL3/SDL_close_code.h>
  426. #endif /* SDL_tray_h_ */