mirror of https://github.com/procxx/kepka.git
Fix window title on Windows 7.
Regression was introduced in dd68c7e90
.
Fixes #6106.
This commit is contained in:
parent
abfe685697
commit
1225c9194a
|
@ -162,9 +162,6 @@ void Application::run() {
|
||||||
|
|
||||||
DEBUG_LOG(("Application Info: inited..."));
|
DEBUG_LOG(("Application Info: inited..."));
|
||||||
|
|
||||||
QCoreApplication::instance()->installNativeEventFilter(
|
|
||||||
psNativeEventFilter());
|
|
||||||
|
|
||||||
cChangeTimeFormat(QLocale::system().timeFormat(QLocale::ShortFormat));
|
cChangeTimeFormat(QLocale::system().timeFormat(QLocale::ShortFormat));
|
||||||
|
|
||||||
DEBUG_LOG(("Application Info: starting app..."));
|
DEBUG_LOG(("Application Info: starting app..."));
|
||||||
|
|
|
@ -118,17 +118,6 @@ QString CurrentExecutablePath(int argc, char *argv[]) {
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
class _PsEventFilter : public QAbstractNativeEventFilter {
|
|
||||||
public:
|
|
||||||
bool nativeEventFilter(const QByteArray &eventType, void *message, long *result) {
|
|
||||||
//auto wnd = App::wnd();
|
|
||||||
//if (!wnd) return false;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
_PsEventFilter *_psEventFilter = nullptr;
|
|
||||||
|
|
||||||
QRect _monitorRect;
|
QRect _monitorRect;
|
||||||
auto _monitorLastGot = 0LL;
|
auto _monitorLastGot = 0LL;
|
||||||
|
|
||||||
|
@ -149,12 +138,6 @@ void psShowOverAll(QWidget *w, bool canFocus) {
|
||||||
void psBringToBack(QWidget *w) {
|
void psBringToBack(QWidget *w) {
|
||||||
}
|
}
|
||||||
|
|
||||||
QAbstractNativeEventFilter *psNativeEventFilter() {
|
|
||||||
delete _psEventFilter;
|
|
||||||
_psEventFilter = new _PsEventFilter();
|
|
||||||
return _psEventFilter;
|
|
||||||
}
|
|
||||||
|
|
||||||
void psWriteDump() {
|
void psWriteDump() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -255,9 +238,6 @@ void start() {
|
||||||
|
|
||||||
void finish() {
|
void finish() {
|
||||||
Notifications::Finish();
|
Notifications::Finish();
|
||||||
|
|
||||||
delete _psEventFilter;
|
|
||||||
_psEventFilter = nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TranslucentWindowsSupported(QPoint globalPosition) {
|
bool TranslucentWindowsSupported(QPoint globalPosition) {
|
||||||
|
|
|
@ -69,8 +69,6 @@ void psBringToBack(QWidget *w);
|
||||||
int psCleanup();
|
int psCleanup();
|
||||||
int psFixPrevious();
|
int psFixPrevious();
|
||||||
|
|
||||||
QAbstractNativeEventFilter *psNativeEventFilter();
|
|
||||||
|
|
||||||
void psNewVersion();
|
void psNewVersion();
|
||||||
|
|
||||||
void psUpdateOverlayed(QWidget *widget);
|
void psUpdateOverlayed(QWidget *widget);
|
||||||
|
|
|
@ -95,11 +95,30 @@ private:
|
||||||
|
|
||||||
#endif // OS_MAC_OLD
|
#endif // OS_MAC_OLD
|
||||||
|
|
||||||
|
class EventFilter : public QAbstractNativeEventFilter {
|
||||||
|
public:
|
||||||
|
EventFilter(not_null<MainWindow*> window) : _window(window) {
|
||||||
|
}
|
||||||
|
|
||||||
|
bool nativeEventFilter(
|
||||||
|
const QByteArray &eventType,
|
||||||
|
void *message,
|
||||||
|
long *result) {
|
||||||
|
return Core::Sandbox::Instance().customEnterFromEventLoop([&] {
|
||||||
|
return _window->psFilterNativeEvent(message);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
not_null<MainWindow*> _window;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
class MainWindow::Private {
|
class MainWindow::Private {
|
||||||
public:
|
public:
|
||||||
Private(MainWindow *window);
|
explicit Private(not_null<MainWindow*> window);
|
||||||
|
|
||||||
void setNativeWindow(NSWindow *window, NSView *view);
|
void setNativeWindow(NSWindow *window, NSView *view);
|
||||||
void setWindowBadge(const QString &str);
|
void setWindowBadge(const QString &str);
|
||||||
|
@ -123,7 +142,7 @@ private:
|
||||||
void initCustomTitle();
|
void initCustomTitle();
|
||||||
void refreshWeakTitleReferences();
|
void refreshWeakTitleReferences();
|
||||||
|
|
||||||
MainWindow *_public;
|
not_null<MainWindow*> _public;
|
||||||
friend class MainWindow;
|
friend class MainWindow;
|
||||||
|
|
||||||
#ifdef OS_MAC_OLD
|
#ifdef OS_MAC_OLD
|
||||||
|
@ -139,11 +158,13 @@ private:
|
||||||
bool _useNativeTitle = false;
|
bool _useNativeTitle = false;
|
||||||
bool _inFullScreen = false;
|
bool _inFullScreen = false;
|
||||||
|
|
||||||
MainWindowObserver *_observer;
|
MainWindowObserver *_observer = nullptr;
|
||||||
NSPasteboard *_generalPasteboard = nullptr;
|
NSPasteboard *_generalPasteboard = nullptr;
|
||||||
int _generalPasteboardChangeCount = -1;
|
int _generalPasteboardChangeCount = -1;
|
||||||
bool _generalPasteboardHasText = false;
|
bool _generalPasteboardHasText = false;
|
||||||
|
|
||||||
|
EventFilter _nativeEventFilter;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Platform
|
} // namespace Platform
|
||||||
|
@ -187,9 +208,10 @@ private:
|
||||||
|
|
||||||
namespace Platform {
|
namespace Platform {
|
||||||
|
|
||||||
MainWindow::Private::Private(MainWindow *window)
|
MainWindow::Private::Private(not_null<MainWindow*> window)
|
||||||
: _public(window)
|
: _public(window)
|
||||||
, _observer([[MainWindowObserver alloc] init:this]) {
|
, _observer([[MainWindowObserver alloc] init:this])
|
||||||
|
, _nativeEventFilter(window) {
|
||||||
_generalPasteboard = [NSPasteboard generalPasteboard];
|
_generalPasteboard = [NSPasteboard generalPasteboard];
|
||||||
|
|
||||||
@autoreleasepool {
|
@autoreleasepool {
|
||||||
|
@ -384,6 +406,9 @@ MainWindow::Private::~Private() {
|
||||||
MainWindow::MainWindow(not_null<Window::Controller*> controller)
|
MainWindow::MainWindow(not_null<Window::Controller*> controller)
|
||||||
: Window::MainWindow(controller)
|
: Window::MainWindow(controller)
|
||||||
, _private(std::make_unique<Private>(this)) {
|
, _private(std::make_unique<Private>(this)) {
|
||||||
|
QCoreApplication::instance()->installNativeEventFilter(
|
||||||
|
&_private->_nativeEventFilter);
|
||||||
|
|
||||||
#ifndef OS_MAC_OLD
|
#ifndef OS_MAC_OLD
|
||||||
auto forceOpenGL = std::make_unique<QOpenGLWidget>(this);
|
auto forceOpenGL = std::make_unique<QOpenGLWidget>(this);
|
||||||
#endif // !OS_MAC_OLD
|
#endif // !OS_MAC_OLD
|
||||||
|
|
|
@ -68,8 +68,6 @@ int psFixPrevious();
|
||||||
|
|
||||||
bool psShowOpenWithMenu(int x, int y, const QString &file);
|
bool psShowOpenWithMenu(int x, int y, const QString &file);
|
||||||
|
|
||||||
QAbstractNativeEventFilter *psNativeEventFilter();
|
|
||||||
|
|
||||||
void psNewVersion();
|
void psNewVersion();
|
||||||
|
|
||||||
void psUpdateOverlayed(QWidget *widget);
|
void psUpdateOverlayed(QWidget *widget);
|
||||||
|
|
|
@ -33,23 +33,6 @@ namespace {
|
||||||
|
|
||||||
QStringList _initLogs;
|
QStringList _initLogs;
|
||||||
|
|
||||||
class _PsEventFilter : public QAbstractNativeEventFilter {
|
|
||||||
public:
|
|
||||||
_PsEventFilter() {
|
|
||||||
}
|
|
||||||
|
|
||||||
bool nativeEventFilter(const QByteArray &eventType, void *message, long *result) {
|
|
||||||
return Core::Sandbox::Instance().customEnterFromEventLoop([&] {
|
|
||||||
auto wnd = App::wnd();
|
|
||||||
if (!wnd) return false;
|
|
||||||
|
|
||||||
return wnd->psFilterNativeEvent(message);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
_PsEventFilter *_psEventFilter = nullptr;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
@ -76,12 +59,6 @@ void psBringToBack(QWidget *w) {
|
||||||
objc_bringToBack(w->winId());
|
objc_bringToBack(w->winId());
|
||||||
}
|
}
|
||||||
|
|
||||||
QAbstractNativeEventFilter *psNativeEventFilter() {
|
|
||||||
delete _psEventFilter;
|
|
||||||
_psEventFilter = new _PsEventFilter();
|
|
||||||
return _psEventFilter;
|
|
||||||
}
|
|
||||||
|
|
||||||
void psWriteDump() {
|
void psWriteDump() {
|
||||||
#ifndef TDESKTOP_DISABLE_CRASH_REPORTS
|
#ifndef TDESKTOP_DISABLE_CRASH_REPORTS
|
||||||
double v = objc_appkitVersion();
|
double v = objc_appkitVersion();
|
||||||
|
@ -139,9 +116,6 @@ void start() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void finish() {
|
void finish() {
|
||||||
delete _psEventFilter;
|
|
||||||
_psEventFilter = nullptr;
|
|
||||||
|
|
||||||
objc_finish();
|
objc_finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "styles/style_window.h"
|
#include "styles/style_window.h"
|
||||||
#include "platform/platform_notifications_manager.h"
|
#include "platform/platform_notifications_manager.h"
|
||||||
#include "platform/win/windows_dlls.h"
|
#include "platform/win/windows_dlls.h"
|
||||||
|
#include "platform/win/windows_event_filter.h"
|
||||||
#include "window/notifications_manager.h"
|
#include "window/notifications_manager.h"
|
||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
#include "core/application.h"
|
#include "core/application.h"
|
||||||
|
@ -129,7 +130,8 @@ public:
|
||||||
update(Change::Moved | Change::Resized);
|
update(Change::Moved | Change::Resized);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool init(QColor c) {
|
bool init(not_null<MainWindow*> window, QColor c) {
|
||||||
|
_window = window;
|
||||||
_fullsize = st::windowShadow.width();
|
_fullsize = st::windowShadow.width();
|
||||||
_shift = st::windowShadowShift;
|
_shift = st::windowShadowShift;
|
||||||
auto cornersImage = QImage(_fullsize, _fullsize, QImage::Format_ARGB32_Premultiplied);
|
auto cornersImage = QImage(_fullsize, _fullsize, QImage::Format_ARGB32_Premultiplied);
|
||||||
|
@ -186,7 +188,7 @@ public:
|
||||||
accumulate_max(max_h, st::titleHeight + st::windowMinHeight);
|
accumulate_max(max_h, st::titleHeight + st::windowMinHeight);
|
||||||
|
|
||||||
HINSTANCE appinst = (HINSTANCE)GetModuleHandle(0);
|
HINSTANCE appinst = (HINSTANCE)GetModuleHandle(0);
|
||||||
HWND hwnd = App::wnd() ? App::wnd()->psHwnd() : 0;
|
HWND hwnd = _window ? _window->psHwnd() : nullptr;
|
||||||
|
|
||||||
for (int i = 0; i < 4; ++i) {
|
for (int i = 0; i < 4; ++i) {
|
||||||
QString cn = QString("TelegramShadow%1").arg(i);
|
QString cn = QString("TelegramShadow%1").arg(i);
|
||||||
|
@ -320,7 +322,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
void update(Changes changes, WINDOWPOS *pos = 0) {
|
void update(Changes changes, WINDOWPOS *pos = 0) {
|
||||||
HWND hwnd = App::wnd() ? App::wnd()->psHwnd() : 0;
|
HWND hwnd = _window ? _window->psHwnd() : 0;
|
||||||
if (!hwnd || !hwnds[0]) return;
|
if (!hwnd || !hwnds[0]) return;
|
||||||
|
|
||||||
if (changes == Changes(Change::Activate)) {
|
if (changes == Changes(Change::Activate)) {
|
||||||
|
@ -339,7 +341,7 @@ public:
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!App::wnd()->positionInited()) return;
|
if (!_window->positionInited()) return;
|
||||||
|
|
||||||
int x = _x, y = _y, w = _w, h = _h;
|
int x = _x, y = _y, w = _w, h = _h;
|
||||||
if (pos && (!(pos->flags & SWP_NOMOVE) || !(pos->flags & SWP_NOSIZE) || !(pos->flags & SWP_NOREPOSITION))) {
|
if (pos && (!(pos->flags & SWP_NOMOVE) || !(pos->flags & SWP_NOSIZE) || !(pos->flags & SWP_NOREPOSITION))) {
|
||||||
|
@ -497,12 +499,17 @@ public:
|
||||||
if (screenDC) ReleaseDC(0, screenDC);
|
if (screenDC) ReleaseDC(0, screenDC);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MainWindow *window() const {
|
||||||
|
return _window;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
int _x = 0, _y = 0, _w = 0, _h = 0;
|
int _x = 0, _y = 0, _w = 0, _h = 0;
|
||||||
int _metaSize = 0, _fullsize = 0, _size = 0, _shift = 0;
|
int _metaSize = 0, _fullsize = 0, _size = 0, _shift = 0;
|
||||||
QVector<BYTE> _alphas, _colors;
|
QVector<BYTE> _alphas, _colors;
|
||||||
|
|
||||||
|
MainWindow *_window = nullptr;
|
||||||
bool hidden = true;
|
bool hidden = true;
|
||||||
|
|
||||||
HWND hwnds[4];
|
HWND hwnds[4];
|
||||||
|
@ -520,8 +527,10 @@ private:
|
||||||
_PsShadowWindows _psShadowWindows;
|
_PsShadowWindows _psShadowWindows;
|
||||||
|
|
||||||
LRESULT CALLBACK _PsShadowWindows::wndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
|
LRESULT CALLBACK _PsShadowWindows::wndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
|
||||||
auto wnd = App::wnd();
|
const auto window = _psShadowWindows.window();
|
||||||
if (!wnd || !wnd->shadowsWorking()) return DefWindowProc(hwnd, msg, wParam, lParam);
|
if (!window || !window->shadowsWorking()) {
|
||||||
|
return DefWindowProc(hwnd, msg, wParam, lParam);
|
||||||
|
}
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < 4; ++i) {
|
for (i = 0; i < 4; ++i) {
|
||||||
|
@ -533,7 +542,7 @@ LRESULT CALLBACK _PsShadowWindows::wndProc(HWND hwnd, UINT msg, WPARAM wParam, L
|
||||||
|
|
||||||
switch (msg) {
|
switch (msg) {
|
||||||
case WM_CLOSE:
|
case WM_CLOSE:
|
||||||
App::wnd()->close();
|
window->close();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WM_NCHITTEST: {
|
case WM_NCHITTEST: {
|
||||||
|
@ -566,20 +575,20 @@ LRESULT CALLBACK _PsShadowWindows::wndProc(HWND hwnd, UINT msg, WPARAM wParam, L
|
||||||
case WM_NCPOINTERUPDATE:
|
case WM_NCPOINTERUPDATE:
|
||||||
case WM_NCPOINTERDOWN:
|
case WM_NCPOINTERDOWN:
|
||||||
case WM_NCPOINTERUP:
|
case WM_NCPOINTERUP:
|
||||||
if (App::wnd() && App::wnd()->psHwnd()) {
|
if (window && window->psHwnd()) {
|
||||||
if (msg == WM_NCLBUTTONDOWN) {
|
if (msg == WM_NCLBUTTONDOWN) {
|
||||||
::SetForegroundWindow(App::wnd()->psHwnd());
|
::SetForegroundWindow(window->psHwnd());
|
||||||
}
|
}
|
||||||
LRESULT res = SendMessage(App::wnd()->psHwnd(), msg, wParam, lParam);
|
LRESULT res = SendMessage(window->psHwnd(), msg, wParam, lParam);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
break;
|
break;
|
||||||
case WM_ACTIVATE:
|
case WM_ACTIVATE:
|
||||||
if (App::wnd() && App::wnd()->psHwnd() && wParam == WA_ACTIVE) {
|
if (window && window->psHwnd() && wParam == WA_ACTIVE) {
|
||||||
if ((HWND)lParam != App::wnd()->psHwnd()) {
|
if ((HWND)lParam != window->psHwnd()) {
|
||||||
::SetForegroundWindow(hwnd);
|
::SetForegroundWindow(hwnd);
|
||||||
::SetWindowPos(App::wnd()->psHwnd(), hwnd, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
|
::SetWindowPos(window->psHwnd(), hwnd, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return DefWindowProc(hwnd, msg, wParam, lParam);
|
return DefWindowProc(hwnd, msg, wParam, lParam);
|
||||||
|
@ -601,6 +610,9 @@ UINT MainWindow::_taskbarCreatedMsgId = 0;
|
||||||
MainWindow::MainWindow(not_null<Window::Controller*> controller)
|
MainWindow::MainWindow(not_null<Window::Controller*> controller)
|
||||||
: Window::MainWindow(controller)
|
: Window::MainWindow(controller)
|
||||||
, ps_tbHider_hWnd(createTaskbarHider()) {
|
, ps_tbHider_hWnd(createTaskbarHider()) {
|
||||||
|
QCoreApplication::instance()->installNativeEventFilter(
|
||||||
|
EventFilter::CreateInstance(this));
|
||||||
|
|
||||||
if (!_taskbarCreatedMsgId) {
|
if (!_taskbarCreatedMsgId) {
|
||||||
_taskbarCreatedMsgId = RegisterWindowMessage(L"TaskbarButtonCreated");
|
_taskbarCreatedMsgId = RegisterWindowMessage(L"TaskbarButtonCreated");
|
||||||
}
|
}
|
||||||
|
@ -787,7 +799,7 @@ void MainWindow::initHook() {
|
||||||
|
|
||||||
Q_DECLARE_METATYPE(QMargins);
|
Q_DECLARE_METATYPE(QMargins);
|
||||||
void MainWindow::psFirstShow() {
|
void MainWindow::psFirstShow() {
|
||||||
_psShadowWindows.init(st::windowShadowFg->c);
|
_psShadowWindows.init(this, st::windowShadowFg->c);
|
||||||
_shadowsWorking = true;
|
_shadowsWorking = true;
|
||||||
|
|
||||||
psUpdateMargins();
|
psUpdateMargins();
|
||||||
|
@ -973,6 +985,8 @@ MainWindow::~MainWindow() {
|
||||||
psDestroyIcons();
|
psDestroyIcons();
|
||||||
_psShadowWindows.destroy();
|
_psShadowWindows.destroy();
|
||||||
if (ps_tbHider_hWnd) DestroyWindow(ps_tbHider_hWnd);
|
if (ps_tbHider_hWnd) DestroyWindow(ps_tbHider_hWnd);
|
||||||
|
|
||||||
|
EventFilter::Destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Platform
|
} // namespace Platform
|
||||||
|
|
|
@ -665,14 +665,15 @@ void querySystemNotificationSettings() {
|
||||||
bool SkipAudio() {
|
bool SkipAudio() {
|
||||||
querySystemNotificationSettings();
|
querySystemNotificationSettings();
|
||||||
|
|
||||||
if (UserNotificationState == QUNS_NOT_PRESENT || UserNotificationState == QUNS_PRESENTATION_MODE) {
|
if (UserNotificationState == QUNS_NOT_PRESENT
|
||||||
|
|| UserNotificationState == QUNS_PRESENTATION_MODE
|
||||||
|
|| QuietHoursEnabled) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (QuietHoursEnabled) {
|
if (const auto filter = EventFilter::GetInstance()) {
|
||||||
return true;
|
if (filter->sessionLoggedOff()) {
|
||||||
}
|
return true;
|
||||||
if (EventFilter::getInstance()->sessionLoggedOff()) {
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -680,10 +681,10 @@ bool SkipAudio() {
|
||||||
bool SkipToast() {
|
bool SkipToast() {
|
||||||
querySystemNotificationSettings();
|
querySystemNotificationSettings();
|
||||||
|
|
||||||
if (UserNotificationState == QUNS_PRESENTATION_MODE || UserNotificationState == QUNS_RUNNING_D3D_FULL_SCREEN/* || UserNotificationState == QUNS_BUSY*/) {
|
if (UserNotificationState == QUNS_PRESENTATION_MODE
|
||||||
return true;
|
|| UserNotificationState == QUNS_RUNNING_D3D_FULL_SCREEN
|
||||||
}
|
//|| UserNotificationState == QUNS_BUSY
|
||||||
if (QuietHoursEnabled) {
|
|| QuietHoursEnabled) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -11,7 +11,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "platform/win/notifications_manager_win.h"
|
#include "platform/win/notifications_manager_win.h"
|
||||||
#include "platform/win/windows_app_user_model_id.h"
|
#include "platform/win/windows_app_user_model_id.h"
|
||||||
#include "platform/win/windows_dlls.h"
|
#include "platform/win/windows_dlls.h"
|
||||||
#include "platform/win/windows_event_filter.h"
|
|
||||||
#include "lang/lang_keys.h"
|
#include "lang/lang_keys.h"
|
||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
#include "mainwidget.h"
|
#include "mainwidget.h"
|
||||||
|
@ -81,10 +80,6 @@ namespace {
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
QAbstractNativeEventFilter *psNativeEventFilter() {
|
|
||||||
return EventFilter::createInstance();
|
|
||||||
}
|
|
||||||
|
|
||||||
void psDeleteDir(const QString &dir) {
|
void psDeleteDir(const QString &dir) {
|
||||||
std::wstring wDir = QDir::toNativeSeparators(dir).toStdWString();
|
std::wstring wDir = QDir::toNativeSeparators(dir).toStdWString();
|
||||||
WCHAR path[4096];
|
WCHAR path[4096];
|
||||||
|
@ -286,7 +281,6 @@ void start() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void finish() {
|
void finish() {
|
||||||
EventFilter::destroy();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsApplicationActive() {
|
bool IsApplicationActive() {
|
||||||
|
|
|
@ -74,8 +74,6 @@ void psBringToBack(QWidget *w);
|
||||||
int psCleanup();
|
int psCleanup();
|
||||||
int psFixPrevious();
|
int psFixPrevious();
|
||||||
|
|
||||||
QAbstractNativeEventFilter *psNativeEventFilter();
|
|
||||||
|
|
||||||
void psNewVersion();
|
void psNewVersion();
|
||||||
|
|
||||||
void psUpdateOverlayed(TWidget *widget);
|
void psUpdateOverlayed(TWidget *widget);
|
||||||
|
|
|
@ -29,40 +29,56 @@ bool IsCompositionEnabled() {
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
EventFilter *EventFilter::createInstance() {
|
EventFilter *EventFilter::CreateInstance(not_null<MainWindow*> window) {
|
||||||
destroy();
|
Expects(instance == nullptr);
|
||||||
instance = new EventFilter();
|
|
||||||
return getInstance();
|
return (instance = new EventFilter(window));
|
||||||
}
|
}
|
||||||
|
|
||||||
EventFilter *EventFilter::getInstance() {
|
EventFilter *EventFilter::GetInstance() {
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
void EventFilter::destroy() {
|
void EventFilter::Destroy() {
|
||||||
|
Expects(instance != nullptr);
|
||||||
|
|
||||||
delete instance;
|
delete instance;
|
||||||
instance = nullptr;
|
instance = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EventFilter::nativeEventFilter(const QByteArray &eventType, void *message, long *result) {
|
EventFilter::EventFilter(not_null<MainWindow*> window) : _window(window) {
|
||||||
auto wnd = App::wnd();
|
}
|
||||||
if (!wnd) return false;
|
|
||||||
|
|
||||||
MSG *msg = (MSG*)message;
|
bool EventFilter::nativeEventFilter(
|
||||||
|
const QByteArray &eventType,
|
||||||
|
void *message,
|
||||||
|
long *result) {
|
||||||
|
const auto msg = static_cast<MSG*>(message);
|
||||||
if (msg->message == WM_ENDSESSION) {
|
if (msg->message == WM_ENDSESSION) {
|
||||||
App::quit();
|
App::quit();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (msg->hwnd == wnd->psHwnd() || msg->hwnd && !wnd->psHwnd()) {
|
if (msg->hwnd == _window->psHwnd()
|
||||||
return mainWindowEvent(msg->hwnd, msg->message, msg->wParam, msg->lParam, (LRESULT*)result);
|
|| msg->hwnd && !_window->psHwnd()) {
|
||||||
|
return mainWindowEvent(
|
||||||
|
msg->hwnd,
|
||||||
|
msg->message,
|
||||||
|
msg->wParam,
|
||||||
|
msg->lParam,
|
||||||
|
(LRESULT*)result);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EventFilter::mainWindowEvent(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, LRESULT *result) {
|
bool EventFilter::mainWindowEvent(
|
||||||
|
HWND hWnd,
|
||||||
|
UINT msg,
|
||||||
|
WPARAM wParam,
|
||||||
|
LPARAM lParam,
|
||||||
|
LRESULT *result) {
|
||||||
using ShadowsChange = MainWindow::ShadowsChange;
|
using ShadowsChange = MainWindow::ShadowsChange;
|
||||||
|
|
||||||
if (auto tbCreatedMsgId = Platform::MainWindow::TaskbarCreatedMsgId()) {
|
if (const auto tbCreatedMsgId = Platform::MainWindow::TaskbarCreatedMsgId()) {
|
||||||
if (msg == tbCreatedMsgId) {
|
if (msg == tbCreatedMsgId) {
|
||||||
Platform::MainWindow::TaskbarCreated();
|
Platform::MainWindow::TaskbarCreated();
|
||||||
}
|
}
|
||||||
|
@ -90,15 +106,15 @@ bool EventFilter::mainWindowEvent(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lPa
|
||||||
|
|
||||||
case WM_ACTIVATE: {
|
case WM_ACTIVATE: {
|
||||||
if (LOWORD(wParam) == WA_CLICKACTIVE) {
|
if (LOWORD(wParam) == WA_CLICKACTIVE) {
|
||||||
App::wnd()->setInactivePress(true);
|
_window->setInactivePress(true);
|
||||||
}
|
}
|
||||||
if (LOWORD(wParam) != WA_INACTIVE) {
|
if (LOWORD(wParam) != WA_INACTIVE) {
|
||||||
App::wnd()->shadowsActivate();
|
_window->shadowsActivate();
|
||||||
} else {
|
} else {
|
||||||
App::wnd()->shadowsDeactivate();
|
_window->shadowsDeactivate();
|
||||||
}
|
}
|
||||||
if (Global::started()) {
|
if (Global::started()) {
|
||||||
App::wnd()->update();
|
_window->update();
|
||||||
}
|
}
|
||||||
} return false;
|
} return false;
|
||||||
|
|
||||||
|
@ -141,42 +157,40 @@ bool EventFilter::mainWindowEvent(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lPa
|
||||||
WINDOWPLACEMENT wp;
|
WINDOWPLACEMENT wp;
|
||||||
wp.length = sizeof(WINDOWPLACEMENT);
|
wp.length = sizeof(WINDOWPLACEMENT);
|
||||||
if (GetWindowPlacement(hWnd, &wp) && (wp.showCmd == SW_SHOWMAXIMIZED || wp.showCmd == SW_SHOWMINIMIZED)) {
|
if (GetWindowPlacement(hWnd, &wp) && (wp.showCmd == SW_SHOWMAXIMIZED || wp.showCmd == SW_SHOWMINIMIZED)) {
|
||||||
App::wnd()->shadowsUpdate(ShadowsChange::Hidden);
|
_window->shadowsUpdate(ShadowsChange::Hidden);
|
||||||
} else {
|
} else {
|
||||||
App::wnd()->shadowsUpdate(ShadowsChange::Moved | ShadowsChange::Resized, (WINDOWPOS*)lParam);
|
_window->shadowsUpdate(ShadowsChange::Moved | ShadowsChange::Resized, (WINDOWPOS*)lParam);
|
||||||
}
|
}
|
||||||
} return false;
|
} return false;
|
||||||
|
|
||||||
case WM_SIZE: {
|
case WM_SIZE: {
|
||||||
if (App::wnd()) {
|
if (wParam == SIZE_MAXIMIZED || wParam == SIZE_RESTORED || wParam == SIZE_MINIMIZED) {
|
||||||
if (wParam == SIZE_MAXIMIZED || wParam == SIZE_RESTORED || wParam == SIZE_MINIMIZED) {
|
if (wParam != SIZE_RESTORED || _window->windowState() != Qt::WindowNoState) {
|
||||||
if (wParam != SIZE_RESTORED || App::wnd()->windowState() != Qt::WindowNoState) {
|
Qt::WindowState state = Qt::WindowNoState;
|
||||||
Qt::WindowState state = Qt::WindowNoState;
|
if (wParam == SIZE_MAXIMIZED) {
|
||||||
if (wParam == SIZE_MAXIMIZED) {
|
state = Qt::WindowMaximized;
|
||||||
state = Qt::WindowMaximized;
|
} else if (wParam == SIZE_MINIMIZED) {
|
||||||
} else if (wParam == SIZE_MINIMIZED) {
|
state = Qt::WindowMinimized;
|
||||||
state = Qt::WindowMinimized;
|
|
||||||
}
|
|
||||||
emit App::wnd()->windowHandle()->windowStateChanged(state);
|
|
||||||
} else {
|
|
||||||
App::wnd()->positionUpdated();
|
|
||||||
}
|
}
|
||||||
App::wnd()->psUpdateMargins();
|
emit _window->windowHandle()->windowStateChanged(state);
|
||||||
MainWindow::ShadowsChanges changes = (wParam == SIZE_MINIMIZED || wParam == SIZE_MAXIMIZED) ? ShadowsChange::Hidden : (ShadowsChange::Resized | ShadowsChange::Shown);
|
} else {
|
||||||
App::wnd()->shadowsUpdate(changes);
|
_window->positionUpdated();
|
||||||
}
|
}
|
||||||
|
_window->psUpdateMargins();
|
||||||
|
MainWindow::ShadowsChanges changes = (wParam == SIZE_MINIMIZED || wParam == SIZE_MAXIMIZED) ? ShadowsChange::Hidden : (ShadowsChange::Resized | ShadowsChange::Shown);
|
||||||
|
_window->shadowsUpdate(changes);
|
||||||
}
|
}
|
||||||
} return false;
|
} return false;
|
||||||
|
|
||||||
case WM_SHOWWINDOW: {
|
case WM_SHOWWINDOW: {
|
||||||
LONG style = GetWindowLong(hWnd, GWL_STYLE);
|
LONG style = GetWindowLong(hWnd, GWL_STYLE);
|
||||||
auto changes = ShadowsChange::Resized | ((wParam && !(style & (WS_MAXIMIZE | WS_MINIMIZE))) ? ShadowsChange::Shown : ShadowsChange::Hidden);
|
auto changes = ShadowsChange::Resized | ((wParam && !(style & (WS_MAXIMIZE | WS_MINIMIZE))) ? ShadowsChange::Shown : ShadowsChange::Hidden);
|
||||||
App::wnd()->shadowsUpdate(changes);
|
_window->shadowsUpdate(changes);
|
||||||
} return false;
|
} return false;
|
||||||
|
|
||||||
case WM_MOVE: {
|
case WM_MOVE: {
|
||||||
App::wnd()->shadowsUpdate(ShadowsChange::Moved);
|
_window->shadowsUpdate(ShadowsChange::Moved);
|
||||||
App::wnd()->positionUpdated();
|
_window->positionUpdated();
|
||||||
} return false;
|
} return false;
|
||||||
|
|
||||||
case WM_NCHITTEST: {
|
case WM_NCHITTEST: {
|
||||||
|
@ -185,7 +199,7 @@ bool EventFilter::mainWindowEvent(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lPa
|
||||||
POINTS p = MAKEPOINTS(lParam);
|
POINTS p = MAKEPOINTS(lParam);
|
||||||
RECT r;
|
RECT r;
|
||||||
GetWindowRect(hWnd, &r);
|
GetWindowRect(hWnd, &r);
|
||||||
auto res = App::wnd()->hitTest(QPoint(p.x - r.left + App::wnd()->deltaLeft(), p.y - r.top + App::wnd()->deltaTop()));
|
auto res = _window->hitTest(QPoint(p.x - r.left + _window->deltaLeft(), p.y - r.top + _window->deltaTop()));
|
||||||
switch (res) {
|
switch (res) {
|
||||||
case Window::HitTestResult::Client:
|
case Window::HitTestResult::Client:
|
||||||
case Window::HitTestResult::SysButton: *result = HTCLIENT; break;
|
case Window::HitTestResult::SysButton: *result = HTCLIENT; break;
|
||||||
|
@ -210,8 +224,8 @@ bool EventFilter::mainWindowEvent(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lPa
|
||||||
case WM_SYSCOMMAND: {
|
case WM_SYSCOMMAND: {
|
||||||
if (wParam == SC_MOUSEMENU) {
|
if (wParam == SC_MOUSEMENU) {
|
||||||
POINTS p = MAKEPOINTS(lParam);
|
POINTS p = MAKEPOINTS(lParam);
|
||||||
App::wnd()->updateSystemMenu(App::wnd()->windowHandle()->windowState());
|
_window->updateSystemMenu(_window->windowHandle()->windowState());
|
||||||
TrackPopupMenu(App::wnd()->psMenu(), TPM_LEFTALIGN | TPM_TOPALIGN | TPM_LEFTBUTTON, p.x, p.y, 0, hWnd, 0);
|
TrackPopupMenu(_window->psMenu(), TPM_LEFTALIGN | TPM_TOPALIGN | TPM_LEFTBUTTON, p.x, p.y, 0, hWnd, 0);
|
||||||
}
|
}
|
||||||
} return false;
|
} return false;
|
||||||
|
|
||||||
|
@ -219,10 +233,10 @@ bool EventFilter::mainWindowEvent(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lPa
|
||||||
if (HIWORD(wParam)) return false;
|
if (HIWORD(wParam)) return false;
|
||||||
int cmd = LOWORD(wParam);
|
int cmd = LOWORD(wParam);
|
||||||
switch (cmd) {
|
switch (cmd) {
|
||||||
case SC_CLOSE: App::wnd()->close(); return true;
|
case SC_CLOSE: _window->close(); return true;
|
||||||
case SC_MINIMIZE: App::wnd()->setWindowState(Qt::WindowMinimized); return true;
|
case SC_MINIMIZE: _window->setWindowState(Qt::WindowMinimized); return true;
|
||||||
case SC_MAXIMIZE: App::wnd()->setWindowState(Qt::WindowMaximized); return true;
|
case SC_MAXIMIZE: _window->setWindowState(Qt::WindowMaximized); return true;
|
||||||
case SC_RESTORE: App::wnd()->setWindowState(Qt::WindowNoState); return true;
|
case SC_RESTORE: _window->setWindowState(Qt::WindowNoState); return true;
|
||||||
}
|
}
|
||||||
} return true;
|
} return true;
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
|
|
||||||
namespace Platform {
|
namespace Platform {
|
||||||
|
|
||||||
|
class MainWindow;
|
||||||
|
|
||||||
class EventFilter : public QAbstractNativeEventFilter {
|
class EventFilter : public QAbstractNativeEventFilter {
|
||||||
public:
|
public:
|
||||||
bool nativeEventFilter(const QByteArray &eventType, void *message, long *result);
|
bool nativeEventFilter(const QByteArray &eventType, void *message, long *result);
|
||||||
|
@ -23,14 +25,14 @@ public:
|
||||||
_sessionLoggedOff = loggedOff;
|
_sessionLoggedOff = loggedOff;
|
||||||
}
|
}
|
||||||
|
|
||||||
static EventFilter *createInstance();
|
static EventFilter *CreateInstance(not_null<MainWindow*> window);
|
||||||
static EventFilter *getInstance();
|
static EventFilter *GetInstance();
|
||||||
static void destroy();
|
static void Destroy();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
EventFilter() {
|
explicit EventFilter(not_null<MainWindow*> window);
|
||||||
}
|
|
||||||
|
|
||||||
|
not_null<MainWindow*> _window;
|
||||||
bool _sessionLoggedOff = false;
|
bool _sessionLoggedOff = false;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue