1
0

SDL_notification.h 11 KB

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