Enumerate the properties contained in a group of properties.
Defined in <SDL3/SDL_properties.h>
bool SDL_EnumerateProperties(SDL_PropertiesID props, SDL_EnumeratePropertiesCallback callback, void *userdata);
SDL_PropertiesID | props | the properties to query. |
SDL_EnumeratePropertiesCallback | callback | the function to call for each property. |
void * | userdata | a pointer that is passed to callback . |
(bool) Returns true on success or false on failure; call SDL_GetError() for more information.
The callback function is called for each property in the group of properties. The properties are locked during enumeration.
It is safe to call this function from any thread.
This function is available since SDL 3.1.3.
// Example program
// Use SDL3 to enumerate the display properties of every display
#include <SDL3/SDL_log.h>
#include <SDL3/SDL_main.h>
#include <SDL3/SDL_video.h>
static void
void *userdata, SDL_PropertiesID props, const char *name)
my_enumerate_properties_callback(
{
SDL_PropertyType prop_type = SDL_GetPropertyType(props, name);
switch (prop_type) {
case SDL_PROPERTY_TYPE_POINTER:
"%s is a pointer poperty", name);
SDL_Log(break;
case SDL_PROPERTY_TYPE_STRING:
SDL_Log("%s is a string property with value %s", name, SDL_GetStringProperty(props, name, ""));
break;
case SDL_PROPERTY_TYPE_NUMBER:
"%s is a number property with value %"SDL_PRIs64, name, SDL_GetNumberProperty(props, name, 0));
SDL_Log(break;
case SDL_PROPERTY_TYPE_FLOAT:
"%s is a float property with value %f", name, SDL_GetFloatProperty(props, name, 0.0f));
SDL_Log(break;
case SDL_PROPERTY_TYPE_BOOLEAN:
SDL_Log("%s is a boolean property with value %d", name, SDL_GetBooleanProperty(props, name, false));
break;
case SDL_PROPERTY_TYPE_INVALID:
default:
"%s is an invalid property", name);
SDL_Log(break;
}
}
int
int argc, char** argv)
main(
{if (!SDL_Init(SDL_INIT_VIDEO)) {
"Unable to initialize SDL: %s", SDL_GetError());
SDL_Log(return 0;
}
"SDL initialized");
SDL_Log(
int num_displays;
SDL_DisplayID *displays = SDL_GetDisplays(&num_displays);"Found %d displays.", num_displays);
SDL_Log(
for(int i = 0; i < num_displays; i++) {
SDL_PropertiesID prop_id = SDL_GetDisplayProperties(displays[i]);"Display %d has properties ID %d", i, prop_id);
SDL_Log(
if(!SDL_EnumerateProperties(prop_id, my_enumerate_properties_callback, NULL)) {
"Error enumerating properties: %s.", SDL_GetError());
SDL_Log(
}
}
SDL_free(displays);
return 0;
}