Skip to content

Commit 665db48

Browse files
author
Semphris
committed
Add SDL_IsTraySupported
1 parent 168d1a9 commit 665db48

File tree

8 files changed

+58
-0
lines changed

8 files changed

+58
-0
lines changed

include/SDL3/SDL_tray.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,26 @@ typedef Uint32 SDL_TrayEntryFlags;
9696
*/
9797
typedef void (SDLCALL *SDL_TrayCallback)(void *userdata, SDL_TrayEntry *entry);
9898

99+
/**
100+
* Check whether or not tray icons can be created.
101+
*
102+
* Note that this function does not guarantee that SDL_CreateTray() will or will
103+
* not work; you should still check SDL_CreateTray() for errors. Also, the
104+
* availability of trays may change while the program is running, for example
105+
* if the user installs or uninstalls a relevant system library.
106+
*
107+
* Using tray icons require the video subsystem.
108+
*
109+
* \returns true if trays are available, false otherwise.
110+
*
111+
* \threadsafety This function should only be called on the main thread.
112+
*
113+
* \since This function is available since SDL 3.4.0.
114+
*
115+
* \sa SDL_CreateTray
116+
*/
117+
extern SDL_DECLSPEC bool SDLCALL SDL_IsTraySupported(void);
118+
99119
/**
100120
* Create an icon to be placed in the operating system's tray, or equivalent.
101121
*

src/dynapi/SDL_dynapi.sym

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1253,6 +1253,7 @@ SDL3_0.0.0 {
12531253
SDL_PutAudioStreamPlanarData;
12541254
SDL_SetAudioIterationCallbacks;
12551255
SDL_GetEventDescription;
1256+
SDL_IsTraySupported;
12561257
# extra symbols go here (don't modify this line)
12571258
local: *;
12581259
};

src/dynapi/SDL_dynapi_overrides.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1278,3 +1278,4 @@
12781278
#define SDL_PutAudioStreamPlanarData SDL_PutAudioStreamPlanarData_REAL
12791279
#define SDL_SetAudioIterationCallbacks SDL_SetAudioIterationCallbacks_REAL
12801280
#define SDL_GetEventDescription SDL_GetEventDescription_REAL
1281+
#define SDL_IsTraySupported SDL_IsTraySupported_REAL

src/dynapi/SDL_dynapi_procs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1286,3 +1286,4 @@ SDL_DYNAPI_PROC(SDL_Renderer*,SDL_CreateGPURenderer,(SDL_Window *a,SDL_GPUShader
12861286
SDL_DYNAPI_PROC(bool,SDL_PutAudioStreamPlanarData,(SDL_AudioStream *a,const void * const*b,int c,int d),(a,b,c,d),return)
12871287
SDL_DYNAPI_PROC(bool,SDL_SetAudioIterationCallbacks,(SDL_AudioDeviceID a,SDL_AudioIterationCallback b,SDL_AudioIterationCallback c,void *d),(a,b,c,d),return)
12881288
SDL_DYNAPI_PROC(int,SDL_GetEventDescription,(const SDL_Event *a,char *b,int c),(a,b,c),return)
1289+
SDL_DYNAPI_PROC(bool,SDL_IsTraySupported,(void),(),return)

src/tray/cocoa/SDL_tray.m

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,16 @@ void SDL_UpdateTrays(void)
8282
{
8383
}
8484

85+
bool SDL_IsTraySupported(void)
86+
{
87+
if (!SDL_IsMainThread()) {
88+
SDL_SetError("This function should be called on the main thread");
89+
return NULL;
90+
}
91+
92+
return true;
93+
}
94+
8595
SDL_Tray *SDL_CreateTray(SDL_Surface *icon, const char *tooltip)
8696
{
8797
if (!SDL_IsMainThread()) {

src/tray/dummy/SDL_tray.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ void SDL_UpdateTrays(void)
2929
{
3030
}
3131

32+
bool SDL_IsTraySupported(void)
33+
{
34+
return false;
35+
}
36+
3237
SDL_Tray *SDL_CreateTray(SDL_Surface *icon, const char *tooltip)
3338
{
3439
SDL_Unsupported();

src/tray/unix/SDL_tray.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,16 @@ void SDL_UpdateTrays(void)
413413
}
414414
}
415415

416+
bool SDL_IsTraySupported(void)
417+
{
418+
if (!SDL_IsMainThread()) {
419+
SDL_SetError("This function should be called on the main thread");
420+
return NULL;
421+
}
422+
423+
return init_gtk();
424+
}
425+
416426
SDL_Tray *SDL_CreateTray(SDL_Surface *icon, const char *tooltip)
417427
{
418428
if (!SDL_IsMainThread()) {

src/tray/windows/SDL_tray.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,16 @@ void SDL_UpdateTrays(void)
216216
{
217217
}
218218

219+
bool SDL_IsTraySupported(void)
220+
{
221+
if (!SDL_IsMainThread()) {
222+
SDL_SetError("This function should be called on the main thread");
223+
return NULL;
224+
}
225+
226+
return true;
227+
}
228+
219229
SDL_Tray *SDL_CreateTray(SDL_Surface *icon, const char *tooltip)
220230
{
221231
if (!SDL_IsMainThread()) {

0 commit comments

Comments
 (0)