Borderless and SDL_GetWindowBordersSize()
How does SDL_GetWindowBordersSize()
behave on borderless windows?
The SDL_GetWindowBordersSize()
function returns the size of a window's decorations.
However, when called on a borderless window, the function typically sets all decoration size values (top, left, bottom, right) to 0
. This is because a borderless window has no decorations to measure.
Here's an example demonstrating this:
#include <SDL.h>
#include <iostream>
int main() {
SDL_Init(SDL_INIT_VIDEO);
SDL_Window* Borderless{SDL_CreateWindow(
"Borderless",
100, 100, 300, 200,
SDL_WINDOW_BORDERLESS
)};
int Top, Left, Bottom, Right;
if (SDL_GetWindowBordersSize(
Borderless, &Top, &Left, &Bottom, &Right
) == 0) {
std::cout << "Top: " << Top
<< ", Left: " << Left
<< ", Bottom: " << Bottom
<< ", Right: " << Right << "\n";
} else {
std::cout << "Error: "
<< SDL_GetError() << "\n";
}
SDL_DestroyWindow(Borderless);
SDL_Quit();
}
Top: 0, Left: 0, Bottom: 0, Right: 0
This behavior is consistent across platforms where SDL abstracts the windowing system. Note that using SDL_GetWindowBordersSize()
on a borderless window will never result in an error unless the window pointer itself is invalid.
Window Decorations and Borders
An introduction to managing SDL2 window decorations, borders, and client areas.