mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Fix windows taskbar notifications counter with multi-windows.
This commit is contained in:
parent
1c720af9bc
commit
b963a68dd6
3 changed files with 53 additions and 42 deletions
|
@ -12,35 +12,24 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "core/application.h"
|
#include "core/application.h"
|
||||||
#include "core/core_settings.h"
|
#include "core/core_settings.h"
|
||||||
#include "core/sandbox.h"
|
#include "core/sandbox.h"
|
||||||
|
#include "base/platform/win/base_windows_winrt.h"
|
||||||
|
|
||||||
#include <QtCore/QCoreApplication>
|
#include <QtCore/QCoreApplication>
|
||||||
#include <QtCore/QAbstractNativeEventFilter>
|
#include <QtCore/QAbstractNativeEventFilter>
|
||||||
|
|
||||||
namespace Platform {
|
namespace Platform {
|
||||||
namespace {
|
|
||||||
|
|
||||||
class WindowsIntegration final
|
|
||||||
: public Integration
|
|
||||||
, public QAbstractNativeEventFilter {
|
|
||||||
public:
|
|
||||||
void init() override;
|
|
||||||
|
|
||||||
private:
|
|
||||||
bool nativeEventFilter(
|
|
||||||
const QByteArray &eventType,
|
|
||||||
void *message,
|
|
||||||
long *result) override;
|
|
||||||
bool processEvent(
|
|
||||||
HWND hWnd,
|
|
||||||
UINT msg,
|
|
||||||
WPARAM wParam,
|
|
||||||
LPARAM lParam,
|
|
||||||
LRESULT *result);
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
void WindowsIntegration::init() {
|
void WindowsIntegration::init() {
|
||||||
QCoreApplication::instance()->installNativeEventFilter(this);
|
QCoreApplication::instance()->installNativeEventFilter(this);
|
||||||
|
_taskbarCreatedMsgId = RegisterWindowMessage(L"TaskbarButtonCreated");
|
||||||
|
}
|
||||||
|
|
||||||
|
ITaskbarList3 *WindowsIntegration::taskbarList() const {
|
||||||
|
return _taskbarList.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
WindowsIntegration &WindowsIntegration::Instance() {
|
||||||
|
return static_cast<WindowsIntegration&>(Integration::Instance());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WindowsIntegration::nativeEventFilter(
|
bool WindowsIntegration::nativeEventFilter(
|
||||||
|
@ -64,6 +53,12 @@ bool WindowsIntegration::processEvent(
|
||||||
WPARAM wParam,
|
WPARAM wParam,
|
||||||
LPARAM lParam,
|
LPARAM lParam,
|
||||||
LRESULT *result) {
|
LRESULT *result) {
|
||||||
|
if (msg && msg == _taskbarCreatedMsgId && !_taskbarList) {
|
||||||
|
_taskbarList = base::WinRT::TryCreateInstance<ITaskbarList3>(
|
||||||
|
CLSID_TaskbarList,
|
||||||
|
CLSCTX_ALL);
|
||||||
|
}
|
||||||
|
|
||||||
switch (msg) {
|
switch (msg) {
|
||||||
case WM_ENDSESSION:
|
case WM_ENDSESSION:
|
||||||
Core::Quit();
|
Core::Quit();
|
||||||
|
@ -90,8 +85,6 @@ bool WindowsIntegration::processEvent(
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
|
||||||
|
|
||||||
std::unique_ptr<Integration> CreateIntegration() {
|
std::unique_ptr<Integration> CreateIntegration() {
|
||||||
return std::make_unique<WindowsIntegration>();
|
return std::make_unique<WindowsIntegration>();
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,9 +7,41 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
*/
|
*/
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "platform/platform_integration.h"
|
||||||
|
|
||||||
|
#include <QAbstractNativeEventFilter>
|
||||||
|
|
||||||
|
#include <winrt/base.h>
|
||||||
|
#include <ShlObj.h>
|
||||||
|
|
||||||
namespace Platform {
|
namespace Platform {
|
||||||
|
|
||||||
class Integration;
|
class WindowsIntegration final
|
||||||
|
: public Integration
|
||||||
|
, public QAbstractNativeEventFilter {
|
||||||
|
public:
|
||||||
|
void init() override;
|
||||||
|
|
||||||
|
[[nodiscard]] ITaskbarList3 *taskbarList() const;
|
||||||
|
|
||||||
|
[[nodiscard]] static WindowsIntegration &Instance();
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool nativeEventFilter(
|
||||||
|
const QByteArray &eventType,
|
||||||
|
void *message,
|
||||||
|
long *result) override;
|
||||||
|
bool processEvent(
|
||||||
|
HWND hWnd,
|
||||||
|
UINT msg,
|
||||||
|
WPARAM wParam,
|
||||||
|
LPARAM lParam,
|
||||||
|
LRESULT *result);
|
||||||
|
|
||||||
|
uint32 _taskbarCreatedMsgId = 0;
|
||||||
|
winrt::com_ptr<ITaskbarList3> _taskbarList;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
[[nodiscard]] std::unique_ptr<Integration> CreateIntegration();
|
[[nodiscard]] std::unique_ptr<Integration> CreateIntegration();
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "platform/platform_notifications_manager.h"
|
#include "platform/platform_notifications_manager.h"
|
||||||
#include "platform/win/tray_win.h"
|
#include "platform/win/tray_win.h"
|
||||||
#include "platform/win/windows_dlls.h"
|
#include "platform/win/windows_dlls.h"
|
||||||
|
#include "platform/win/integration_win.h"
|
||||||
#include "window/notifications_manager.h"
|
#include "window/notifications_manager.h"
|
||||||
#include "window/window_session_controller.h"
|
#include "window/window_session_controller.h"
|
||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
|
@ -82,9 +83,7 @@ private:
|
||||||
|
|
||||||
using namespace Microsoft::WRL;
|
using namespace Microsoft::WRL;
|
||||||
|
|
||||||
ComPtr<ITaskbarList3> taskbarList;
|
|
||||||
bool handleSessionNotification = false;
|
bool handleSessionNotification = false;
|
||||||
uint32 kTaskbarCreatedMsgId = 0;
|
|
||||||
|
|
||||||
[[nodiscard]] HICON NativeIcon(const QIcon &icon, QSize size) {
|
[[nodiscard]] HICON NativeIcon(const QIcon &icon, QSize size) {
|
||||||
if (!icon.isNull()) {
|
if (!icon.isNull()) {
|
||||||
|
@ -124,15 +123,6 @@ bool EventFilter::mainWindowEvent(
|
||||||
WPARAM wParam,
|
WPARAM wParam,
|
||||||
LPARAM lParam,
|
LPARAM lParam,
|
||||||
LRESULT *result) {
|
LRESULT *result) {
|
||||||
if (const auto tbCreatedMsgId = kTaskbarCreatedMsgId) {
|
|
||||||
if (msg == tbCreatedMsgId) {
|
|
||||||
HRESULT hr = CoCreateInstance(CLSID_TaskbarList, nullptr, CLSCTX_ALL, IID_PPV_ARGS(&taskbarList));
|
|
||||||
if (!SUCCEEDED(hr)) {
|
|
||||||
taskbarList.Reset();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (msg) {
|
switch (msg) {
|
||||||
|
|
||||||
case WM_DESTROY: {
|
case WM_DESTROY: {
|
||||||
|
@ -179,9 +169,6 @@ MainWindow::MainWindow(not_null<Window::Controller*> controller)
|
||||||
, _taskbarHiderWindow(std::make_unique<QWindow>()) {
|
, _taskbarHiderWindow(std::make_unique<QWindow>()) {
|
||||||
qApp->installNativeEventFilter(&_private->filter);
|
qApp->installNativeEventFilter(&_private->filter);
|
||||||
|
|
||||||
if (!kTaskbarCreatedMsgId) {
|
|
||||||
kTaskbarCreatedMsgId = RegisterWindowMessage(L"TaskbarButtonCreated");
|
|
||||||
}
|
|
||||||
setupNativeWindowFrame();
|
setupNativeWindowFrame();
|
||||||
|
|
||||||
using namespace rpl::mappers;
|
using namespace rpl::mappers;
|
||||||
|
@ -356,7 +343,9 @@ void MainWindow::updateIconCounters() {
|
||||||
QIcon iconSmall, iconBig;
|
QIcon iconSmall, iconBig;
|
||||||
iconSmall.addPixmap(iconSmallPixmap16);
|
iconSmall.addPixmap(iconSmallPixmap16);
|
||||||
iconSmall.addPixmap(iconSmallPixmap32);
|
iconSmall.addPixmap(iconSmallPixmap32);
|
||||||
const auto bigCounter = taskbarList.Get() ? 0 : counter;
|
const auto integration = &Platform::WindowsIntegration::Instance();
|
||||||
|
const auto taskbarList = integration->taskbarList();
|
||||||
|
const auto bigCounter = taskbarList ? 0 : counter;
|
||||||
iconBig.addPixmap(Tray::IconWithCounter(
|
iconBig.addPixmap(Tray::IconWithCounter(
|
||||||
Tray::CounterLayerArgs(32, bigCounter, muted),
|
Tray::CounterLayerArgs(32, bigCounter, muted),
|
||||||
false,
|
false,
|
||||||
|
@ -528,9 +517,6 @@ void MainWindow::destroyCachedIcons() {
|
||||||
MainWindow::~MainWindow() {
|
MainWindow::~MainWindow() {
|
||||||
WTSUnRegisterSessionNotification(_hWnd);
|
WTSUnRegisterSessionNotification(_hWnd);
|
||||||
_private->viewSettings.Reset();
|
_private->viewSettings.Reset();
|
||||||
if (taskbarList) {
|
|
||||||
taskbarList.Reset();
|
|
||||||
}
|
|
||||||
destroyCachedIcons();
|
destroyCachedIcons();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue