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.

Questions & Answers

Answers are generated by AI models and may not have been reviewed. Be mindful when running any code on your device.

Why use a borderless window?
Why would you want a borderless window in an application?
Can SDL customize border colors?
Can I change the color of the border or title bar in SDL2?
Uses of window decoration sizes
What are some practical uses for knowing the size of window decorations?
Resizable borderless windows in SDL2
Can I create a borderless window that still has a resizable frame?
Decorations in fullscreen modes
How do window decorations affect fullscreen modes?
Can I remove only the title bar?
Can I remove only the title bar but keep the borders?
Customizing window decorations
How can I customize window decorations in SDL2?
Or Ask your Own Question
Purchase the course to ask your own questions