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