SDL_notification.h 11 KB

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