SDL_tray.h 13 KB

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