mirror of
https://github.com/elasota/Aerofoil.git
synced 2025-12-14 03:59:36 +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));
|
PostKeyboardEvent(eventQueue, keyEventType, subset, key, (lParam & 0xffff));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case WM_QUIT:
|
||||||
|
{
|
||||||
|
if (GpVOSEvent *evt = eventQueue->QueueEvent())
|
||||||
|
evt->m_eventType = GpVOSEventTypes::kQuit;
|
||||||
|
}
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
|
|
||||||
#include "PLAppleEvents.h"
|
#include "PLAppleEvents.h"
|
||||||
|
#include "AppEventHandler.h"
|
||||||
#include "DialogManager.h"
|
#include "DialogManager.h"
|
||||||
#include "Externs.h"
|
#include "Externs.h"
|
||||||
#include "House.h"
|
#include "House.h"
|
||||||
@@ -168,6 +169,30 @@ PLError_t MyGotRequiredParams (const AppleEvent *theAE)
|
|||||||
PLErrors::kInvalidParameter;
|
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
|
//-------------------------------------------------------------- SetUpAppleEvents
|
||||||
// Initializes all handlers, etc. for dealing with Apple Events.
|
// Initializes all handlers, etc. for dealing with Apple Events.
|
||||||
|
|
||||||
@@ -175,6 +200,8 @@ void SetUpAppleEvents (void)
|
|||||||
{
|
{
|
||||||
PLError_t theErr;
|
PLError_t theErr;
|
||||||
|
|
||||||
|
PortabilityLayer::AppEventHandler::SetInstance(SystemEventHandlerImpl::GetInstance());
|
||||||
|
|
||||||
openAppAEUPP = NewAEEventHandlerProc(DoOpenAppAE);
|
openAppAEUPP = NewAEEventHandlerProc(DoOpenAppAE);
|
||||||
openDocAEUPP = NewAEEventHandlerProc(DoOpenDocAE);
|
openDocAEUPP = NewAEEventHandlerProc(DoOpenDocAE);
|
||||||
printDocAEUPP = NewAEEventHandlerProc(DoPrintDocAE);
|
printDocAEUPP = NewAEEventHandlerProc(DoPrintDocAE);
|
||||||
|
|||||||
@@ -251,6 +251,7 @@ namespace GpVOSEventTypes
|
|||||||
kMouseInput,
|
kMouseInput,
|
||||||
kGamepadInput,
|
kGamepadInput,
|
||||||
kVideoResolutionChanged,
|
kVideoResolutionChanged,
|
||||||
|
kQuit
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -56,6 +56,7 @@ LRESULT CALLBACK WinProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|||||||
switch (message)
|
switch (message)
|
||||||
{
|
{
|
||||||
case WM_DESTROY:
|
case WM_DESTROY:
|
||||||
|
case WM_CLOSE:
|
||||||
{
|
{
|
||||||
PostQuitMessage(0);
|
PostQuitMessage(0);
|
||||||
return 0;
|
return 0;
|
||||||
@@ -756,9 +757,6 @@ void GpDisplayDriverD3D11::Run()
|
|||||||
{
|
{
|
||||||
DispatchMessage(&msg);
|
DispatchMessage(&msg);
|
||||||
|
|
||||||
if (msg.message == WM_QUIT)
|
|
||||||
break;
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
if (msg.message == WM_MOUSEMOVE)
|
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 "PLCore.h"
|
||||||
|
#include "AppEventHandler.h"
|
||||||
#include "PLEventQueue.h"
|
#include "PLEventQueue.h"
|
||||||
#include "PLKeyEncoding.h"
|
#include "PLKeyEncoding.h"
|
||||||
#include "PLMovies.h"
|
#include "PLMovies.h"
|
||||||
@@ -135,6 +136,14 @@ static void TranslateVOSEvent(const GpVOSEvent *vosEvent, uint32_t timestamp, Po
|
|||||||
case GpVOSEventTypes::kVideoResolutionChanged:
|
case GpVOSEventTypes::kVideoResolutionChanged:
|
||||||
TranslateVideoResolutionChangedEvent(vosEvent->m_event.m_resolutionChangedEvent);
|
TranslateVideoResolutionChangedEvent(vosEvent->m_event.m_resolutionChangedEvent);
|
||||||
break;
|
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="AEHandlerDesc.h" />
|
||||||
<ClInclude Include="AEManager.h" />
|
<ClInclude Include="AEManager.h" />
|
||||||
<ClInclude Include="AntiAliasTable.h" />
|
<ClInclude Include="AntiAliasTable.h" />
|
||||||
|
<ClInclude Include="AppEventHandler.h" />
|
||||||
<ClInclude Include="ArrayTools.h" />
|
<ClInclude Include="ArrayTools.h" />
|
||||||
<ClInclude Include="BinarySearch.h" />
|
<ClInclude Include="BinarySearch.h" />
|
||||||
<ClInclude Include="BinHex4.h" />
|
<ClInclude Include="BinHex4.h" />
|
||||||
@@ -303,6 +304,7 @@
|
|||||||
<ClCompile Include="..\stb\stb_image_write.c" />
|
<ClCompile Include="..\stb\stb_image_write.c" />
|
||||||
<ClCompile Include="AEManager.cpp" />
|
<ClCompile Include="AEManager.cpp" />
|
||||||
<ClCompile Include="AntiAliasTable.cpp" />
|
<ClCompile Include="AntiAliasTable.cpp" />
|
||||||
|
<ClCompile Include="AppEventHandler.cpp" />
|
||||||
<ClCompile Include="BinHex4.cpp" />
|
<ClCompile Include="BinHex4.cpp" />
|
||||||
<ClCompile Include="BitmapImage.cpp" />
|
<ClCompile Include="BitmapImage.cpp" />
|
||||||
<ClCompile Include="ByteSwap.cpp" />
|
<ClCompile Include="ByteSwap.cpp" />
|
||||||
|
|||||||
@@ -483,6 +483,9 @@
|
|||||||
<ClInclude Include="ArrayTools.h">
|
<ClInclude Include="ArrayTools.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="AppEventHandler.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="CFileStream.cpp">
|
<ClCompile Include="CFileStream.cpp">
|
||||||
@@ -758,5 +761,8 @@
|
|||||||
<ClCompile Include="TextPlacer.cpp">
|
<ClCompile Include="TextPlacer.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="AppEventHandler.cpp">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
Reference in New Issue
Block a user