Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sync: from linuxdeepin/dtkgui #107

Merged
merged 1 commit into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 58 additions & 54 deletions src/plugins/platform/treeland/dtreelandplatformwindowinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,15 @@ void DTreeLandPlatformWindowHelper::onActiveChanged()

void DTreeLandPlatformWindowHelper::onSurfaceCreated()
{
Q_EMIT surfaceCreated();
if (m_isNoTitlebar) {
doSetEnabledNoTitlebar();
}
if (m_radius > 0) {
doSetWindowRadius();
}
if (m_isWindowBlur) {
doSetEnabledBlurWindow();
}
}

void DTreeLandPlatformWindowHelper::onSurfaceDestroyed()
Expand Down Expand Up @@ -258,33 +266,56 @@ PersonalizationWindowContext *DTreeLandPlatformWindowHelper::windowContext() con
return m_windowContext;
}

void DTreeLandPlatformWindowHelper::setEnabledNoTitlebar(bool enable)
{
m_isNoTitlebar = enable;
doSetEnabledNoTitlebar();
}
void DTreeLandPlatformWindowHelper::setWindowRadius(int windowRadius)
{
m_radius = windowRadius;
doSetWindowRadius();
}
void DTreeLandPlatformWindowHelper::setEnableBlurWindow(bool enableBlurWindow)
{
m_isWindowBlur = enableBlurWindow;
doSetEnabledBlurWindow();
}

void DTreeLandPlatformWindowHelper::doSetEnabledNoTitlebar()
{
if (auto context = windowContext()) {
context->set_titlebar(m_isNoTitlebar ? PersonalizationWindowContext::enable_mode_disable : PersonalizationWindowContext::enable_mode_enable);
}
}

void DTreeLandPlatformWindowHelper::doSetWindowRadius()
{
if (auto context = windowContext()) {
context->set_round_corner_radius(m_radius);
}
}

void DTreeLandPlatformWindowHelper::doSetEnabledBlurWindow()
{
if (auto context = windowContext()) {
context->set_blend_mode(m_isWindowBlur ? PersonalizationWindowContext::blend_mode_blur : PersonalizationWindowContext::blend_mode_transparent);
}
}

DTreeLandPlatformWindowInterface::DTreeLandPlatformWindowInterface(QWindow *window, DPlatformHandle *platformHandle, QObject *parent)
: QObject(parent)
, DPlatformWindowInterface(window, platformHandle)
{
if (!MoveWindowHelper::mapped.value(window)) {
Q_UNUSED(new MoveWindowHelper(window))
}

if (auto helper = DTreeLandPlatformWindowHelper::get(m_window)) {
connect(helper, &DTreeLandPlatformWindowHelper::surfaceCreated, this, &DTreeLandPlatformWindowInterface::onSurfaceCreated);
}
}

DTreeLandPlatformWindowInterface::~DTreeLandPlatformWindowInterface()
{
}

void DTreeLandPlatformWindowInterface::onSurfaceCreated()
{
if (m_isNoTitlebar) {
doSetEnabledNoTitlebar();
}
if (m_isWindowBlur) {
doSetEnabledBlurWindow();
}
}

void DTreeLandPlatformWindowInterface::setEnabled(bool enabled)
{
if (setEnabledNoTitlebar(enabled)) {
Expand All @@ -308,7 +339,9 @@ bool DTreeLandPlatformWindowInterface::setEnabledNoTitlebar(bool enable)
return true;
}
m_isNoTitlebar = enable;
doSetEnabledNoTitlebar();
if (auto helper = DTreeLandPlatformWindowHelper::get(m_window)) {
helper->setEnabledNoTitlebar(enable);
}
return true;
}

Expand All @@ -323,7 +356,12 @@ void DTreeLandPlatformWindowInterface::setWindowRadius(int windowRadius)
return;
}
m_radius = windowRadius;
doSetWindowRadius();
if (auto helper = DTreeLandPlatformWindowHelper::get(m_window)) {
helper->setWindowRadius(m_radius);
}
if (m_platformHandle) {
Q_EMIT m_platformHandle->windowRadiusChanged();
}
}

