sdlxGetDisplays function video

List<int> sdlxGetDisplays()

Get a list of currently connected displays.

\param count a pointer filled in with the number of displays returned, may be NULL. \returns a 0 terminated array of display instance IDs or NULL on failure; call SDL_GetError() for more information. This should be freed with SDL_free() when it is no longer needed.

\threadsafety This function should only be called on the main thread.

\since This function is available since SDL 3.2.0.

extern SDL_DECLSPEC SDL_DisplayID * SDLCALL SDL_GetDisplays(int *count)

Implementation

List<int> sdlxGetDisplays() {
  final result = <int>[];
  final countPointer = calloc<Int32>();
  final displaysPointer = sdlGetDisplays(countPointer);
  if (displaysPointer != nullptr) {
    for (var i = 0; i < countPointer.value; i++) {
      result.add(displaysPointer[i]);
    }
    sdlFree(displaysPointer.cast<Void>());
  }
  countPointer.callocFree();
  return result;
}