| 1 |
// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd. |
| 2 |
// |
| 3 |
// SPDX-License-Identifier: LGPL-3.0-or-later |
| 4 |
|
| 5 |
#ifndef DPLATFORMHANDLE_H |
| 6 |
#define DPLATFORMHANDLE_H |
| 7 |
|
| 8 |
#include <dtkgui_global.h> |
| 9 |
|
| 10 |
#include <QObject> |
| 11 |
#include <QPainterPath> |
| 12 |
#include <QColor> |
| 13 |
#include <QRegion> |
| 14 |
|
| 15 |
#include <functional> |
| 16 |
|
| 17 |
QT_BEGIN_NAMESPACE |
| 18 |
class QWindow; |
| 19 |
QT_END_NAMESPACE |
| 20 |
|
| 21 |
DGUI_BEGIN_NAMESPACE |
| 22 |
// TODO: class DPlatformHandle will be removed in the future |
| 23 |
class DPlatformHandle : public QObject |
| 24 |
{ |
| 25 |
Q_OBJECT |
| 26 |
|
| 27 |
Q_PROPERTY(int windowRadius READ windowRadius WRITE setWindowRadius NOTIFY windowRadiusChanged) |
| 28 |
Q_PROPERTY(int borderWidth READ borderWidth WRITE setBorderWidth NOTIFY borderWidthChanged) |
| 29 |
Q_PROPERTY(QColor borderColor READ borderColor WRITE setBorderColor NOTIFY borderColorChanged) |
| 30 |
Q_PROPERTY(int shadowRadius READ shadowRadius WRITE setShadowRadius NOTIFY shadowRadiusChanged) |
| 31 |
Q_PROPERTY(QPoint shadowOffset READ shadowOffset WRITE setShadowOffset NOTIFY shadowOffsetChanged) |
| 32 |
Q_PROPERTY(QColor shadowColor READ shadowColor WRITE setShadowColor NOTIFY shadowColorChanged) |
| 33 |
Q_PROPERTY(EffectScene windowEffect READ windowEffect WRITE setWindowEffect NOTIFY windowEffectChanged) |
| 34 |
Q_PROPERTY(EffectType windowStartUpEffect READ windowStartUpEffect WRITE setWindowStartUpEffect NOTIFY windowStartUpEffectChanged) |
| 35 |
Q_PROPERTY(QPainterPath clipPath READ clipPath WRITE setClipPath NOTIFY clipPathChanged) |
| 36 |
Q_PROPERTY(QRegion frameMask READ frameMask WRITE setFrameMask NOTIFY frameMaskChanged) |
| 37 |
Q_PROPERTY(QMargins frameMargins READ frameMargins NOTIFY frameMarginsChanged) |
| 38 |
Q_PROPERTY(bool translucentBackground READ translucentBackground WRITE setTranslucentBackground NOTIFY translucentBackgroundChanged) |
| 39 |
Q_PROPERTY(bool enableSystemResize READ enableSystemResize WRITE setEnableSystemResize NOTIFY enableSystemResizeChanged) |
| 40 |
Q_PROPERTY(bool enableSystemMove READ enableSystemMove WRITE setEnableSystemMove NOTIFY enableSystemMoveChanged) |
| 41 |
Q_PROPERTY(bool enableBlurWindow READ enableBlurWindow WRITE setEnableBlurWindow NOTIFY enableBlurWindowChanged) |
| 42 |
Q_PROPERTY(bool autoInputMaskByClipPath READ autoInputMaskByClipPath WRITE setAutoInputMaskByClipPath NOTIFY autoInputMaskByClipPathChanged) |
| 43 |
Q_PROPERTY(WId realWindowId READ realWindowId CONSTANT) |
| 44 |
|
| 45 |
public: |
| 46 |
explicit DPlatformHandle(QWindow *window, QObject *parent = 0); |
| 47 |
~DPlatformHandle(); |
| 48 |
|
| 49 |
static QString pluginVersion(); |
| 50 |
static bool isDXcbPlatform(); |
| 51 |
|
| 52 |
static void enableDXcbForWindow(QWindow *window); |
| 53 |
static void enableDXcbForWindow(QWindow *window, bool redirectContent); |
| 54 |
static bool isEnabledDXcb(const QWindow *window); |
| 55 |
|
| 56 |
static bool setEnabledNoTitlebarForWindow(QWindow *window, bool enable); |
| 57 |
static bool isEnabledNoTitlebar(const QWindow *window); |
| 58 |
|
| 59 |
struct WMBlurArea { |
| 60 |
qint32 x = 0; |
| 61 |
qint32 y = 0; |
| 62 |
qint32 width = 0; |
| 63 |
qint32 height = 0; |
| 64 |
qint32 xRadius = 0; |
| 65 |
qint32 yRaduis = 0; |
| 66 |
}; |
| 67 |
|
| 68 |
enum WallpaperScaleMode { |
| 69 |
FollowScreen = 0x00000000, |
| 70 |
FollowWindow = 0x00010000 |
| 71 |
}; |
| 72 |
|
| 73 |
enum WallpaperFillMode { |
| 74 |
PreserveAspectCrop = 0x00000000, |
| 75 |
PreserveAspectFit = 0x00000001 |
| 76 |
}; |
| 77 |
|
| 78 |
enum EffectScene { |
| 79 |
EffectNoRadius = 0x01, // 取消窗口圆角 |
| 80 |
EffectNoShadow = 0x02, // 取消窗口阴影 |
| 81 |
EffectNoBorder = 0x04, // 取消窗口边框 |
| 82 |
EffectNoStart = 0x10, // 取消启动场景动效 |
| 83 |
EffectNoClose = 0x20, // 取消关闭场景动效 |
| 84 |
EffectNoMaximize = 0x40, // 取消最大化场景动效 |
| 85 |
EffectNoMinimize = 0x80 // 取消最小化场景动效 |
| 86 |
}; |
| 87 |
|
| 88 |
enum EffectType { |
| 89 |
EffectNormal = 0x01, // 标准缩放动效 |
| 90 |
EffectCursor = 0x02, // 鼠标位置展开动效 |
| 91 |
EffectTop = 0x04, // 从上往下展开 |
| 92 |
EffectBottom = 0x08, // 从下往上展开 |
| 93 |
EffectOut = 0x10 // 由外向内 |
| 94 |
}; |
| 95 |
|
| 96 |
Q_ENUM(EffectScene) |
| 97 |
Q_ENUM(EffectType) |
| 98 |
Q_DECLARE_FLAGS(EffectScenes, EffectScene) |
| 99 |
Q_DECLARE_FLAGS(EffectTypes, EffectType) |
| 100 |
Q_ENUM(EffectScenes) |
| 101 |
Q_ENUM(EffectTypes) |
| 102 |
|
| 103 |
static bool setWindowBlurAreaByWM(QWindow *window, const QVector<WMBlurArea> &area); |
| 104 |
static bool setWindowBlurAreaByWM(QWindow *window, const QList<QPainterPath> &paths); |
| 105 |
static bool setWindowWallpaperParaByWM(QWindow *window, const QRect &area, WallpaperScaleMode sMode, WallpaperFillMode fMode); |
| 106 |
static bool connectWindowManagerChangedSignal(QObject *object, std::function<void ()> slot); |
| 107 |
static bool connectHasBlurWindowChanged(QObject *object, std::function<void ()> slot); |
| 108 |
|
| 109 |
bool setWindowBlurAreaByWM(const QVector<WMBlurArea> &area); |
| 110 |
bool setWindowBlurAreaByWM(const QList<QPainterPath> &paths); |
| 111 |
|
| 112 |
static void setDisableWindowOverrideCursor(QWindow *window, bool disable); |
| 113 |
|
| 114 |
int windowRadius() const; |
| 115 |
|
| 116 |
int borderWidth() const; |
| 117 |
QColor borderColor() const; |
| 118 |
|
| 119 |
int shadowRadius() const; |
| 120 |
QPoint shadowOffset() const; |
| 121 |
QColor shadowColor() const; |
| 122 |
|
| 123 |
EffectScene windowEffect(); |
| 124 |
EffectType windowStartUpEffect(); |
| 125 |
|
| 126 |
QPainterPath clipPath() const; |
| 127 |
QRegion frameMask() const; |
| 128 |
QMargins frameMargins() const; |
| 129 |
|
| 130 |
bool translucentBackground() const; |
| 131 |
bool enableSystemResize() const; |
| 132 |
bool enableSystemMove() const; |
| 133 |
bool enableBlurWindow() const; |
| 134 |
bool autoInputMaskByClipPath() const; |
| 135 |
|
| 136 |
WId realWindowId() const; |
| 137 |
static WId windowLeader(); |
| 138 |
|
| 139 |
public Q_SLOTS: |
| 140 |
void setWindowRadius(int windowRadius); |
| 141 |
void setBorderWidth(int borderWidth); |
| 142 |
void setBorderColor(const QColor &borderColor); |
| 143 |
|
| 144 |
void setWindowEffect(EffectScenes effectScene); |
| 145 |
void setWindowStartUpEffect(EffectTypes effectType); |
| 146 |
|
| 147 |
void setShadowRadius(int shadowRadius); |
| 148 |
void setShadowOffset(const QPoint &shadowOffset); |
| 149 |
void setShadowColor(const QColor &shadowColor); |
| 150 |
|
| 151 |
void setClipPath(const QPainterPath &clipPath); |
| 152 |
void setFrameMask(const QRegion &frameMask); |
| 153 |
|
| 154 |
void setTranslucentBackground(bool translucentBackground); |
| 155 |
void setEnableSystemResize(bool enableSystemResize); |
| 156 |
void setEnableSystemMove(bool enableSystemMove); |
| 157 |
void setEnableBlurWindow(bool enableBlurWindow); |
| 158 |
void setAutoInputMaskByClipPath(bool autoInputMaskByClipPath); |
| 159 |
|
| 160 |
Q_SIGNALS: |
| 161 |
void frameMarginsChanged(); |
| 162 |
void windowRadiusChanged(); |
| 163 |
void borderWidthChanged(); |
| 164 |
void borderColorChanged(); |
| 165 |
void shadowRadiusChanged(); |
| 166 |
void shadowOffsetChanged(); |
| 167 |
void shadowColorChanged(); |
| 168 |
void windowEffectChanged(); |
| 169 |
void windowStartUpEffectChanged(); |
| 170 |
void clipPathChanged(); |
| 171 |
void frameMaskChanged(); |
| 172 |
void translucentBackgroundChanged(); |
| 173 |
void enableSystemResizeChanged(); |
| 174 |
void enableSystemMoveChanged(); |
| 175 |
void enableBlurWindowChanged(); |
| 176 |
void autoInputMaskByClipPathChanged(); |
| 177 |
|
| 178 |
protected: |
| 179 |
bool eventFilter(QObject *obj, QEvent *event) Q_DECL_OVERRIDE; |
| 180 |
|
| 181 |
private: |
| 182 |
QWindow *m_window; |
| 183 |
}; |
| 184 |
|
| 185 |
inline DPlatformHandle::WMBlurArea dMakeWMBlurArea(quint32 x, quint32 y, quint32 width, quint32 height, quint32 xr = 0, quint32 yr = 0) |
| 186 |
{ |
| 187 |
DPlatformHandle::WMBlurArea a; |
| 188 |
|
| 189 |
a.x = x; |
| 190 |
a.y = y; |
| 191 |
a.width = width; |
| 192 |
a.height = height; |
| 193 |
a.xRadius = xr; |
| 194 |
a.yRaduis = yr; |
| 195 |
|
| 196 |
return a; |
| 197 |
} |
| 198 |
|
| 199 |
DGUI_END_NAMESPACE |
| 200 |
|
| 201 |
QT_BEGIN_NAMESPACE |
| 202 |
DGUI_USE_NAMESPACE |
| 203 |
QDebug operator<<(QDebug deg, const DPlatformHandle::WMBlurArea &area); |
| 204 |
QT_END_NAMESPACE |
| 205 |
|
| 206 |
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) |
| 207 |
Q_DECLARE_METATYPE(QPainterPath) |
| 208 |
Q_DECLARE_METATYPE(QMargins) |
| 209 |
#endif |
| 210 |
Q_DECLARE_METATYPE(QRegion) |
| 211 |
Q_DECLARE_OPERATORS_FOR_FLAGS(DPlatformHandle::EffectScenes) |
| 212 |
Q_DECLARE_OPERATORS_FOR_FLAGS(DPlatformHandle::EffectTypes) |
| 213 |
|
| 214 |
#endif // DPLATFORMHANDLE_H |