summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/winrt
diff options
context:
space:
mode:
authorMaurice Kalinowski <maurice.kalinowski@digia.com>2014-01-31 13:02:01 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-02-04 13:56:18 +0100
commiteba56a35e3a1e208ba7b6c5b7bf26f61215d38d2 (patch)
tree2976c8e4db1d5b689093a4011a97711ee4255567 /src/plugins/platforms/winrt
parent19463c5c3f4b5b25eff557c813d6e6975ebc2491 (diff)
Add suspend and resume event handling for WinRT
Task-number: QTBUG-35952 Change-Id: Icb4edb0f55c1d02dfbb5501df311b0fff87d2dc1 Reviewed-by: Andrew Knight <andrew.knight@digia.com>
Diffstat (limited to 'src/plugins/platforms/winrt')
-rw-r--r--src/plugins/platforms/winrt/qwinrtscreen.cpp28
-rw-r--r--src/plugins/platforms/winrt/qwinrtscreen.h11
2 files changed, 39 insertions, 0 deletions
diff --git a/src/plugins/platforms/winrt/qwinrtscreen.cpp b/src/plugins/platforms/winrt/qwinrtscreen.cpp
index 911d3619fe..5bbf73a945 100644
--- a/src/plugins/platforms/winrt/qwinrtscreen.cpp
+++ b/src/plugins/platforms/winrt/qwinrtscreen.cpp
@@ -54,6 +54,8 @@
#include <wrl.h>
#include <windows.system.h>
+#include <Windows.Applicationmodel.h>
+#include <Windows.ApplicationModel.core.h>
#include <windows.devices.input.h>
#include <windows.ui.h>
#include <windows.ui.core.h>
@@ -64,6 +66,8 @@
using namespace Microsoft::WRL;
using namespace Microsoft::WRL::Wrappers;
+using namespace ABI::Windows::ApplicationModel;
+using namespace ABI::Windows::ApplicationModel::Core;
using namespace ABI::Windows::Foundation;
using namespace ABI::Windows::System;
using namespace ABI::Windows::UI::Core;
@@ -72,6 +76,8 @@ using namespace ABI::Windows::UI::ViewManagement;
using namespace ABI::Windows::Devices::Input;
using namespace ABI::Windows::Graphics::Display;
+typedef IEventHandler<IInspectable*> ResumeHandler;
+typedef IEventHandler<SuspendingEventArgs*> SuspendHandler;
typedef ITypedEventHandler<CoreWindow*, WindowActivatedEventArgs*> ActivatedHandler;
typedef ITypedEventHandler<CoreWindow*, CoreWindowEventArgs*> ClosedHandler;
typedef ITypedEventHandler<CoreWindow*, CharacterReceivedEventArgs*> CharacterReceivedHandler;
@@ -485,6 +491,13 @@ QWinRTScreen::QWinRTScreen(ICoreWindow *window)
GetActivationFactory(HString::MakeReference(RuntimeClass_Windows_UI_ViewManagement_ApplicationView).Get(),
&m_applicationView);
#endif
+
+
+ if (SUCCEEDED(RoGetActivationFactory(Wrappers::HString::MakeReference(RuntimeClass_Windows_ApplicationModel_Core_CoreApplication).Get(),
+ IID_PPV_ARGS(&m_application)))) {
+ m_application->add_Suspending(Callback<SuspendHandler>(this, &QWinRTScreen::onSuspended).Get(), &m_suspendTokens[Qt::ApplicationSuspended]);
+ m_application->add_Resuming(Callback<ResumeHandler>(this, &QWinRTScreen::onResume).Get(), &m_suspendTokens[Qt::ApplicationHidden]);
+ }
}
QRect QWinRTScreen::geometry() const
@@ -938,6 +951,21 @@ HRESULT QWinRTScreen::onActivated(ICoreWindow *window, IWindowActivatedEventArgs
return S_OK;
}
+HRESULT QWinRTScreen::onSuspended(IInspectable *, ISuspendingEventArgs *)
+{
+ QWindowSystemInterface::handleApplicationStateChanged(Qt::ApplicationSuspended);
+ QWindowSystemInterface::flushWindowSystemEvents();
+ return S_OK;
+}
+
+HRESULT QWinRTScreen::onResume(IInspectable *, IInspectable *)
+{
+ // First the system invokes onResume and then changes
+ // the visibility of the screen to be active.
+ QWindowSystemInterface::handleApplicationStateChanged(Qt::ApplicationHidden);
+ return S_OK;
+}
+
HRESULT QWinRTScreen::onClosed(ICoreWindow *window, ICoreWindowEventArgs *args)
{
Q_UNUSED(window);
diff --git a/src/plugins/platforms/winrt/qwinrtscreen.h b/src/plugins/platforms/winrt/qwinrtscreen.h
index 21e50fa10a..3131f879b5 100644
--- a/src/plugins/platforms/winrt/qwinrtscreen.h
+++ b/src/plugins/platforms/winrt/qwinrtscreen.h
@@ -53,6 +53,12 @@
namespace ABI {
namespace Windows {
+ namespace ApplicationModel {
+ struct ISuspendingEventArgs;
+ namespace Core {
+ struct ICoreApplication;
+ }
+ }
namespace UI {
namespace Core {
struct IAutomationProviderRequestedEventArgs;
@@ -123,6 +129,7 @@ private:
// Event handlers
QHash<QEvent::Type, EventRegistrationToken> m_tokens;
+ QHash<Qt::ApplicationState, EventRegistrationToken> m_suspendTokens;
HRESULT onKeyDown(ABI::Windows::UI::Core::ICoreWindow *window, ABI::Windows::UI::Core::IKeyEventArgs *args);
HRESULT onKeyUp(ABI::Windows::UI::Core::ICoreWindow *window, ABI::Windows::UI::Core::IKeyEventArgs *args);
@@ -133,6 +140,9 @@ private:
HRESULT onSizeChanged(ABI::Windows::UI::Core::ICoreWindow *window, ABI::Windows::UI::Core::IWindowSizeChangedEventArgs *args);
HRESULT onActivated(ABI::Windows::UI::Core::ICoreWindow *, ABI::Windows::UI::Core::IWindowActivatedEventArgs *args);
+ HRESULT onSuspended(IInspectable *, ABI::Windows::ApplicationModel::ISuspendingEventArgs *);
+ HRESULT onResume(IInspectable *, IInspectable *);
+
HRESULT onClosed(ABI::Windows::UI::Core::ICoreWindow *, ABI::Windows::UI::Core::ICoreWindowEventArgs *args);
HRESULT onVisibilityChanged(ABI::Windows::UI::Core::ICoreWindow *, ABI::Windows::UI::Core::IVisibilityChangedEventArgs *args);
HRESULT onAutomationProviderRequested(ABI::Windows::UI::Core::ICoreWindow *, ABI::Windows::UI::Core::IAutomationProviderRequestedEventArgs *args);
@@ -141,6 +151,7 @@ private:
ABI::Windows::UI::Core::ICoreWindow *m_coreWindow;
ABI::Windows::UI::ViewManagement::IApplicationViewStatics *m_applicationView;
+ ABI::Windows::ApplicationModel::Core::ICoreApplication *m_application;
QRect m_geometry;
QImage::Format m_format;
QSurfaceFormat m_surfaceFormat;