From 09d77e1ba2890f8e1c4b3434b422dee5aec37b45 Mon Sep 17 00:00:00 2001 From: fallenoak Date: Mon, 2 Jan 2023 15:37:41 -0600 Subject: [PATCH] feat(event): handle close event --- src/event/Event.cpp | 4 ++++ src/event/Event.hpp | 2 ++ src/event/Input.cpp | 10 +++++++++- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/event/Event.cpp b/src/event/Event.cpp index e27d367..7255315 100644 --- a/src/event/Event.cpp +++ b/src/event/Event.cpp @@ -46,6 +46,10 @@ void EventInitialize(int32_t threadCount, int32_t netServer) { // OsInputSetEventPollProc(&sub_47DCA0); } +void EventInitiateShutdown() { + IEvtSchedulerShutdown(); +} + int32_t EventIsControlKeyDown() { return EventIsKeyDown(KEY_LCONTROL) || EventIsKeyDown(KEY_RCONTROL); } diff --git a/src/event/Event.hpp b/src/event/Event.hpp index 22cc108..031ee1e 100644 --- a/src/event/Event.hpp +++ b/src/event/Event.hpp @@ -39,6 +39,8 @@ void EventDoMessageLoop(); void EventInitialize(int32_t threadCount, int32_t netServer); +void EventInitiateShutdown(); + int32_t EventIsControlKeyDown(); int32_t EventIsKeyDown(KEY key); diff --git a/src/event/Input.cpp b/src/event/Input.cpp index e3f3fef..be6704c 100644 --- a/src/event/Input.cpp +++ b/src/event/Input.cpp @@ -1,4 +1,5 @@ #include "event/Input.hpp" +#include "event/Event.hpp" #include "event/EvtContext.hpp" #include "event/Queue.hpp" #include "gx/Window.hpp" @@ -65,6 +66,10 @@ void PostChar(EvtContext* context, int32_t ch, int32_t repeat) { IEvtQueueDispatch(context, EVENT_ID_CHAR, &data); } +void PostClose() { + EventInitiateShutdown(); +} + void PostKeyDown(EvtContext* context, int32_t key, int32_t repeat, int32_t time) { if (key <= KEY_LASTMETAKEY) { if ((1 << key) & Input::s_metaKeyState) { @@ -202,7 +207,10 @@ void ProcessInput(const int32_t param[], OSINPUT id, int32_t* shutdown, EvtConte break; case OS_INPUT_CLOSE: - // TODO + // TODO ConfirmClose() + PostClose(); + *shutdown = 1; + break; case OS_INPUT_FOCUS: