SDL_notification.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2026 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. * # CategoryNotifications
  20. *
  21. * Notifications are temporary popup dialogs that passively present
  22. * information to the user, or prompt user action. They are managed
  23. * and presented by the system, and can present simple options for
  24. * user feedback, usually in the form of buttons.
  25. *
  26. * The capabilities of notifications, and how they are displayed,
  27. * vary between systems, but they generally allow for a title,
  28. * message body, an associated image, and buttons to allow the user
  29. * to provide feedback.
  30. *
  31. * How notifications are presented and handled are subject to system
  32. * policy, and it should not be assumed that showing a notification
  33. * means that the user will see it immediately, if at all. The
  34. * user may disable notifications for certain applications, they may
  35. * be suppressed based on the current activity, and most systems
  36. * provide a "do not disturb" mode that universally silences
  37. * notifications when activated.
  38. *
  39. * There is both a customizable function `SDL_ShowNotificationWithProperties()`
  40. * that offers many options for what is displayed, and also a much-simplified
  41. * version `SDL_ShowSimpleNotification()`, which simply takes a header (required),
  42. * body (optional), and image (optional).
  43. */
  44. #ifndef SDL_notification_h_
  45. #define SDL_notification_h_
  46. #include <SDL3/SDL_properties.h>
  47. #include <SDL3/SDL_stdinc.h>
  48. #include <SDL3/SDL_surface.h>
  49. #include <SDL3/SDL_begin_code.h>
  50. /* Set up for C function definitions, even when using C++ */
  51. #ifdef __cplusplus
  52. extern "C" {
  53. #endif
  54. /**
  55. * The path to an image to be used as the header icon for system notifications on
  56. * some platforms. This is required on:
  57. * - Windows
  58. * - *nix when not running in a container, and no .desktop entry is available
  59. *
  60. * Image types supported depend on the platform, but .png generally offers the best
  61. * compatability.
  62. *
  63. * On *nix platforms, this can also be the name of a system icon, as specified by
  64. * the Icon Naming Specification.
  65. *
  66. * Can be set before calling SDL_ShowNotification() or SDL_ShowSimpleNotification()
  67. * for the first time.
  68. *
  69. * \since This macro is available since SDL 3.6.0.
  70. */
  71. #define SDL_PROP_GLOBAL_NOTIFICATION_HEADER_ICON_STRING "SDL.notification.header_icon"
  72. typedef Uint32 SDL_NotificationID; /**< The identifier for a system notification. */
  73. typedef enum SDL_NotificationPriority
  74. {
  75. SDL_NOTIFICATION_PRIORITY_LOW = -1, /**< Lowest priority. */
  76. SDL_NOTIFICATION_PRIORITY_NORMAL = 0, /**< Normal/medium priority. */
  77. SDL_NOTIFICATION_PRIORITY_HIGH = 1, /**< High/important priority. */
  78. SDL_NOTIFICATION_PRIORITY_CRITICAL = 2 /**< Highest/critical priority. Note that this may override any "Do Not Disturb" settings and wake the screen. */
  79. } SDL_NotificationPriority;
  80. typedef enum SDL_NotificationActionType
  81. {
  82. SDL_NOTIFICATION_ACTION_TYPE_BUTTON = 1 /**< Adds a button to the notification that generates feedback when activated. */
  83. } SDL_NotificationActionType;
  84. /**
  85. * Notification structure describing actions that can be used to allow users
  86. * to interact with notification dialogs. Exactly How they are presented depends
  87. * on the platform and implementation.
  88. *
  89. * User interactions with a notification are reported via events with the type
  90. * SDL_EVENT_NOTIFICATION_ACTION_INVOKED.
  91. *
  92. * Action types:
  93. * - button: A button with a localized text label, which generates feedback when activated.
  94. *
  95. * \sa SDL_NotificationEvent
  96. * \sa SDL_NotificationActionType
  97. */
  98. typedef union SDL_NotificationAction
  99. {
  100. SDL_NotificationActionType type;
  101. struct
  102. {
  103. SDL_NotificationActionType type; /**< SDL_NOTIFICATION_ACTION_TYPE_BUTTON */
  104. const char *action_id; /**< The identifier string for the button. 'default' is a reserved identifier and must not be used. */
  105. const char *action_label; /**< The localized label for the button associated with the action, in UTF-8 encoding. */
  106. } button;
  107. Uint8 padding[128];
  108. } SDL_NotificationAction;
  109. #define SDL_PROP_NOTIFICATION_ACTIONS_POINTER "SDL.notification.actions"
  110. #define SDL_PROP_NOTIFICATION_ACTION_COUNT_NUMBER "SDL.notification.action_count"
  111. #define SDL_PROP_NOTIFICATION_IMAGE_POINTER "SDL.notification.image"
  112. #define SDL_PROP_NOTIFICATION_MESSAGE_STRING "SDL.notification.message"
  113. #define SDL_PROP_NOTIFICATION_PRIORITY_NUMBER "SDL.notification.priority"
  114. #define SDL_PROP_NOTIFICATION_REPLACES_NUMBER "SDL.notification.replaces"
  115. #define SDL_PROP_NOTIFICATION_SOUND_STRING "SDL.notification.sound"
  116. #define SDL_PROP_NOTIFICATION_TRANSIENT_BOOLEAN "SDL.notification.transient"
  117. #define SDL_PROP_NOTIFICATION_TITLE_STRING "SDL.notification.title"
  118. /**
  119. * Requests permission from the system to display notifications. A return value of `true`
  120. * only means that the system supports notifications, and that the request for permission
  121. * was successfully issued. It does not reflect any user settings to allow or deny
  122. * notifications.
  123. *
  124. * \returns True on success or false on failure; call
  125. * SDL_GetError() for more information.
  126. *
  127. * \since This function is available since SDL 3.6.0
  128. *
  129. * \sa SDL_ShowNotification
  130. * \sa SDL_ShowNotificationWithProperties
  131. * \sa SDL_NotificationAction
  132. */
  133. extern SDL_DECLSPEC bool SDLCALL SDL_RequestNotificationPermission(void);
  134. /**
  135. * Show a system notification.
  136. *
  137. * System notifications are small, asynchronous popup windows that notify the user
  138. * of some information. How they are displayed is system dependent.
  139. *
  140. * These are the supported properties:
  141. *
  142. * - `SDL_PROP_NOTIFICATION_TITLE_STRING`: the title of the notification, in
  143. * UTF-8 encoding. This property is required.
  144. * - `SDL_PROP_NOTIFICATION_ACTIONS_POINTER`: An array of pointers to `SDL_NotificationAction`
  145. * structs that will add actions to the notification, usually in the form of buttons or menu
  146. * items. Note that systems may have a limit on the maximum number of actions that a
  147. * notification can have.
  148. * - `SDL_PROP_NOTIFICATIONS_ACTION_COUNT_NUMBER`: the number of actions in the array of actions,
  149. * if it exists.
  150. * - `SDL_PROP_NOTIFICATION_IMAGE_POINTER`: a pointer to an `SDL_Surface` containing
  151. * an image that will be attached to the notification. In most cases, the image is displayed
  152. * in the form of a large icon or thumbnail alongside the message body. Notifications on Apple
  153. * platforms can be expanded to show a larger format image.
  154. * - `SDL_PROP_NOTIFICATION_MESSAGE_STRING`: the message body of the notification,
  155. * in UTF-8 encoding.
  156. * - `SDL_PROP_NOTIFICATION_PRIORITY_NUMBER`: an `SDL_NotificationPriority` value representing
  157. * the notification priority.
  158. * - `SDL_PROP_NOTIFICATION_REPLACES_NUMBER`: the `SDL_NotificationID` of a previously
  159. * shown notification that this notification should replace.
  160. * - `SDL_PROP_NOTIFICATION_SOUND_STRING`: sets a sound to play when the notification is shown.
  161. * This can have the value "default", to play the system default notification sound, "silent",
  162. * to play no sound, or contain the path to a file with a custom sound. The paths and formats
  163. * that can be used for custom sounds are system-specific, and can have some restrictions,
  164. * depending on the platform:
  165. * - Apple platforms require that the sound file is contained within the app bundle. Supported
  166. * formats are: Linear PCM, MA4 (IMA/ADPCM), uLaw, or aLaw, in an .aiff, .wav, or .caf file.
  167. * - Windows can only play custom notification sounds when the app is packaged inside an MSIX
  168. * installer. Playback from arbitrary file paths is not supported. Supported formats are:
  169. * .aac, .flac, .m4a, .mp3, .wav, and .wma.
  170. * - Unix platforms can generally load sounds from any arbitrary path, as long as the read
  171. * permissions are correct. Supported formats are: ogg/opus, ogg/vorbis, and wav/pcm.
  172. * If this property is not set, the system default sound will be used.
  173. * - `SDL_PROP_NOTIFICATION_TRANSIENT_BOOLEAN`: true if the notification should not persist
  174. * in the system notification center after initially being shown.
  175. *
  176. * Not all properties are supported by all platforms.
  177. *
  178. * Notifications are available on:
  179. * - Windows 10 or higher
  180. * - macOS 10.14 or higher
  181. * - iOS 11 or higher
  182. * - *nix platforms that support the org.freedesktop.Notifications, or
  183. * org.freedesktop.portal.Notification interfaces
  184. *
  185. * \param props the properties to be used when creating this notification.
  186. * \returns A non-zero SDL_NotificationID on success or 0 on failure; call
  187. * SDL_GetError() for more information.
  188. *
  189. * \since This function is available since SDL 3.6.0
  190. *
  191. * \sa SDL_ShowNotification
  192. * \sa SDL_NotificationAction
  193. * \sa SDL_NotificationPriority
  194. * \sa SDL_NotificationEvent
  195. */
  196. extern SDL_DECLSPEC SDL_NotificationID SDLCALL SDL_ShowNotificationWithProperties(SDL_PropertiesID props);
  197. /**
  198. * Show a system notification with normal priority.
  199. *
  200. * \param title UTF-8 title text, required.
  201. * \param message UTF-8 message text, may be NULL.
  202. * \param image The image associated with this notification, may be NULL.
  203. * \param actions An array of actions to attach to the notification, may be NULL.
  204. * \param num_actions The number of actions in the actions array.
  205. * \returns A non-zero SDL_NotificationID on success or 0 on failure; call
  206. * SDL_GetError() for more information.
  207. *
  208. * \since This function is available since SDL 3.6.0
  209. *
  210. * \sa SDL_ShowNotificationWithProperties
  211. * \sa SDL_NotificationAction
  212. * \sa SDL_NotificationEvent
  213. */
  214. extern SDL_DECLSPEC SDL_NotificationID SDLCALL SDL_ShowNotification(const char *title, const char *message, SDL_Surface *image, SDL_NotificationAction *actions, int num_actions);
  215. /**
  216. * Remove a notification.
  217. *
  218. * \param notification the ID of the notification to remove.
  219. * \returns True on success or false on failure; call
  220. * SDL_GetError() for more information.
  221. *
  222. * \since This function is available since SDL 3.6.0
  223. *
  224. * \sa SDL_ShowNotificationWithProperties
  225. * \sa SDL_ShowNotification
  226. */
  227. extern SDL_DECLSPEC bool SDLCALL SDL_RemoveNotification(SDL_NotificationID notification);
  228. // Ends C function definitions when using C++
  229. #ifdef __cplusplus
  230. }
  231. #endif
  232. #include <SDL3/SDL_close_code.h>
  233. #endif // SDL_notification_h_