KDDockWidgets API Documentation 2.0
Loading...
Searching...
No Matches
CustomFrameHelper.cpp
Go to the documentation of this file.
1/*
2 This file is part of KDDockWidgets.
3
4 SPDX-FileCopyrightText: 2019 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
5 Author: SĂ©rgio Martins <sergio.martins@kdab.com>
6
7 SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only
8
9 Contact KDAB at <info@kdab.com> for commercial licensing options.
10*/
11
12#include "CustomFrameHelper_p.h"
13#include "core/Logging_p.h"
14#include "core/ScopedValueRollback_p.h"
15#include "core/Utils_p.h"
16#include "core/Window_p.h"
17#include "qtcommon/Window_p.h"
18
19#include <QGuiApplication>
20
21using namespace KDDockWidgets;
22using namespace KDDockWidgets::Core;
23
24#ifdef KDDW_FRONTEND_QT_WINDOWS
25namespace KDDockWidgets {
26Window::Ptr windowForHandle(WId id)
27{
28 const Window::List windows = Platform::instance()->windows();
29 for (Core::Window::Ptr w : windows) {
30 if (w->isVisible() && w->handle() == id) {
31 return w;
32 }
33 }
34 return nullptr;
35}
36}
37#endif
38
39CustomFrameHelper::CustomFrameHelper(ShouldUseCustomFrame func, QObject *parent)
40 : QObject(parent)
41 , m_shouldUseCustomFrameFunc(func)
42{
43#if defined(KDDW_FRONTEND_QT_WINDOWS)
44 qGuiApp->installNativeEventFilter(this);
45#endif
46}
47
48CustomFrameHelper::~CustomFrameHelper()
49{
50 m_inDtor = true;
51}
52
53void CustomFrameHelper::applyCustomFrame(Core::Window::Ptr window)
54{
55#ifdef KDDW_FRONTEND_QT_WINDOWS
56 WidgetResizeHandler::setupWindow(window);
57#else
58 KDDW_UNUSED(window);
59 KDDW_ERROR("Not implemented on this platform");
60#endif
61}
62
63bool CustomFrameHelper::nativeEventFilter(const QByteArray &eventType, void *message,
64 Qt5Qt6Compat::qintptr *result)
65{
66 if (m_shouldUseCustomFrameFunc == nullptr || m_recursionGuard)
67 return false;
68
69 ScopedValueRollback guard(m_recursionGuard, true);
70
71#ifdef KDDW_FRONTEND_QT_WINDOWS
72 if (m_inDtor || !KDDockWidgets::usesAeroSnapWithCustomDecos())
73 return false;
74
75 if (eventType != "windows_generic_MSG")
76 return false;
77
78 auto msg = static_cast<MSG *>(message);
79 if (!WidgetResizeHandler::isInterestingNativeEvent(msg->message)) {
80 // Save some CPU cycles
81 return false;
82 }
83
84 Window::Ptr window = KDDockWidgets::windowForHandle(WId(msg->hwnd));
85 if (!window)
86 return false;
87
88 const WidgetResizeHandler::NativeFeatures features = m_shouldUseCustomFrameFunc(window);
89 if (!features.hasFeatures()) {
90 // No native support for is desired for this window
91 return false;
92 }
93
94 const char *propertyName = "kddw_customframe_setup_ran";
95 auto windowQt = static_cast<QtCommon::Window *>(window.get());
96 const bool setupRan = windowQt->property(propertyName).toBool();
97 if (!setupRan) {
98 // Add drop shadow
99 WidgetResizeHandler::setupWindow(window);
100 windowQt->setProperty(propertyName, true);
101 }
102
103 return WidgetResizeHandler::handleWindowsNativeEvent(window, msg, result, features);
104#else
105 KDDW_UNUSED(eventType);
106 KDDW_UNUSED(message);
107 KDDW_UNUSED(result);
108 return false;
109#endif
110}
#define KDDW_UNUSED(name)
virtual Vector< std::shared_ptr< Core::Window > > windows() const =0
Returns all windows.
static Platform * instance()
Returns the platform singleton.
Class to abstract QAction, so code still works with QtQuick and Flutter.

© Klarälvdalens Datakonsult AB (KDAB)
"The Qt, C++ and OpenGL Experts"
https://www.kdab.com/
KDDockWidgets
Advanced Dock Widget Framework for Qt
https://www.kdab.com/development-resources/qt-tools/kddockwidgets/
Generated by doxygen 1.9.8