Resizable borderless windows in SDL2

Can I create a borderless window that still has a resizable frame?

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.

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?
Borderless and SDL_GetWindowBordersSize()
How does SDL_GetWindowBordersSize() behave on borderless windows?
Uses of window decoration sizes
What are some practical uses for knowing the size of window decorations?
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
Get an immediate answer to your specific question using our AI assistant