Skip to content

Add SDL_IsTraySupported #13124

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions include/SDL3/SDL_tray.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,27 @@ typedef Uint32 SDL_TrayEntryFlags;
*/
typedef void (SDLCALL *SDL_TrayCallback)(void *userdata, SDL_TrayEntry *entry);

/**
* Check whether or not tray icons can be created.
*
* Note that this function does not guarantee that SDL_CreateTray() will or will
* not work; you should still check SDL_CreateTray() for errors. Also, the
* availability of trays may change while the program is running, for example
* if the user installs or uninstalls a relevant system library.
*
* Using tray icons require the video subsystem.
*
* \returns true if trays are available, false otherwise.
*
* \threadsafety This function should only be called on the main thread. It will
* return false if not called on the main thread.
*
* \since This function is available since SDL 3.4.0.
*
* \sa SDL_CreateTray
*/
extern SDL_DECLSPEC bool SDLCALL SDL_IsTraySupported(void);

/**
* Create an icon to be placed in the operating system's tray, or equivalent.
*
Expand Down
1 change: 1 addition & 0 deletions src/dynapi/SDL_dynapi.sym
Original file line number Diff line number Diff line change
Expand Up @@ -1253,6 +1253,7 @@ SDL3_0.0.0 {
SDL_PutAudioStreamPlanarData;
SDL_SetAudioIterationCallbacks;
SDL_GetEventDescription;
SDL_IsTraySupported;
# extra symbols go here (don't modify this line)
local: *;
};
1 change: 1 addition & 0 deletions src/dynapi/SDL_dynapi_overrides.h
Original file line number Diff line number Diff line change
Expand Up @@ -1278,3 +1278,4 @@
#define SDL_PutAudioStreamPlanarData SDL_PutAudioStreamPlanarData_REAL
#define SDL_SetAudioIterationCallbacks SDL_SetAudioIterationCallbacks_REAL
#define SDL_GetEventDescription SDL_GetEventDescription_REAL
#define SDL_IsTraySupported SDL_IsTraySupported_REAL
1 change: 1 addition & 0 deletions src/dynapi/SDL_dynapi_procs.h
Original file line number Diff line number Diff line change
Expand Up @@ -1286,3 +1286,4 @@ SDL_DYNAPI_PROC(SDL_Renderer*,SDL_CreateGPURenderer,(SDL_Window *a,SDL_GPUShader
SDL_DYNAPI_PROC(bool,SDL_PutAudioStreamPlanarData,(SDL_AudioStream *a,const void * const*b,int c,int d),(a,b,c,d),return)
SDL_DYNAPI_PROC(bool,SDL_SetAudioIterationCallbacks,(SDL_AudioDeviceID a,SDL_AudioIterationCallback b,SDL_AudioIterationCallback c,void *d),(a,b,c,d),return)
SDL_DYNAPI_PROC(int,SDL_GetEventDescription,(const SDL_Event *a,char *b,int c),(a,b,c),return)
SDL_DYNAPI_PROC(bool,SDL_IsTraySupported,(void),(),return)
10 changes: 10 additions & 0 deletions src/tray/cocoa/SDL_tray.m
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,16 @@ void SDL_UpdateTrays(void)
{
}

bool SDL_IsTraySupported(void)
{
if (!SDL_IsMainThread()) {
SDL_SetError("This function should be called on the main thread");
return false;
}

return true;
}

SDL_Tray *SDL_CreateTray(SDL_Surface *icon, const char *tooltip)
{
if (!SDL_IsMainThread()) {
Expand Down
5 changes: 5 additions & 0 deletions src/tray/dummy/SDL_tray.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ void SDL_UpdateTrays(void)
{
}

bool SDL_IsTraySupported(void)
{
return false;
}

SDL_Tray *SDL_CreateTray(SDL_Surface *icon, const char *tooltip)
{
SDL_Unsupported();
Expand Down
10 changes: 10 additions & 0 deletions src/tray/unix/SDL_tray.c
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,16 @@ void SDL_UpdateTrays(void)
}
}

bool SDL_IsTraySupported(void)
{
if (!SDL_IsMainThread()) {
SDL_SetError("This function should be called on the main thread");
return false;
}

return init_gtk();
}

SDL_Tray *SDL_CreateTray(SDL_Surface *icon, const char *tooltip)
{
if (!SDL_IsMainThread()) {
Expand Down
10 changes: 10 additions & 0 deletions src/tray/windows/SDL_tray.c
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,16 @@ void SDL_UpdateTrays(void)
{
}

bool SDL_IsTraySupported(void)
{
if (!SDL_IsMainThread()) {
SDL_SetError("This function should be called on the main thread");
return false;
}

return true;
}

SDL_Tray *SDL_CreateTray(SDL_Surface *icon, const char *tooltip)
{
if (!SDL_IsMainThread()) {
Expand Down
Loading