Unfortunately, SDL2 does not natively support creating a borderless window with a resizable frame.
The SDL_WINDOW_BORDERLESS
flag removes all decorations, including resize handles. The SDL_WINDOW_RESIZABLE
flag, which allows resizing, only applies to windows with decorations.
If you need a resizable borderless window, you must implement the resizing functionality yourself by handling window resizing events (SDL_WINDOWEVENT_RESIZED
) and manually adjusting the window size. You can also combine this with custom rendering to simulate resize handles.
Example of handling resize events:
#include <SDL.h>
#include <iostream>
int main() {
SDL_Init(SDL_INIT_VIDEO);
SDL_Window* Window{SDL_CreateWindow(
"Resizable Borderless",
SDL_WINDOWPOS_CENTERED,
SDL_WINDOWPOS_CENTERED,
800, 600,
SDL_WINDOW_BORDERLESS
)};
SDL_Event Event;
bool Running{true};
while (Running) {
while (SDL_PollEvent(&Event)) {
if (Event.type == SDL_QUIT) {
Running = false;
} else if (
Event.type == SDL_WINDOWEVENT &&
Event.window.event == SDL_WINDOWEVENT_RESIZED
) {
int NewWidth = Event.window.data1;
int NewHeight = Event.window.data2;
std::cout << "Window resized to: "
<< NewWidth << "x" << NewHeight << "\n";
}
}
}
SDL_DestroyWindow(Window);
SDL_Quit();
}
Window resized to: 1024x768
If resizing is critical, consider using platform-specific APIs to add custom resize handles. Another option is to use higher-level libraries like Dear ImGui that support customizable windowing.
Answers to questions are automatically generated and may not have been reviewed.
An introduction to managing SDL2 window decorations, borders, and client areas.