Window Decorations and Borders

Borderless and SDL_GetWindowBordersSize()

How does SDL_GetWindowBordersSize() behave on borderless windows?

Abstract art representing computer programming

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.

This Question is from the Lesson:

Window Decorations and Borders

An introduction to managing SDL2 window decorations, borders, and client areas.

Answers to questions are automatically generated and may not have been reviewed.

This Question is from the Lesson:

Window Decorations and Borders

An introduction to managing SDL2 window decorations, borders, and client areas.

sdl2-promo.jpg
Part of the course:

Game Dev with SDL2

Learn C++ and SDL development by creating hands on, practical projects inspired by classic retro games

Free, unlimited access

This course includes:

  • 67 Lessons
  • 100+ Code Samples
  • 91% Positive Reviews
  • Regularly Updated
  • Help and FAQ
Free, Unlimited Access

Professional C++

Comprehensive course covering advanced concepts, and how to use them on large-scale projects.

Screenshot from Warhammer: Total War
Screenshot from Tomb Raider
Screenshot from Jedi: Fallen Order
Contact|Privacy Policy|Terms of Use
Copyright © 2024 - All Rights Reserved