Add new verbosity level for logging of `SDL_SysWMEvent`s Now logged only if SDL_HINT_EVENT_LOGGING is set to "3" or above.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
diff --git a/include/SDL_hints.h b/include/SDL_hints.h
index 03bbb57..d2a0d0e 100644
--- a/include/SDL_hints.h
+++ b/include/SDL_hints.h
@@ -392,13 +392,14 @@ extern "C" {
#define SDL_HINT_ENABLE_STEAM_CONTROLLERS "SDL_ENABLE_STEAM_CONTROLLERS"
/**
- * \brief A variable controlling whether SDL logs all events pushed onto its internal queue.
+ * \brief A variable controlling verbosity of the logging of SDL events pushed onto the internal queue.
*
- * This variable can be set to the following values:
+ * This variable can be set to the following values, from least to most verbose:
*
* "0" - Don't log any events (default)
- * "1" - Log all events except mouse and finger motion, which are pretty spammy.
- * "2" - Log all events.
+ * "1" - Log most events (other than the really spammy ones).
+ * "2" - Include mouse and finger motion events.
+ * "3" - Include SDL_SysWMEvent events.
*
* This is generally meant to be used to debug SDL itself, but can be useful
* for application developers that need better visibility into what is going
diff --git a/src/events/SDL_events.c b/src/events/SDL_events.c
index caa8b87..962120d 100644
--- a/src/events/SDL_events.c
+++ b/src/events/SDL_events.c
@@ -150,13 +150,19 @@ SDL_PollSentinelChanged(void *userdata, const char *name, const char *oldValue,
SDL_EventState(SDL_POLLSENTINEL, SDL_GetStringBoolean(hint, SDL_TRUE) ? SDL_ENABLE : SDL_DISABLE);
}
-/* 0 (default) means no logging, 1 means logging, 2 means logging with mouse and finger motion */
-static int SDL_DoEventLogging = 0;
+/**
+ * Verbosity of logged events as defined in SDL_HINT_EVENT_LOGGING:
+ * - 0: (default) no logging
+ * - 1: logging of most events
+ * - 2: as above, plus mouse and finger motion
+ * - 3: as above, plus SDL_SysWMEvents
+ */
+static int SDL_EventLoggingVerbosity = 0;
static void SDLCALL
SDL_EventLoggingChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
{
- SDL_DoEventLogging = (hint && *hint) ? SDL_clamp(SDL_atoi(hint), 0, 2) : 0;
+ SDL_EventLoggingVerbosity = (hint && *hint) ? SDL_clamp(SDL_atoi(hint), 0, 3) : 0;
}
static void
@@ -166,7 +172,7 @@ SDL_LogEvent(const SDL_Event *event)
char details[128];
/* sensor/mouse/finger motion are spammy, ignore these if they aren't demanded. */
- if ( (SDL_DoEventLogging < 2) &&
+ if ( (SDL_EventLoggingVerbosity < 2) &&
( (event->type == SDL_MOUSEMOTION) ||
(event->type == SDL_FINGERMOTION) ||
(event->type == SDL_CONTROLLERTOUCHPADMOTION) ||
@@ -175,6 +181,11 @@ SDL_LogEvent(const SDL_Event *event)
return;
}
+ /* window manager events are even more spammy, and don't provide much useful info. */
+ if ((SDL_EventLoggingVerbosity < 3) && (event->type == SDL_SYSWMEVENT)) {
+ return;
+ }
+
/* this is to make SDL_snprintf() calls cleaner. */
#define uint unsigned int
@@ -590,7 +601,7 @@ SDL_AddEvent(SDL_Event * event)
SDL_EventQ.free = entry->next;
}
- if (SDL_DoEventLogging) {
+ if (SDL_EventLoggingVerbosity > 0) {
SDL_LogEvent(event);
}