Skip to content

Commit

Permalink
feat: support to change window effects
Browse files Browse the repository at this point in the history
  • Loading branch information
Whale107 authored and 18202781743 committed Aug 13, 2024
1 parent 1ffd986 commit 820e303
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
37 changes: 36 additions & 1 deletion include/kernel/dplatformhandle.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ class DPlatformHandle : public QObject
Q_PROPERTY(int shadowRadius READ shadowRadius WRITE setShadowRadius NOTIFY shadowRadiusChanged)
Q_PROPERTY(QPoint shadowOffset READ shadowOffset WRITE setShadowOffset NOTIFY shadowOffsetChanged)
Q_PROPERTY(QColor shadowColor READ shadowColor WRITE setShadowColor NOTIFY shadowColorChanged)
Q_PROPERTY(EffectScene windowEffect READ windowEffect WRITE setWindowEffect NOTIFY windowEffectChanged)
Q_PROPERTY(EffectType windowStartUpEffect READ windowStartUpEffect WRITE setWindowStartUpEffect NOTIFY windowStartUpEffectChanged)
Q_PROPERTY(QPainterPath clipPath READ clipPath WRITE setClipPath NOTIFY clipPathChanged)
Q_PROPERTY(QRegion frameMask READ frameMask WRITE setFrameMask NOTIFY frameMaskChanged)
Q_PROPERTY(QMargins frameMargins READ frameMargins NOTIFY frameMarginsChanged)
Expand Down Expand Up @@ -72,6 +74,30 @@ class DPlatformHandle : public QObject
PreserveAspectFit = 0x00000001
};

enum EffectScene {
EffectNoRadius = 0x01, // 取消窗口圆角
EffectNoShadow = 0x02, // 取消窗口阴影
EffectNoBorder = 0x04, // 取消窗口边框
EffectNoStart = 0x10, // 取消启动场景动效
EffectNoClose = 0x20, // 取消关闭场景动效
EffectNoMaximize = 0x40, // 取消最大化场景动效
EffectNoMinimize = 0x80 // 取消最小化场景动效
};

enum EffectType {
EffectNormal = 0x01, // 标准缩放动效
EffectCursor = 0x02, // 鼠标位置展开动效
EffectTop = 0x04, // 从上往下展开
EffectBottom = 0x08 // 从下往上展开
};

Q_ENUM(EffectScene)
Q_ENUM(EffectType)
Q_DECLARE_FLAGS(EffectScenes, EffectScene)
Q_DECLARE_FLAGS(EffectTypes, EffectType)
Q_ENUM(EffectScenes)
Q_ENUM(EffectTypes)

static bool setWindowBlurAreaByWM(QWindow *window, const QVector<WMBlurArea> &area);
static bool setWindowBlurAreaByWM(QWindow *window, const QList<QPainterPath> &paths);
static bool setWindowWallpaperParaByWM(QWindow *window, const QRect &area, WallpaperScaleMode sMode, WallpaperFillMode fMode);
Expand All @@ -92,6 +118,9 @@ class DPlatformHandle : public QObject
QPoint shadowOffset() const;
QColor shadowColor() const;

EffectScene windowEffect();
EffectType windowStartUpEffect();

QPainterPath clipPath() const;
QRegion frameMask() const;
QMargins frameMargins() const;
Expand All @@ -107,10 +136,12 @@ class DPlatformHandle : public QObject

public Q_SLOTS:
void setWindowRadius(int windowRadius);

void setBorderWidth(int borderWidth);
void setBorderColor(const QColor &borderColor);

void setWindowEffect(EffectScenes effectScene);
void setWindowStartUpEffect(EffectTypes effectType);

void setShadowRadius(int shadowRadius);
void setShadowOffset(const QPoint &shadowOffset);
void setShadowColor(const QColor &shadowColor);
Expand All @@ -132,6 +163,8 @@ public Q_SLOTS:
void shadowRadiusChanged();
void shadowOffsetChanged();
void shadowColorChanged();
void windowEffectChanged();
void windowStartUpEffectChanged();
void clipPathChanged();
void frameMaskChanged();
void translucentBackgroundChanged();
Expand Down Expand Up @@ -173,5 +206,7 @@ Q_DECLARE_METATYPE(QPainterPath)
Q_DECLARE_METATYPE(QMargins)
#endif
Q_DECLARE_METATYPE(QRegion)
Q_DECLARE_OPERATORS_FOR_FLAGS(DPlatformHandle::EffectScenes)
Q_DECLARE_OPERATORS_FOR_FLAGS(DPlatformHandle::EffectTypes)

#endif // DPLATFORMHANDLE_H
22 changes: 22 additions & 0 deletions src/kernel/dplatformhandle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ DEFINE_CONST_CHAR(netWmStates);
DEFINE_CONST_CHAR(windowRadius);
DEFINE_CONST_CHAR(borderWidth);
DEFINE_CONST_CHAR(borderColor);
DEFINE_CONST_CHAR(windowEffect);
DEFINE_CONST_CHAR(windowStartUpEffect);
DEFINE_CONST_CHAR(shadowRadius);
DEFINE_CONST_CHAR(shadowOffset);
DEFINE_CONST_CHAR(shadowColor);
Expand Down Expand Up @@ -1088,6 +1090,16 @@ QColor DPlatformHandle::shadowColor() const
return qvariant_cast<QColor>(m_window->property(_shadowColor));
}

DPlatformHandle::EffectScene DPlatformHandle::windowEffect()
{
return qvariant_cast<EffectScene>(m_window->property(_windowEffect));
}

DPlatformHandle::EffectType DPlatformHandle::windowStartUpEffect()
{
return qvariant_cast<EffectType>(m_window->property(_windowStartUpEffect));
}

QPainterPath DPlatformHandle::clipPath() const
{
return qvariant_cast<QPainterPath>(m_window->property(_clipPath));
Expand Down Expand Up @@ -1164,6 +1176,16 @@ void DPlatformHandle::setBorderColor(const QColor &borderColor)
setWindowProperty(m_window, _borderColor, QVariant::fromValue(borderColor));
}

void DPlatformHandle::setWindowEffect(DPlatformHandle::EffectScenes effectScene)
{
setWindowProperty(m_window, _windowEffect, static_cast<quint32>(effectScene));
}

void DPlatformHandle::setWindowStartUpEffect(DPlatformHandle::EffectTypes effectType)
{
setWindowProperty(m_window, _windowStartUpEffect, static_cast<quint32>(effectType));
}

void DPlatformHandle::setShadowRadius(int shadowRadius)
{
setWindowProperty(m_window, _shadowRadius, shadowRadius);
Expand Down

0 comments on commit 820e303

Please sign in to comment.