From ce4af658ba9991a3e19e25383a6051cb101d1460 Mon Sep 17 00:00:00 2001
From: Frank Praznik <[EMAIL REDACTED]>
Date: Tue, 7 Oct 2025 11:02:49 -0400
Subject: [PATCH] events: Periodically poll tray events on *nix platforms
Tray events on *nix platforms usually run over DBus, and the events subsequently aren't delivered via the window event queue. As a result, SDL_WaitEvent() won't unblock when tray events arrive, particularly if there is no currently active window.
Wake up periodically to poll when tray items are active to avoid blocking the delivery and processing of tray events.
---
src/events/SDL_events.c | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/src/events/SDL_events.c b/src/events/SDL_events.c
index ef3510320a714..e98af739902d9 100644
--- a/src/events/SDL_events.c
+++ b/src/events/SDL_events.c
@@ -43,6 +43,10 @@
#include "../video/android/SDL_androidevents.h"
#endif
+#ifdef SDL_PLATFORM_UNIX
+#include "../tray/SDL_tray_utils.h"
+#endif
+
// An arbitrary limit so we don't have unbounded growth
#define SDL_MAX_QUEUED_EVENTS 65535
@@ -52,6 +56,9 @@
// Determines how often to pump events if joysticks or sensors are actively being read
#define EVENT_POLL_INTERVAL_NS SDL_MS_TO_NS(1)
+// Determines how often to pump events if tray items are active
+#define TRAY_POLL_INTERVAL_NS SDL_MS_TO_NS(50)
+
// Make sure the type in the SDL_Event aligns properly across the union
SDL_COMPILE_TIME_ASSERT(SDL_Event_type, sizeof(Uint32) == sizeof(SDL_EventType));
@@ -1531,6 +1538,12 @@ static Sint64 SDL_events_get_polling_interval(void)
}
#endif
+#ifdef SDL_PLATFORM_UNIX
+ if (SDL_HasActiveTrays()) {
+ // Tray events on *nix platforms run separately from window system events, and need periodic polling
+ poll_intervalNS = SDL_min(poll_intervalNS, TRAY_POLL_INTERVAL_NS);
+ }
+#endif
return poll_intervalNS;
}