mirror of
https://github.com/elasota/Aerofoil.git
synced 2025-09-23 06:53:43 +00:00
Handle Quit event more gracefully
This commit is contained in:
@@ -379,6 +379,12 @@ static void TranslateWindowsMessage(const MSG *msg, IGpVOSEventQueue *eventQueue
|
||||
PostKeyboardEvent(eventQueue, keyEventType, subset, key, (lParam & 0xffff));
|
||||
}
|
||||
break;
|
||||
case WM_QUIT:
|
||||
{
|
||||
if (GpVOSEvent *evt = eventQueue->QueueEvent())
|
||||
evt->m_eventType = GpVOSEventTypes::kQuit;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@@ -7,6 +7,7 @@
|
||||
|
||||
|
||||
#include "PLAppleEvents.h"
|
||||
#include "AppEventHandler.h"
|
||||
#include "DialogManager.h"
|
||||
#include "Externs.h"
|
||||
#include "House.h"
|
||||
@@ -168,12 +169,38 @@ PLError_t MyGotRequiredParams (const AppleEvent *theAE)
|
||||
PLErrors::kInvalidParameter;
|
||||
}
|
||||
|
||||
class SystemEventHandlerImpl : public PortabilityLayer::IAppEventHandler
|
||||
{
|
||||
public:
|
||||
void OnQuit() override;
|
||||
|
||||
static SystemEventHandlerImpl *GetInstance();
|
||||
|
||||
private:
|
||||
static SystemEventHandlerImpl ms_instance;
|
||||
};
|
||||
|
||||
void SystemEventHandlerImpl::OnQuit()
|
||||
{
|
||||
quitting = true;
|
||||
}
|
||||
|
||||
|
||||
SystemEventHandlerImpl *SystemEventHandlerImpl::GetInstance()
|
||||
{
|
||||
return &ms_instance;
|
||||
}
|
||||
|
||||
SystemEventHandlerImpl SystemEventHandlerImpl::ms_instance;
|
||||
|
||||
//-------------------------------------------------------------- SetUpAppleEvents
|
||||
// Initializes all handlers, etc. for dealing with Apple Events.
|
||||
|
||||
void SetUpAppleEvents (void)
|
||||
{
|
||||
PLError_t theErr;
|
||||
|
||||
PortabilityLayer::AppEventHandler::SetInstance(SystemEventHandlerImpl::GetInstance());
|
||||
|
||||
openAppAEUPP = NewAEEventHandlerProc(DoOpenAppAE);
|
||||
openDocAEUPP = NewAEEventHandlerProc(DoOpenDocAE);
|
||||
|
@@ -251,6 +251,7 @@ namespace GpVOSEventTypes
|
||||
kMouseInput,
|
||||
kGamepadInput,
|
||||
kVideoResolutionChanged,
|
||||
kQuit
|
||||
};
|
||||
}
|
||||
|
||||
|
@@ -56,6 +56,7 @@ LRESULT CALLBACK WinProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
switch (message)
|
||||
{
|
||||
case WM_DESTROY:
|
||||
case WM_CLOSE:
|
||||
{
|
||||
PostQuitMessage(0);
|
||||
return 0;
|
||||
@@ -756,9 +757,6 @@ void GpDisplayDriverD3D11::Run()
|
||||
{
|
||||
DispatchMessage(&msg);
|
||||
|
||||
if (msg.message == WM_QUIT)
|
||||
break;
|
||||
else
|
||||
{
|
||||
if (msg.message == WM_MOUSEMOVE)
|
||||
{
|
||||
|
16
PortabilityLayer/AppEventHandler.cpp
Normal file
16
PortabilityLayer/AppEventHandler.cpp
Normal file
@@ -0,0 +1,16 @@
|
||||
#include "AppEventHandler.h"
|
||||
|
||||
namespace PortabilityLayer
|
||||
{
|
||||
IAppEventHandler *AppEventHandler::ms_instance;
|
||||
|
||||
IAppEventHandler *AppEventHandler::GetInstance()
|
||||
{
|
||||
return ms_instance;
|
||||
}
|
||||
|
||||
void AppEventHandler::SetInstance(IAppEventHandler *instance)
|
||||
{
|
||||
ms_instance = instance;
|
||||
}
|
||||
}
|
19
PortabilityLayer/AppEventHandler.h
Normal file
19
PortabilityLayer/AppEventHandler.h
Normal file
@@ -0,0 +1,19 @@
|
||||
#pragma once
|
||||
|
||||
namespace PortabilityLayer
|
||||
{
|
||||
struct IAppEventHandler
|
||||
{
|
||||
virtual void OnQuit() = 0;
|
||||
};
|
||||
|
||||
class AppEventHandler
|
||||
{
|
||||
public:
|
||||
static IAppEventHandler *GetInstance();
|
||||
static void SetInstance(IAppEventHandler *instance);
|
||||
|
||||
private:
|
||||
static IAppEventHandler *ms_instance;
|
||||
};
|
||||
}
|
@@ -1,4 +1,5 @@
|
||||
#include "PLCore.h"
|
||||
#include "AppEventHandler.h"
|
||||
#include "PLEventQueue.h"
|
||||
#include "PLKeyEncoding.h"
|
||||
#include "PLMovies.h"
|
||||
@@ -135,6 +136,14 @@ static void TranslateVOSEvent(const GpVOSEvent *vosEvent, uint32_t timestamp, Po
|
||||
case GpVOSEventTypes::kVideoResolutionChanged:
|
||||
TranslateVideoResolutionChangedEvent(vosEvent->m_event.m_resolutionChangedEvent);
|
||||
break;
|
||||
case GpVOSEventTypes::kQuit:
|
||||
if (TimeTaggedVOSEvent *evt = queue->Enqueue())
|
||||
*evt = TimeTaggedVOSEvent::Create(*vosEvent, timestamp);
|
||||
|
||||
if (PortabilityLayer::IAppEventHandler *appHandler = PortabilityLayer::AppEventHandler::GetInstance())
|
||||
appHandler->OnQuit();
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -146,6 +146,7 @@
|
||||
<ClInclude Include="AEHandlerDesc.h" />
|
||||
<ClInclude Include="AEManager.h" />
|
||||
<ClInclude Include="AntiAliasTable.h" />
|
||||
<ClInclude Include="AppEventHandler.h" />
|
||||
<ClInclude Include="ArrayTools.h" />
|
||||
<ClInclude Include="BinarySearch.h" />
|
||||
<ClInclude Include="BinHex4.h" />
|
||||
@@ -303,6 +304,7 @@
|
||||
<ClCompile Include="..\stb\stb_image_write.c" />
|
||||
<ClCompile Include="AEManager.cpp" />
|
||||
<ClCompile Include="AntiAliasTable.cpp" />
|
||||
<ClCompile Include="AppEventHandler.cpp" />
|
||||
<ClCompile Include="BinHex4.cpp" />
|
||||
<ClCompile Include="BitmapImage.cpp" />
|
||||
<ClCompile Include="ByteSwap.cpp" />
|
||||
|
@@ -483,6 +483,9 @@
|
||||
<ClInclude Include="ArrayTools.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="AppEventHandler.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="CFileStream.cpp">
|
||||
@@ -758,5 +761,8 @@
|
||||
<ClCompile Include="TextPlacer.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="AppEventHandler.cpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
Reference in New Issue
Block a user