| | |
| | | } |
| | | |
| | | static inline void triggerFrameChange(HWND hwnd) { |
| | | Q_ASSERT(hwnd); |
| | | if (!hwnd) { |
| | | return; |
| | | } |
| | | ::SetWindowPos(hwnd, nullptr, 0, 0, 0, 0, |
| | | SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOOWNERZORDER | |
| | | SWP_FRAMECHANGED); |
| | | } |
| | | |
| | | static inline quint32 getDpiForWindow(HWND hwnd) { |
| | | Q_ASSERT(hwnd); |
| | | if (!hwnd) { |
| | | return 0; |
| | | } |
| | | const DynamicApis &apis = DynamicApis::instance(); |
| | | if (apis.pGetDpiForWindow) { // Win10 |
| | | return apis.pGetDpiForWindow(hwnd); |
| | |
| | | } |
| | | |
| | | static inline quint32 getResizeBorderThickness(HWND hwnd) { |
| | | Q_ASSERT(hwnd); |
| | | if (!hwnd) { |
| | | return 0; |
| | | } |
| | | const DynamicApis &apis = DynamicApis::instance(); |
| | | if (apis.pGetSystemMetricsForDpi) { |
| | | const quint32 dpi = getDpiForWindow(hwnd); |
| | |
| | | } |
| | | |
| | | static inline quint32 getTitleBarHeight(HWND hwnd) { |
| | | Q_ASSERT(hwnd); |
| | | if (!hwnd) { |
| | | return 0; |
| | | } |
| | | const auto captionHeight = [hwnd]() -> int { |
| | | const DynamicApis &apis = DynamicApis::instance(); |
| | | if (apis.pGetSystemMetricsForDpi) { |
| | |
| | | } |
| | | |
| | | static inline void updateInternalWindowFrameMargins(HWND hwnd, QWindow *window) { |
| | | Q_ASSERT(hwnd); |
| | | Q_ASSERT(window); |
| | | if (!hwnd || !window) { |
| | | return; |
| | | } |
| | | const auto margins = [hwnd]() -> QMargins { |
| | | const int titleBarHeight = getTitleBarHeight(hwnd); |
| | | if (isWin10OrGreater()) { |
| | |
| | | } |
| | | |
| | | static inline MONITORINFOEXW getMonitorForWindow(HWND hwnd) { |
| | | Q_ASSERT(hwnd); |
| | | if (!hwnd) { |
| | | return {}; |
| | | } |
| | | // Use "MONITOR_DEFAULTTONEAREST" here so that we can still get the correct |
| | | // monitor even if the window is minimized. |
| | | HMONITOR monitor = ::MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST); |
| | |
| | | }; |
| | | |
| | | static inline void moveToDesktopCenter(HWND hwnd) { |
| | | Q_ASSERT(hwnd); |
| | | if (!hwnd) { |
| | | return; |
| | | } |
| | | const auto monitorInfo = getMonitorForWindow(hwnd); |
| | | RECT windowRect{}; |
| | | ::GetWindowRect(hwnd, &windowRect); |
| | | const auto newX = (RECT_WIDTH(monitorInfo.rcMonitor) - RECT_WIDTH(windowRect)) / 2; |
| | | const auto newY = (RECT_HEIGHT(monitorInfo.rcMonitor) - RECT_HEIGHT(windowRect)) / 2; |
| | | ::SetWindowPos(hwnd, nullptr, newX, newY, 0, 0, SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOOWNERZORDER); |
| | | ::SetWindowPos(hwnd, nullptr, newX, newY, 0, 0, |
| | | SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOOWNERZORDER); |
| | | } |
| | | |
| | | static inline bool isFullScreen(HWND hwnd) { |
| | |
| | | return ::CallWindowProcW(g_qtWindowProc, hWnd, message, wParam, lParam); |
| | | } |
| | | |
| | | Win32WindowContext::Win32WindowContext(QObject *host, WindowItemDelegate *delegate) |
| | | : AbstractWindowContext(host, delegate) { |
| | | Win32WindowContext::Win32WindowContext() : AbstractWindowContext() { |
| | | } |
| | | |
| | | Win32WindowContext::~Win32WindowContext() { |
| | |
| | | } |
| | | } |
| | | |
| | | bool Win32WindowContext::setup() { |
| | | if (!m_windowHandle) { |
| | | bool Win32WindowContext::setup(QObject *host, WindowItemDelegate *delegate) { |
| | | if (!AbstractWindowContext::setup(host, delegate)) { |
| | | return false; |
| | | } |
| | | |
| | |
| | | case WM_SHOWWINDOW: { |
| | | if (!centered) { |
| | | // If wParam is TRUE, the window is being shown. |
| | | // If lParam is zero, the message was sent because of a call to the ShowWindow function. |
| | | // If lParam is zero, the message was sent because of a call to the ShowWindow |
| | | // function. |
| | | if (wParam && lParam == 0) { |
| | | centered = true; |
| | | moveToDesktopCenter(hWnd); |
| | |
| | | // and align it with the upper-left corner of our new client area". |
| | | const auto clientRect = |
| | | wParam ? &(reinterpret_cast<LPNCCALCSIZE_PARAMS>(lParam))->rgrc[0] |
| | | : reinterpret_cast<LPRECT>(lParam); |
| | | : reinterpret_cast<LPRECT>(lParam); |
| | | if (isWin10OrGreater()) { |
| | | // Store the original top margin before the default window procedure applies the |
| | | // default frame. |
| | |
| | | break; |
| | | case CoreWindowAgent::Close: |
| | | *result = HTCLOSE; |
| | | break; |
| | | case CoreWindowAgent::Unknown: |
| | | break; |
| | | default: |
| | | break; // unreachable |