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