SDL3pp
A slim C++ wrapper for SDL3
Loading...
Searching...
No Matches
Classes | Typedefs | Functions | Variables

SDL offers a way to add items to the "system tray" (more correctly called the "notification area" on Windows). More...

Classes

struct  SDL::TrayBase
 An opaque handle representing a toplevel system tray object. More...
 
struct  SDL::TrayRef
 Handle to a non owned tray. More...
 
struct  SDL::Tray
 Handle to an owned tray. More...
 
class  SDL::TrayMenu
 An opaque handle representing a menu/submenu on a system tray object. More...
 
struct  SDL::TrayEntryBase
 An opaque handle representing an entry on a system tray object. More...
 
struct  SDL::TrayEntryRef
 Handle to a non owned trayEntry. More...
 
struct  SDL::TrayEntry
 Handle to an owned trayEntry. More...
 

Typedefs

using SDL::DetachedTrayEntry = DetachedResource< TrayEntryRef, TrayEntry >
 A trayEntry result that will be owned only if assigned to a TrayEntry.
 
using SDL::TrayEntryFlags = Uint32
 Flags that control the creation of system tray entries.
 
using SDL::TrayCallback = SDL_TrayCallback
 A callback that is invoked when a tray entry is selected.
 
using SDL::TrayCB = std::function< void(TrayEntryRef)>
 A callback that is invoked when a tray entry is selected.
 

Functions

void SDL::UpdateTrays ()
 Update the trays.
 
TrayMenu SDL::TrayBase::CreateMenu ()
 Create a menu for a system tray.
 
TrayMenu SDL::TrayBase::GetMenu () const
 Gets a previously created tray menu.
 
std::span< TrayEntrySDL::TrayMenu::GetEntries ()
 Returns a list of entries in the menu, in order.
 
DetachedTrayEntry SDL::TrayMenu::InsertEntry (int pos, StringParam label, TrayEntryFlags flags)
 Insert a tray entry at a given position.
 
TrayEntryRef SDL::TrayMenu::GetParentEntry () const
 Gets the entry for which the menu is a submenu, if the current menu is a submenu.
 
TrayRef SDL::TrayMenu::GetParentTray () const
 Gets the tray for which this menu is the first-level menu, if the current menu isn't a submenu.
 

Variables

constexpr TrayEntryFlags SDL::TRAYENTRY_BUTTON
 Make the entry a simple button. Required.
 
constexpr TrayEntryFlags SDL::TRAYENTRY_CHECKBOX
 Make the entry a checkbox. Required.
 
constexpr TrayEntryFlags SDL::TRAYENTRY_SUBMENU
 Prepare the entry to have a submenu. Required.
 
constexpr TrayEntryFlags SDL::TRAYENTRY_DISABLED
 Make the entry disabled. Optional.
 
constexpr TrayEntryFlags SDL::TRAYENTRY_CHECKED = SDL_TRAYENTRY_CHECKED
 Make the entry checked.
 

Detailed Description

On platforms that offer this concept, an SDL app can add a tray icon, submenus, checkboxes, and clickable entries, and register a callback that is fired when the user clicks on these pieces.

Typedef Documentation

◆ DetachedTrayEntry

This is designed as resource types to cases where ownership might not be required.

◆ TrayCallback

using SDL::TrayCallback = typedef SDL_TrayCallback
Parameters
userdataan optional pointer to pass extra data to the callback when it will be invoked.
entrythe tray entry that was selected.
Since
This datatype is available since SDL 3.2.0.
See also
TrayEntryBase.SetCallback

◆ TrayCB

using SDL::TrayCB = typedef std::function<void(TrayEntryRef)>
Parameters
entrythe tray entry that was selected.
Since
This datatype is available since SDL 3.2.0.
See also
TrayEntryBase.SetCallback

◆ TrayEntryFlags

using SDL::TrayEntryFlags = typedef Uint32

Some of these flags are required; exactly one of them must be specified at the time a tray entry is created. Other flags are optional; zero or more of those can be OR'ed together with the required flag.

Since
This datatype is available since SDL 3.2.0.
See also
TrayMenu.InsertEntry

Function Documentation

◆ CreateMenu()

TrayMenu SDL::TrayBase::CreateMenu ( )
inline

This should be called at most once per tray icon.

This function does the same thing as TrayEntryBase.CreateSubmenu(), except that it takes a TrayBase instead of a TrayEntryBase.

