2022-01-04 12:29:40 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
|
|
|
the official desktop application for the Telegram messaging service.
|
|
|
|
|
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|
|
|
*/
|
|
|
|
#include "platform/win/integration_win.h"
|
|
|
|
|
|
|
|
#include "platform/platform_integration.h"
|
|
|
|
#include "platform/platform_specific.h"
|
|
|
|
#include "core/application.h"
|
2022-06-13 09:27:38 +00:00
|
|
|
#include "core/core_settings.h"
|
2022-01-04 12:29:40 +00:00
|
|
|
#include "core/sandbox.h"
|
2022-06-20 08:56:50 +00:00
|
|
|
#include "base/platform/win/base_windows_winrt.h"
|
2022-01-04 12:29:40 +00:00
|
|
|
|
|
|
|
#include <QtCore/QCoreApplication>
|
|
|
|
#include <QtCore/QAbstractNativeEventFilter>
|
|
|
|
|
|
|
|
namespace Platform {
|
|
|
|
|
|
|
|
void WindowsIntegration::init() {
|
|
|
|
QCoreApplication::instance()->installNativeEventFilter(this);
|
2022-06-20 08:56:50 +00:00
|
|
|
_taskbarCreatedMsgId = RegisterWindowMessage(L"TaskbarButtonCreated");
|
|
|
|
}
|
|
|
|
|
|
|
|
ITaskbarList3 *WindowsIntegration::taskbarList() const {
|
|
|
|
return _taskbarList.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
WindowsIntegration &WindowsIntegration::Instance() {
|
|
|
|
return static_cast<WindowsIntegration&>(Integration::Instance());
|
2022-01-04 12:29:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool WindowsIntegration::nativeEventFilter(
|
|
|
|
const QByteArray &eventType,
|
|
|
|
void *message,
|
|
|
|
long *result) {
|
|
|
|
return Core::Sandbox::Instance().customEnterFromEventLoop([&] {
|
|
|
|
const auto msg = static_cast<MSG*>(message);
|
|
|
|
return processEvent(
|
|
|
|
msg->hwnd,
|
|
|
|
msg->message,
|
|
|
|
msg->wParam,
|
|
|
|
msg->lParam,
|
|
|
|
(LRESULT*)result);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
bool WindowsIntegration::processEvent(
|
|
|
|
HWND hWnd,
|
|
|
|
UINT msg,
|
|
|
|
WPARAM wParam,
|
|
|
|
LPARAM lParam,
|
|
|
|
LRESULT *result) {
|
2022-06-20 08:56:50 +00:00
|
|
|
if (msg && msg == _taskbarCreatedMsgId && !_taskbarList) {
|
|
|
|
_taskbarList = base::WinRT::TryCreateInstance<ITaskbarList3>(
|
|
|
|
CLSID_TaskbarList,
|
|
|
|
CLSCTX_ALL);
|
|
|
|
}
|
|
|
|
|
2022-01-04 12:29:40 +00:00
|
|
|
switch (msg) {
|
|
|
|
case WM_ENDSESSION:
|
2022-01-27 12:48:51 +00:00
|
|
|
Core::Quit();
|
2022-01-04 12:29:40 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case WM_TIMECHANGE:
|
|
|
|
Core::App().checkAutoLockIn(100);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WM_WTSSESSION_CHANGE:
|
|
|
|
if (wParam == WTS_SESSION_LOGOFF
|
|
|
|
|| wParam == WTS_SESSION_LOCK) {
|
|
|
|
Core::App().setScreenIsLocked(true);
|
|
|
|
} else if (wParam == WTS_SESSION_LOGON
|
|
|
|
|| wParam == WTS_SESSION_UNLOCK) {
|
|
|
|
Core::App().setScreenIsLocked(false);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2023-05-13 17:01:06 +00:00
|
|
|
#if QT_VERSION < QT_VERSION_CHECK(6, 5, 0)
|
2022-01-04 12:29:40 +00:00
|
|
|
case WM_SETTINGCHANGE:
|
|
|
|
Core::App().settings().setSystemDarkMode(Platform::IsDarkMode());
|
|
|
|
break;
|
2023-05-13 17:01:06 +00:00
|
|
|
#endif // Qt < 6.5.0
|
2022-01-04 12:29:40 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<Integration> CreateIntegration() {
|
|
|
|
return std::make_unique<WindowsIntegration>();
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Platform
|