4#include <SDL3/SDL_tray.h>
5#include "SDL3pp_stdinc.h"
6#include "SDL3pp_surface.h"
49 constexpr explicit operator bool()
const {
return !!
value; }
94 constexpr explicit operator bool()
const {
return !!
value; }
117 SDL_TRAYENTRY_BUTTON;
120 SDL_TRAYENTRY_CHECKBOX;
123 SDL_TRAYENTRY_SUBMENU;
126 SDL_TRAYENTRY_DISABLED;
179 : m_resource(resource)
220 : m_resource(SDL_CreateTray(icon, tooltip))
225 ~Tray() { SDL_DestroyTray(m_resource); }
230 std::swap(m_resource, other.m_resource);
241 m_resource =
nullptr;
249 constexpr bool operator==(std::nullptr_t _)
const {
return !m_resource; }
252 constexpr explicit operator bool()
const {
return !!m_resource; }
255 constexpr operator TrayParam()
const {
return {m_resource}; }
358 :
Tray(resource.value)
388 : m_trayMenu(trayMenu)
529 : m_resource(resource)
548 std::swap(m_resource, other.m_resource);
559 m_resource =
nullptr;
567 constexpr bool operator==(std::nullptr_t _)
const {
return !m_resource; }
570 constexpr explicit operator bool()
const {
return !!m_resource; }
842 return Tray(icon, std::move(tooltip));
860 SDL_SetTrayIcon(tray, icon);
883 SDL_SetTrayTooltip(tray, tooltip);
915 return SDL_CreateTrayMenu(tray);
944 return SDL_CreateTraySubmenu(entry);
1002 return SDL_GetTraySubmenu(entry);
1029 auto entries = SDL_GetTrayEntries(menu, &count);
1030 return std::span<TrayEntry>{
reinterpret_cast<TrayEntry*
>(entries),
1087 return SDL_InsertTrayEntryAt(menu, pos, label, flags);
1119 SDL_SetTrayEntryLabel(entry, label);
1146 return SDL_GetTrayEntryLabel(entry);
1173 SDL_SetTrayEntryChecked(entry, checked);
1200 return SDL_GetTrayEntryChecked(entry);
1225 SDL_SetTrayEntryEnabled(entry, enabled);
1250 return SDL_GetTrayEntryEnabled(entry);
1278 SDL_SetTrayEntryCallback(entry, callback, userdata);
1333 return SDL_GetTrayEntryParent(entry);
1361 return SDL_GetTrayMenuParentEntry(menu);
1389 return SDL_GetTrayMenuParentTray(menu);
1420 SDL_TrayEntry* entry) { Wrapper::Call(userdata, entry); },
1421 Wrapper::Wrap(
get(), std::move(callback)));
Helpers to use C++ strings parameters.
Definition: SDL3pp_strings.h:43
An opaque handle representing an entry on a system tray object.
Definition: SDL3pp_tray.h:516
constexpr TrayEntryRaw get() const
Retrieves underlying TrayEntryRaw.
Definition: SDL3pp_tray.h:553
constexpr TrayEntry()=default
Default ctor.
TrayEntry & operator=(TrayEntry other)
Assignment operator.
Definition: SDL3pp_tray.h:546
constexpr TrayEntry(const TrayEntry &other)=default
Copy constructor.
void SetCallback(TrayCB callback)
Sets a callback to be invoked when the entry is selected.
Definition: SDL3pp_tray.h:1416
constexpr bool operator==(std::nullptr_t _) const
Comparison.
Definition: SDL3pp_tray.h:567
constexpr auto operator<=>(const TrayEntry &other) const =default
Comparison.
constexpr TrayEntry(TrayEntry &&other)
Move constructor.
Definition: SDL3pp_tray.h:537
~TrayEntry()
Destructor.
Definition: SDL3pp_tray.h:543
constexpr TrayEntry(const TrayEntryRaw resource)
Constructs from TrayEntryParam.
Definition: SDL3pp_tray.h:528
constexpr TrayEntryRaw release()
Retrieves underlying TrayEntryRaw and clear this.
Definition: SDL3pp_tray.h:556
An opaque handle representing a toplevel system tray object.
Definition: SDL3pp_tray.h:164
constexpr bool operator==(std::nullptr_t _) const
Comparison.
Definition: SDL3pp_tray.h:249
constexpr Tray()=default
Default ctor.
constexpr TrayRaw release()
Retrieves underlying TrayRaw and clear this.
Definition: SDL3pp_tray.h:238
constexpr Tray(const TrayRaw resource)
Constructs from TrayParam.
Definition: SDL3pp_tray.h:178
~Tray()
Destructor.
Definition: SDL3pp_tray.h:225
constexpr auto operator<=>(const Tray &other) const =default
Comparison.
constexpr Tray(Tray &&other)
Move constructor.
Definition: SDL3pp_tray.h:187
constexpr TrayRaw get() const
Retrieves underlying TrayRaw.
Definition: SDL3pp_tray.h:235
Tray(SurfaceParam icon, StringParam tooltip)
Create an icon to be placed in the operating system's tray, or equivalent.
Definition: SDL3pp_tray.h:219
constexpr Tray(const Tray &other)=delete
Copy constructor.
Tray & operator=(Tray other)
Assignment operator.
Definition: SDL3pp_tray.h:228
Uint32 Uint32
An unsigned 32-bit integer type.
Definition: SDL3pp_stdinc.h:328
TrayMenu CreateSubmenu()
Create a submenu for a system tray entry.
Definition: SDL3pp_tray.h:947
TrayEntry InsertEntry(int pos, StringParam label, TrayEntryFlags flags)
Insert a tray entry at a given position.
Definition: SDL3pp_tray.h:1090
SDL_TrayMenu * TrayMenuRaw
Alias to raw representation for TrayMenu.
Definition: SDL3pp_tray.h:62
void SetTooltip(StringParam tooltip)
Updates the system tray icon's tooltip.
Definition: SDL3pp_tray.h:886
void SetTrayEntryEnabled(TrayEntryParam entry, bool enabled)
Sets whether or not an entry is enabled.
Definition: SDL3pp_tray.h:1223
void UpdateTrays()
Update the trays.
Definition: SDL3pp_tray.h:1407
bool GetTrayEntryEnabled(TrayEntryParam entry)
Gets whether or not an entry is enabled.
Definition: SDL3pp_tray.h:1248
TrayEntry InsertTrayEntryAt(TrayMenu menu, int pos, StringParam label, TrayEntryFlags flags)
Insert a tray entry at a given position.
Definition: SDL3pp_tray.h:1082
TrayEntryParam GetParentEntry() const
Gets the entry for which the menu is a submenu, if the current menu is a submenu.
Definition: SDL3pp_tray.h:1364
TrayMenu GetMenu() const
Gets a previously created tray menu.
Definition: SDL3pp_tray.h:976
void DestroyTray(TrayRaw tray)
Destroys a tray object.
Definition: SDL3pp_tray.h:1314
constexpr TrayEntryFlags TRAYENTRY_BUTTON
Make the entry a simple button. Required.
Definition: SDL3pp_tray.h:116
void SetIcon(SurfaceParam icon)
Updates the system tray icon's icon.
Definition: SDL3pp_tray.h:863
void SetChecked(bool checked)
Sets whether or not an entry is checked.
Definition: SDL3pp_tray.h:1176
constexpr TrayEntryFlags TRAYENTRY_DISABLED
Make the entry disabled. Optional.
Definition: SDL3pp_tray.h:125
TrayParam GetTrayMenuParentTray(TrayMenuRaw menu)
Gets the tray for which this menu is the first-level menu, if the current menu isn't a submenu.
Definition: SDL3pp_tray.h:1387
TrayMenu CreateMenu()
Create a menu for a system tray.
Definition: SDL3pp_tray.h:918
void SetTrayEntryCallback(TrayEntryParam entry, TrayCallback callback, void *userdata)
Sets a callback to be invoked when the entry is selected.
Definition: SDL3pp_tray.h:1274
TrayMenu GetParent()
Gets the menu containing a certain tray entry.
Definition: SDL3pp_tray.h:1336
void SetTrayEntryLabel(TrayEntryParam entry, StringParam label)
Sets the label of an entry.
Definition: SDL3pp_tray.h:1117
TrayMenu GetTrayEntryParent(TrayEntryParam entry)
Gets the menu containing a certain tray entry.
Definition: SDL3pp_tray.h:1331
std::function< void(TrayEntryRaw)> TrayCB
A callback that is invoked when a tray entry is selected.
Definition: SDL3pp_tray.h:154
void Click()
Simulate a click on a tray entry.
Definition: SDL3pp_tray.h:1298
std::span< TrayEntry > GetTrayEntries(TrayMenu menu)
Returns a list of entries in the menu, in order.
Definition: SDL3pp_tray.h:1026
void SetTrayIcon(TrayParam tray, SurfaceParam icon)
Updates the system tray icon's icon.
Definition: SDL3pp_tray.h:858
TrayMenu GetTraySubmenu(TrayEntryParam entry)
Gets a previously created tray entry submenu.
Definition: SDL3pp_tray.h:1000
void Destroy()
Destroys a tray object.
Definition: SDL3pp_tray.h:1316
void SetEnabled(bool enabled)
Sets whether or not an entry is enabled.
Definition: SDL3pp_tray.h:1228
TrayMenu CreateTrayMenu(TrayParam tray)
Create a menu for a system tray.
Definition: SDL3pp_tray.h:913
void RemoveTrayEntry(TrayEntryRaw entry)
Removes a tray entry.
Definition: SDL3pp_tray.h:1052
void ClickTrayEntry(TrayEntryParam entry)
Simulate a click on a tray entry.
Definition: SDL3pp_tray.h:1296
Tray CreateTray(SurfaceParam icon, StringParam tooltip)
Create an icon to be placed in the operating system's tray, or equivalent.
Definition: SDL3pp_tray.h:840
TrayEntryParam GetTrayMenuParentEntry(TrayMenuRaw menu)
Gets the entry for which the menu is a submenu, if the current menu is a submenu.
Definition: SDL3pp_tray.h:1359
bool GetTrayEntryChecked(TrayEntryParam entry)
Gets whether or not an entry is checked.
Definition: SDL3pp_tray.h:1198
const char * GetTrayEntryLabel(TrayEntryParam entry)
Gets the label of an entry.
Definition: SDL3pp_tray.h:1144
TrayMenu GetSubmenu()
Gets a previously created tray entry submenu.
Definition: SDL3pp_tray.h:1005
const char * GetLabel() const
Gets the label of an entry.
Definition: SDL3pp_tray.h:1149
bool GetChecked() const
Gets whether or not an entry is checked.
Definition: SDL3pp_tray.h:1203
SDL_TrayEntry * TrayEntryRaw
Alias to raw representation for TrayEntry.
Definition: SDL3pp_tray.h:71
std::span< TrayEntry > GetEntries()
Returns a list of entries in the menu, in order.
Definition: SDL3pp_tray.h:1034
SDL_TrayCallback TrayCallback
A callback that is invoked when a tray entry is selected.
Definition: SDL3pp_tray.h:142
bool GetEnabled() const
Gets whether or not an entry is enabled.
Definition: SDL3pp_tray.h:1253
void SetTrayTooltip(TrayParam tray, StringParam tooltip)
Updates the system tray icon's tooltip.
Definition: SDL3pp_tray.h:881
TrayParam GetParentTray() const
Gets the tray for which this menu is the first-level menu, if the current menu isn't a submenu.
Definition: SDL3pp_tray.h:1392
constexpr TrayEntryFlags TRAYENTRY_CHECKED
Make the entry checked. This is valid only for checkboxes. Optional.
Definition: SDL3pp_tray.h:129
void Remove()
Removes a tray entry.
Definition: SDL3pp_tray.h:1054
Uint32 TrayEntryFlags
Flags that control the creation of system tray entries.
Definition: SDL3pp_tray.h:114
TrayMenu GetTrayMenu(TrayParam tray)
Gets a previously created tray menu.
Definition: SDL3pp_tray.h:974
TrayMenu CreateTraySubmenu(TrayEntryParam entry)
Create a submenu for a system tray entry.
Definition: SDL3pp_tray.h:942
void SetTrayEntryChecked(TrayEntryParam entry, bool checked)
Sets whether or not an entry is checked.
Definition: SDL3pp_tray.h:1171
constexpr TrayEntryFlags TRAYENTRY_SUBMENU
Prepare the entry to have a submenu. Required.
Definition: SDL3pp_tray.h:122
constexpr TrayEntryFlags TRAYENTRY_CHECKBOX
Make the entry a checkbox. Required.
Definition: SDL3pp_tray.h:119
void SetLabel(StringParam label)
Sets the label of an entry.
Definition: SDL3pp_tray.h:1122
SDL_Tray * TrayRaw
Alias to raw representation for Tray.
Definition: SDL3pp_tray.h:26
Main include header for the SDL3pp library.
Store callbacks by key.
Definition: SDL3pp_callbackWrapper.h:222
Safely wrap Surface for non owning parameters.
Definition: SDL3pp_surface.h:46
Safely wrap TrayEntry for non owning parameters.
Definition: SDL3pp_tray.h:78
constexpr TrayEntryParam(TrayEntryRaw value)
Constructs from TrayEntryRaw.
Definition: SDL3pp_tray.h:82
constexpr auto operator<=>(const TrayEntryParam &other) const =default
Comparison.
constexpr TrayEntryParam(std::nullptr_t _=nullptr)
Constructs null/invalid.
Definition: SDL3pp_tray.h:88
TrayEntryRaw value
parameter's TrayEntryRaw
Definition: SDL3pp_tray.h:79
RAII owning version TrayEntry.
Definition: SDL3pp_tray.h:802
constexpr TrayEntryScoped(TrayEntry &&other)
Move constructor.
Definition: SDL3pp_tray.h:808
~TrayEntryScoped()
Destructor.
Definition: SDL3pp_tray.h:814
Safely wrap Tray for non owning parameters.
Definition: SDL3pp_tray.h:33
TrayRaw value
parameter's TrayRaw
Definition: SDL3pp_tray.h:34
constexpr auto operator<=>(const TrayParam &other) const =default
Comparison.
constexpr TrayParam(std::nullptr_t _=nullptr)
Constructs null/invalid.
Definition: SDL3pp_tray.h:43
constexpr TrayParam(TrayRaw value)
Constructs from TrayRaw.
Definition: SDL3pp_tray.h:37
Semi-safe reference for Tray.
Definition: SDL3pp_tray.h:349
TrayRef(TrayParam resource)
Constructs from TrayParam.
Definition: SDL3pp_tray.h:357
~TrayRef()
Destructor.
Definition: SDL3pp_tray.h:369
TrayRef(const TrayRef &other)
Copy constructor.
Definition: SDL3pp_tray.h:363