A menu does not need to be destroyed; it will be destroyed with the tray.

Returns
the newly created menu.
Thread safety:
This function should be called on the thread that created the tray.
Since
This function is available since SDL 3.2.0.
See also
TrayBase.TrayBase
TrayBase.GetMenu
TrayMenu.GetParentTray

◆ GetEntries()

std::span< TrayEntry > SDL::TrayMenu::GetEntries ( )
inline
Returns
a nullptr-terminated list of entries within the given menu. The pointer becomes invalid when any function that inserts or deletes entries in the menu is called.
Thread safety:
This function should be called on the thread that created the tray.
Since
This function is available since SDL 3.2.0.
See also
TrayEntryRef.Remove
TrayMenu.InsertEntry

◆ GetMenu()

TrayMenu SDL::TrayBase::GetMenu ( ) const
inline

You should have called TrayBase.CreateMenu() on the tray object. This function allows you to fetch it again later.

This function does the same thing as TrayEntryBase.GetSubmenu(), except that it takes a TrayBase instead of a TrayEntryBase.

A menu does not need to be destroyed; it will be destroyed with the tray.

Returns
the newly created menu.
Thread safety:
This function should be called on the thread that created the tray.
Since
This function is available since SDL 3.2.0.
See also
TrayBase.TrayBase
TrayBase.CreateMenu

◆ GetParentEntry()

TrayEntryRef SDL::TrayMenu::GetParentEntry ( ) const
inline

Either this function or TrayMenu.GetParentTray() will return non-nullptr for any given menu.

Returns
the parent entry, or nullptr if this menu is not a submenu.
Thread safety:
This function should be called on the thread that created the tray.
Since
This function is available since SDL 3.2.0.
See also
TrayEntryBase.CreateSubmenu
TrayMenu.GetParentTray

◆ GetParentTray()

TrayRef SDL::TrayMenu::GetParentTray ( ) const
inline

Either this function or TrayMenu.GetParentEntry() will return non-nullptr for any given menu.

Returns
the parent tray, or nullptr if this menu is a submenu.
Thread safety:
This function should be called on the thread that created the tray.
Since
This function is available since SDL 3.2.0.
See also
TrayBase.CreateMenu
TrayMenu.GetParentEntry

◆ InsertEntry()

DetachedTrayEntry SDL::TrayMenu::InsertEntry ( int  pos,
StringParam  label,
TrayEntryFlags  flags 
)
inline

If label is nullptr, the entry will be a separator. Many functions won't work for an entry that is a separator.

An entry does not need to be destroyed; it will be destroyed with the tray.

Parameters
posthe desired position for the new entry. Entries at or following this place will be moved. If pos is -1, the entry is appended.
labelthe text to be displayed on the entry, in UTF-8 encoding, or nullptr for a separator.
flagsa combination of flags, some of which are mandatory.
Returns
the newly created entry, or nullptr if pos is out of bounds.
Thread safety:
This function should be called on the thread that created the tray.
Since
This function is available since SDL 3.2.0.
See also
TrayMenu.AppendEntry
TrayEntryFlags
TrayMenu.GetEntries
TrayEntryRef.Remove
TrayEntryBase.GetParent

◆ UpdateTrays()

void SDL::UpdateTrays ( )
inline

This is called automatically by the event loop and is only needed if you're using trays but aren't handling SDL events.

Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.

Variable Documentation

◆ TRAYENTRY_BUTTON

constexpr TrayEntryFlags SDL::TRAYENTRY_BUTTON
constexpr
Initial value:
=
SDL_TRAYENTRY_BUTTON

◆ TRAYENTRY_CHECKBOX

constexpr TrayEntryFlags SDL::TRAYENTRY_CHECKBOX
constexpr
Initial value:
=
SDL_TRAYENTRY_CHECKBOX

◆ TRAYENTRY_CHECKED

constexpr TrayEntryFlags SDL::TRAYENTRY_CHECKED = SDL_TRAYENTRY_CHECKED
constexpr

This is valid only for checkboxes. Optional.

◆ TRAYENTRY_DISABLED

constexpr TrayEntryFlags SDL::TRAYENTRY_DISABLED
constexpr
Initial value:
=
SDL_TRAYENTRY_DISABLED

◆ TRAYENTRY_SUBMENU

constexpr TrayEntryFlags SDL::TRAYENTRY_SUBMENU
constexpr
Initial value:
=
SDL_TRAYENTRY_SUBMENU