Allow a callback function to be set to define how the behavior of the system window exit button behaves
- Dominant language
- C++
- Stars
- 6.3k
- Forks
- 455
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 130
Description
**Is your feature request related to a problem? Please describe (REQUIRED):**
Currently the engine immediately closes when the X button on desktop OS platforms is pressed. In some applications/games you want to instead show a dialog to the user to confirm they want to close.
Implementing this probably requires modifying code related to GLFW. GLFW has a function glfwSetWindowCloseCallback.
https://www.glfw.org/docs/3.2/group__window.html#gaade9264e79fae52bdb78e2df11ee8d6a
```
local function close_callback()
.. -- really close?
end
sys.set_windows_close_callback(close_callback)
```
or
```
window.set_close_callback(close_callback)
```
or
Add the close callback as an event for window.set_listener()
```
window.WINDOW_EVENT_CLOSE_CALLBACK
```
And if the window.set_listener() callback is defined then do not do current behavior but let the user define the behavior in the window listener callback. Obviously this would be a change that devs would need to change code to work around if they are expecting X to close always previously.
**Describe the solution you'd like (REQUIRED):**
Add an ability to define a callback function for closing. If the callback is not defined then do behavior as is, otherwise let the callback function decide what to do.
**Describe alternatives you've considered (REQUIRED):**
We have looked into this functionality in DefOS and it would be better to be part of the core engine.
Contributor guide
Research direction
Start by tracing the engine's GLFW window-close handling and compare it with glfwSetWindowCloseCallback, which the issue identifies as the relevant entry point. Resolve the public Lua API shape and verify that an unset callback preserves current closing behavior while a defined callback controls the result.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, lua
- Domain
- desktop, game-dev
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100