Skip to content

Commit e082fc0

Browse files
author
Semphris
committed
Add SDL_IsTraySupported
1 parent 8bd29f7 commit e082fc0

File tree

8 files changed

+65
-0
lines changed

8 files changed

+65
-0
lines changed

include/SDL3/SDL_tray.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,25 @@ 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.
104+
*
105+
* Using tray icons require the video subsystem.
106+
*
107+
* \returns true if trays are available, false otherwise.
108+
*
109+
* \threadsafety This function should only be called on the main thread. It will
110+
* return false if not called on the main thread.
111+
*
112+
* \since This function is available since SDL 3.4.0.
113+
*
114+
* \sa SDL_CreateTray
115+
*/
116+
extern SDL_DECLSPEC bool SDLCALL SDL_IsTraySupported(void);
117+
99118
/**
100119
* Create an icon to be placed in the operating system's tray, or equivalent.
101120
*

src/dynapi/SDL_dynapi.sym

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

src/dynapi/SDL_dynapi_overrides.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1279,3 +1279,4 @@
12791279
#define SDL_SetAudioIterationCallbacks SDL_SetAudioIterationCallbacks_REAL
12801280
#define SDL_GetEventDescription SDL_GetEventDescription_REAL
12811281
#define SDL_PutAudioStreamDataNoCopy SDL_PutAudioStreamDataNoCopy_REAL
1282+
#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
@@ -1287,3 +1287,4 @@ SDL_DYNAPI_PROC(bool,SDL_PutAudioStreamPlanarData,(SDL_AudioStream *a,const void
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)
12891289
SDL_DYNAPI_PROC(bool,SDL_PutAudioStreamDataNoCopy,(SDL_AudioStream *a,const void *b,int c,SDL_AudioStreamDataCompleteCallback d,void *e),(a,b,c,d,e),return)
1290+
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 false;
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: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,24 @@ 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 false;
421+
}
422+
423+
static bool has_trays = false;
424+
static bool has_been_detected_once = false;
425+
426+
if (!has_been_detected_once) {
427+
has_trays = init_gtk();
428+
has_been_detected_once = true;
429+
}
430+
431+
return has_trays;
432+
}
433+
416434
SDL_Tray *SDL_CreateTray(SDL_Surface *icon, const char *tooltip)
417435
{
418436
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 false;
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)