CustomFrame: Allow to specify a callback for QWindow opt-in
Which QWindows should get a custom frame is up to you. Just return true in the callback.
This commit is contained in:
@@ -561,9 +561,10 @@ bool NCHITTESTEventFilter::nativeEventFilter(const QByteArray &eventType, void *
|
||||
#endif
|
||||
|
||||
|
||||
CustomFrameHelper::CustomFrameHelper(QObject *parent)
|
||||
CustomFrameHelper::CustomFrameHelper(ShouldUseCustomFrame func, QObject *parent)
|
||||
: QObject(parent)
|
||||
, QAbstractNativeEventFilter()
|
||||
, m_shouldUseCustomFrameFunc(func)
|
||||
{
|
||||
#ifdef Q_OS_WIN
|
||||
qApp->installNativeEventFilter(this);
|
||||
@@ -588,6 +589,9 @@ void CustomFrameHelper::applyCustomFrame(QWindow *window)
|
||||
bool CustomFrameHelper::nativeEventFilter(const QByteArray &eventType, void *message,
|
||||
Qt5Qt6Compat::qintptr *result)
|
||||
{
|
||||
if (m_shouldUseCustomFrameFunc == nullptr)
|
||||
return false;
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
if (m_inDtor || !KDDockWidgets::usesAeroSnapWithCustomDecos())
|
||||
return false;
|
||||
@@ -598,7 +602,7 @@ bool CustomFrameHelper::nativeEventFilter(const QByteArray &eventType, void *mes
|
||||
auto msg = static_cast<MSG *>(message);
|
||||
|
||||
QWindow *window = QWindow::fromWinId(WId(msg->hwnd));
|
||||
if (!window)
|
||||
if (!window || !m_shouldUseCustomFrameFunc(window))
|
||||
return false;
|
||||
|
||||
const char *propertyName = "kddw_customframe_setup_ran";
|
||||
|
||||
@@ -124,13 +124,16 @@ public:
|
||||
|
||||
#endif // Q_OS_WIN
|
||||
|
||||
typedef bool (*ShouldUseCustomFrame)(QWindow *);
|
||||
|
||||
class DOCKS_EXPORT CustomFrameHelper
|
||||
: public QObject
|
||||
, public QAbstractNativeEventFilter
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit CustomFrameHelper(QObject *parent = nullptr);
|
||||
explicit CustomFrameHelper(ShouldUseCustomFrame shouldUseCustomFrameFunc,
|
||||
QObject *parent = nullptr);
|
||||
~CustomFrameHelper() override;
|
||||
|
||||
public Q_SLOTS:
|
||||
@@ -142,6 +145,7 @@ protected:
|
||||
|
||||
private:
|
||||
bool m_inDtor = false;
|
||||
ShouldUseCustomFrame m_shouldUseCustomFrameFunc = nullptr;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user