mirror of
				https://github.com/libsdl-org/SDL.git
				synced 2025-11-04 01:34:38 +00:00 
			
		
		
		
	Add new verbosity level for logging of SDL_SysWMEvents
				
					
				
			Now logged only if SDL_HINT_EVENT_LOGGING is set to "3" or above.
This commit is contained in:
		@@ -392,13 +392,14 @@ extern "C" {
 | 
				
			|||||||
#define SDL_HINT_ENABLE_STEAM_CONTROLLERS "SDL_ENABLE_STEAM_CONTROLLERS"
 | 
					#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)
 | 
					 *    "0"     - Don't log any events (default)
 | 
				
			||||||
 *    "1"     - Log all events except mouse and finger motion, which are pretty spammy.
 | 
					 *    "1"     - Log most events (other than the really spammy ones).
 | 
				
			||||||
 *    "2"     - Log all events.
 | 
					 *    "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
 | 
					 *  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
 | 
					 *  for application developers that need better visibility into what is going
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -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);
 | 
					    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
 | 
					static void SDLCALL
 | 
				
			||||||
SDL_EventLoggingChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
 | 
					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
 | 
					static void
 | 
				
			||||||
@@ -166,7 +172,7 @@ SDL_LogEvent(const SDL_Event *event)
 | 
				
			|||||||
    char details[128];
 | 
					    char details[128];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* sensor/mouse/finger motion are spammy, ignore these if they aren't demanded. */
 | 
					    /* 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_MOUSEMOTION) ||
 | 
				
			||||||
              (event->type == SDL_FINGERMOTION) ||
 | 
					              (event->type == SDL_FINGERMOTION) ||
 | 
				
			||||||
              (event->type == SDL_CONTROLLERTOUCHPADMOTION) ||
 | 
					              (event->type == SDL_CONTROLLERTOUCHPADMOTION) ||
 | 
				
			||||||
@@ -175,6 +181,11 @@ SDL_LogEvent(const SDL_Event *event)
 | 
				
			|||||||
        return;
 | 
					        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. */
 | 
					    /* this is to make SDL_snprintf() calls cleaner. */
 | 
				
			||||||
    #define uint unsigned int
 | 
					    #define uint unsigned int
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -590,7 +601,7 @@ SDL_AddEvent(SDL_Event * event)
 | 
				
			|||||||
        SDL_EventQ.free = entry->next;
 | 
					        SDL_EventQ.free = entry->next;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (SDL_DoEventLogging) {
 | 
					    if (SDL_EventLoggingVerbosity > 0) {
 | 
				
			||||||
        SDL_LogEvent(event);
 | 
					        SDL_LogEvent(event);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user