# Handling "Are you sure you want to quit"

**URL:** <https://discourse.libsdl.org/t/handling-are-you-sure-you-want-to-quit/58880>\
**Category:** Game Development\
**Created:** [March 30, 2025, 9:42am UTC](https://discourse.libsdl.org/t/handling-are-you-sure-you-want-to-quit/58880 "2025-03-30T09:42:54Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![zhulikkulik](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/z/ce7236/32.png) [@zhulikkulik](https://discourse.libsdl.org/u/zhulikkulik)\
**Post date:** [March 30, 2025, 9:42am UTC](https://discourse.libsdl.org/t/handling-are-you-sure-you-want-to-quit/58880/1 "2025-03-30T09:42:54Z")

</div>

I guess it’s a noob question, but what’s the proper way of handling such type of interaction if player presses “close window” button or Alt+F4?

The way I understand it - by the time I get to react to “(event.type == SDL\_EVENT\_WINDOW\_CLOSE\_REQUESTED)” SDL already posts a whole bunch of other messages to the queue and begins to destroy window. Am I supposed to just flush “window destroy(ed)” events and SDL\_EVENT\_QUIT? Because that sounds hacky and broken.  
Or should I set event filter in this case?

---

<div class="post-metadata">

**Author:** ![Peter87](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/p/f07891/32.png) [@Peter87](https://discourse.libsdl.org/u/Peter87)\
**Post date:** [March 30, 2025, 12:56pm UTC](https://discourse.libsdl.org/t/handling-are-you-sure-you-want-to-quit/58880/2 "2025-03-30T12:56:16Z")

</div>

If you want to prevent getting a `SDL_EVENT_QUIT` event when the user tries to close last window you can set the hint [`SDL_HINT_QUIT_ON_LAST_WINDOW_CLOSE`](https://wiki.libsdl.org/SDL3/SDL_HINT_QUIT_ON_LAST_WINDOW_CLOSE) to zero.

```c
SDL_SetHint(SDL_HINT_QUIT_ON_LAST_WINDOW_CLOSE, "0");

```

---

<div class="post-metadata">

**Author:** ![DrNoob](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/drnoob/32/5587_2.png) [@DrNoob](https://discourse.libsdl.org/u/DrNoob)\
**Post date:** [March 30, 2025, 1:00pm UTC](https://discourse.libsdl.org/t/handling-are-you-sure-you-want-to-quit/58880/3 "2025-03-30T13:00:46Z")

</div>

On the window close button, Alt+F4 (Windows) or CMD+Q (macOS), you just get an `SDL_EVENT_QUIT` event and can decide what to do with that. For example, in my game I automatically pause the game and open the quit menu (inside my main menu) when receiving this event. SDL has not yet destroyed the window at this point.

---

<div class="post-metadata">

**Author:** ![zhulikkulik](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/z/ce7236/32.png) [@zhulikkulik](https://discourse.libsdl.org/u/zhulikkulik)\
**Post date:** [March 30, 2025, 5:10pm UTC](https://discourse.libsdl.org/t/handling-are-you-sure-you-want-to-quit/58880/4 "2025-03-30T17:10:17Z")

</div>

Hm… I actually get `SDL_EVENT_WINDOW_CLOSE_REQUESTED` first and `SDL_EVENT_QUIT` comes next. But it seems like if I just ignore it and keep running the loop - nothing happens. The “animation” continues and the window responds.

Thanks!
