Cannot remove the Window title bar and borders

Hello,

I’m using SDL 2.0.9 on Windows 10 64bits, and I try to create a window with no borders and title bar using the SDL_SetWindowBordered function. At first, it seems to work. But if I change the input focus, by clicking on the taskbar for example, a thick grey border and a blue title bar shows up in the window.

I tried to repaint the background on every frame, and it kinda works, but then the window starts to flicker between the title bar and the background color. I also tried to disable Win32 styles and ex styles manually from the Win32 handle, but it does nothing about that.

Here’s the minimal required code to reproduce it :

#define SDL_MAIN_HANDLED
#include <SDL2/SDL.h>
int main()
{
SDL_Init( SDL_INIT_VIDEO | SDL_INIT_EVENTS );

auto sdl2_window = SDL_CreateWindow(
“Window”,
SDL_WINDOWPOS_CENTERED,
SDL_WINDOWPOS_CENTERED,
800,
600,
SDL_WINDOW_RESIZABLE
);

SDL_SetWindowBordered( sdl2_window, SDL_FALSE );

bool run{ true };
while ( run )
{
SDL_Event event{};
SDL_PollEvent( &event );
if ( event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_CLOSE )
run = false;
}

SDL_DestroyWindow( sdl2_window );

return 0;
}

And a picture of the result :

Thanks!

Your code doesnt show how and when you call SDL_RenderPresent(). The flickering can happen when you call this function repeatedly without recreating the backbuffer each time.
https://discourse.libsdl.org/t/schizophrenic-renderer-when-in-fullscreen-mode/25590/11

Thanks for the suggestion, but unfortunately I described my issue poorly by using the word flicker. That’s not really what is happening, and after more research, I understand the problem more accurately.

Using this code on Window 10 with SDL 2.0.9 :

#define SDL_MAIN_HANDLED
#include <SDL2/SDL.h>
#include

int main()
{
SDL_Init( SDL_INIT_VIDEO | SDL_INIT_EVENTS );

auto sdl2_window = SDL_CreateWindow(
“Window”,
SDL_WINDOWPOS_CENTERED,
SDL_WINDOWPOS_CENTERED,
800,
600,
SDL_WINDOW_RESIZABLE
);

SDL_SetWindowBordered( sdl2_window, SDL_FALSE );

auto renderer = SDL_CreateRenderer( sdl2_window, -1, SDL_RENDERER_ACCELERATED );

bool run{ true };
while ( run )
{
SDL_Event event{};
SDL_PollEvent( &event );
if ( event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_CLOSE )
run = false;

  std::this_thread::sleep_for( std::chrono::seconds( 1 ) );

  SDL_RenderClear( renderer );
  SDL_RenderPresent( renderer );

}

SDL_DestroyWindow( sdl2_window );

return 0;
}

At first we get a black window with no border or title bar at all. That’s good, that’s the expected behavior given that we’re calling SDL_SetWindowBordered with SDL_FALSE. If we click outside of this window, it loses the input focus, that’s still the expected behavior. But now if we click inside the window, giving it back the input focus, the borders and title bar appears. This is not supposed to happen. In my sample code, I added a one second sleep in the event loop to highlight this issue, as it is hard to see at full speed because the background is being redrawn just after, overwriting the frame and making it hard to see.

From what I understand, this frame is not drawn by the system. It looks like it is the SDL who draws it when the window gains input focus, and I have found no solution to stop this from happening.

I submitted a bug report about this :
https://bugzilla.libsdl.org/show_bug.cgi?id=4466