What do you mean by “unresponsive”? If you mean unresponsive to SDL events that you intend to handle yourself, then it would probably be helpful to see the code where you’re handling the events.
It is definitely not necessary to run an event loop for each window in a separate thread. E.g., here’s a single-threaded program that creates two windows, and shrinks whichever one you click on:
#include <stdio.h>
#include <stdbool.h>
#include "SDL.h"
#define DEFAULT_WINDOW_FLAGS SDL_WINDOW_ALLOW_HIGHDPI | SDL_WINDOW_RESIZABLE | SDL_WINDOW_OPENGL
#define DEFAULT_RENDER_FLAGS SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC
void init_SDL()
{
if (SDL_Init(SDL_INIT_VIDEO) != 0) {
fprintf(stderr, "\nError initializing SDL: %s\n", SDL_GetError());
exit(1);
}
}
int main()
{
init_SDL();
SDL_Window *winA = SDL_CreateWindow("Window A", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 800, 400, (Uint32)DEFAULT_WINDOW_FLAGS);
SDL_Window *winB = SDL_CreateWindow("Window B", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 700, 500, (Uint32)DEFAULT_WINDOW_FLAGS);
SDL_Renderer *rendA = SDL_CreateRenderer(winA, -1, (Uint32)DEFAULT_RENDER_FLAGS);
SDL_Renderer *rendB = SDL_CreateRenderer(winB, -1, (Uint32)DEFAULT_RENDER_FLAGS);
bool quit = false;
while (!quit) {
SDL_Event e;
while (SDL_PollEvent(&e)) {
if (e.type == SDL_QUIT || (e.type == SDL_WINDOWEVENT && e.window.event == SDL_WINDOWEVENT_CLOSE)) {
quit = true;
} else if (e.type == SDL_MOUSEBUTTONDOWN) {
int w, h;
if (e.button.windowID == SDL_GetWindowID(winA)) {
SDL_GetWindowSize(winA, &w, &h);
SDL_SetWindowSize(winA, w - 10, h - 10);
fprintf(stdout, "Handle mouse click for Window A\n");
} else if (e.button.windowID == SDL_GetWindowID(winB)) {
SDL_GetWindowSize(winB, &w, &h);
SDL_SetWindowSize(winB, w - 10, h - 10);
fprintf(stdout, "Handle mouse click for Window B\n");
}
}
}
SDL_SetRenderDrawColor(rendA, 0, 0, 0, 0);
SDL_SetRenderDrawColor(rendB, 0, 0, 0, 0);
SDL_RenderClear(rendA);
SDL_RenderClear(rendB);
SDL_RenderPresent(rendA);
SDL_RenderPresent(rendB);
SDL_Delay(1);
}
}