-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlnativeeventfilter.cpp
More file actions
52 lines (41 loc) · 1.6 KB
/
lnativeeventfilter.cpp
File metadata and controls
52 lines (41 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include "lnativeeventfilter.h"
#include "lmsghandler.h"
#include <windows.h>
LNativeEventFilter::LNativeEventFilter()
{
LMsgHandler *pMsgHandler = LMsgHandler::getInstance();
connect(pMsgHandler, &LMsgHandler::registerBorderlessWin, this, [=](quint32 wId){
_WinList.append(wId);
});
}
LNativeEventFilter::~LNativeEventFilter()
{
}
bool LNativeEventFilter::nativeEventFilter(const QByteArray &eventType, void *message, long *result)
{
Q_UNUSED(eventType)
MSG *msg = static_cast<MSG *>(message);
// this kills the window frame and title bar we added with WS_THICKFRAME or WS_CAPTION.
if (msg->message == WM_NCCALCSIZE && _WinList.contains(quint32(msg->hwnd)))
{
// Correct window rectangle recomputation
// https://github.com/telegramdesktop/tdesktop/blob/dev/Telegram/SourceFiles/platform/win/windows_event_filter.cpp
WINDOWPLACEMENT wp;
wp.length = sizeof(WINDOWPLACEMENT);
if (GetWindowPlacement(msg->hwnd, &wp) && wp.showCmd == SW_SHOWMAXIMIZED) {
LPNCCALCSIZE_PARAMS params = (LPNCCALCSIZE_PARAMS)msg->lParam;
LPRECT r = (msg->wParam == TRUE) ? ¶ms->rgrc[0] : (LPRECT)msg->lParam;
HMONITOR hMonitor = MonitorFromPoint({ (r->left + r->right) / 2, (r->top + r->bottom) / 2 }, MONITOR_DEFAULTTONEAREST);
if (hMonitor) {
MONITORINFO mi;
mi.cbSize = sizeof(mi);
if (GetMonitorInfo(hMonitor, &mi)) {
*r = mi.rcWork;
}
}
}
if (result) *result = 0;
return true;
}
return false;
}