bool DTreeLandPlatformWindowInterface::enableBlurWindow() const
Expand All @@ -337,45 +375,11 @@ void DTreeLandPlatformWindowInterface::setEnableBlurWindow(bool enable)
return;
}
m_isWindowBlur = enable;
doSetEnabledBlurWindow();
}

void DTreeLandPlatformWindowInterface::doSetEnabledNoTitlebar()
{
if (auto helper = DTreeLandPlatformWindowHelper::get(m_window)) {
auto context = helper->windowContext();
if (!context) {
return;
}
context->set_titlebar(m_isNoTitlebar ? PersonalizationWindowContext::enable_mode_disable : PersonalizationWindowContext::enable_mode_enable);
}
}

void DTreeLandPlatformWindowInterface::doSetWindowRadius()
{
if (auto helper = DTreeLandPlatformWindowHelper::get(m_window)) {
auto context = helper->windowContext();
if (!context) {
return;
}
context->set_round_corner_radius(m_radius);
if (m_platformHandle) {
Q_EMIT m_platformHandle->windowRadiusChanged();
}
helper->setEnableBlurWindow(enable);
}
}

void DTreeLandPlatformWindowInterface::doSetEnabledBlurWindow()
{
if (auto helper = DTreeLandPlatformWindowHelper::get(m_window)) {
auto context = helper->windowContext();
if (!context) {
return;
}
context->set_blend_mode(m_isWindowBlur ? PersonalizationWindowContext::blend_mode_blur : PersonalizationWindowContext::blend_mode_transparent);
if (m_platformHandle) {
Q_EMIT m_platformHandle->enableBlurWindowChanged();
}
if (m_platformHandle) {
Q_EMIT m_platformHandle->enableBlurWindowChanged();
}
}
DGUI_END_NAMESPACE
21 changes: 12 additions & 9 deletions src/plugins/platform/treeland/dtreelandplatformwindowinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@
QWindow *window() const { return qobject_cast<QWindow *>(parent()); }
PersonalizationWindowContext *windowContext() const;

Q_SIGNALS:
void surfaceCreated();
void setEnabledNoTitlebar(bool enable);
void setWindowRadius(int windowRadius);
void setEnableBlurWindow(bool enableBlurWindow);

private slots:

Check warning on line 29 in src/plugins/platform/treeland/dtreelandplatformwindowinterface.h

View workflow job for this annotation

GitHub Actions / cppcheck

There is an unknown macro here somewhere. Configuration is required. If slots is a macro then please configure it.
void onActiveChanged();
void onSurfaceCreated();
void onSurfaceDestroyed();
Expand All @@ -32,9 +34,17 @@
explicit DTreeLandPlatformWindowHelper(QWindow *window);
bool eventFilter(QObject *watched, QEvent *event) override;
void initWaylandWindow();

void doSetEnabledNoTitlebar();
void doSetWindowRadius();
void doSetEnabledBlurWindow();
private:
PersonalizationWindowContext *m_windowContext = nullptr;
static QMap<QWindow *, DTreeLandPlatformWindowHelper*> windowMap;

bool m_isNoTitlebar = false;
bool m_isWindowBlur = false;
int m_radius = 0;
};

class DTreeLandPlatformWindowInterface : public QObject, public DPlatformWindowInterface
Expand All @@ -56,14 +66,7 @@
bool enableBlurWindow() const override;
void setEnableBlurWindow(bool enableBlurWindow) override;

public slots:
void onSurfaceCreated();

private:
void doSetEnabledNoTitlebar();
void doSetWindowRadius();
void doSetEnabledBlurWindow();

bool m_isNoTitlebar = false;
bool m_isWindowBlur = false;
int m_radius = 0;
Expand Down
Loading