SDL: Add new verbosity level for logging of `SDL_SysWMEvent`s

From 6150245d65cf5910015ba804934999fbb4b3d6a6 Mon Sep 17 00:00:00 2001
From: Susko3 <[EMAIL REDACTED]>
Date: Tue, 3 May 2022 00:11:44 +0200
Subject: [PATCH] Add new verbosity level for logging of `SDL_SysWMEvent`s

Now logged only if SDL_HINT_EVENT_LOGGING is set to "3" or above.
---
 include/SDL_hints.h     |  9 +++++----
 src/events/SDL_events.c | 21 ++++++++++++++++-----
 2 files changed, 21 insertions(+), 9 deletions(-)

diff --git a/include/SDL_hints.h b/include/SDL_hints.h
index 03bbb57bad0..d2a0d0e19e0 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 caa8b87ebd5..962120dbf72 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);
     }