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

Fix the issue when the window changes the decoration status and is left without a round corner #95

Merged
merged 1 commit into from
Jul 16, 2023
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
35 changes: 17 additions & 18 deletions src/ShapeCornersEffect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,17 @@ ShapeCornersEffect::~ShapeCornersEffect() = default;
void
ShapeCornersEffect::windowAdded(KWin::EffectWindow *w)
{
if (m_managed.contains(w))
return;
qDebug() << w->windowRole() << w->windowType() << w->windowClass();
if (!w->hasDecoration())
return;
m_managed.insert(w);

redirect(w);
setShader(w, m_shaderManager.GetShader().get());
auto r = m_managed.insert(w);
if (r.second) {
redirect(w);
setShader(w, m_shaderManager.GetShader().get());
}
}

void ShapeCornersEffect::windowRemoved(KWin::EffectWindow *w)
{
m_managed.remove(w);
m_managed.erase(w);
unredirect(w);
}

Expand All @@ -78,22 +75,20 @@ ShapeCornersEffect::reconfigure(ReconfigureFlags flags)
ShapeCornersConfig::self()->read();
}

bool isMaximized(KWin::EffectWindow *w) {
bool ShapeCornersEffect::isMaximized(const KWin::EffectWindow *w) {
auto screenGeometry = KWin::effects->findScreen(w->screen()->name())->geometry();
return (w->x() == screenGeometry.x() && w->width() == screenGeometry.width()) ||
(w->y() == screenGeometry.y() && w->height() == screenGeometry.height());
}

QRectF operator *(QRect r, qreal scale) { return {r.x() * scale, r.y() * scale, r.width() * scale, r.height() * scale}; }
QRectF operator *(QRectF r, qreal scale) { return {r.x() * scale, r.y() * scale, r.width() * scale, r.height() * scale}; }
QRect toRect(const QRectF& r) { return {(int)r.x(), (int)r.y(), (int)r.width(), (int)r.height()}; }
const QRect& toRect(const QRect& r) { return r; }

void ShapeCornersEffect::prePaintWindow(KWin::EffectWindow *w, KWin::WindowPrePaintData &data, std::chrono::milliseconds time)
{
if (!m_shaderManager.IsValid()
|| !m_managed.contains(w)
|| isMaximized(w)
)
if (!hasEffect(w))
{
Effect::prePaintWindow(w, data, time);
return;
Expand Down Expand Up @@ -129,10 +124,7 @@ bool ShapeCornersEffect::supported()

void ShapeCornersEffect::drawWindow(KWin::EffectWindow *w, int mask, const QRegion &region,
KWin::WindowPaintData &data) {
if (!m_shaderManager.IsValid()
|| !m_managed.contains(w)
|| isMaximized(w)
)
if (!hasEffect(w))
{
unredirect(w);
#if KWIN_EFFECT_API_VERSION >= 236
Expand All @@ -155,3 +147,10 @@ void ShapeCornersEffect::drawWindow(KWin::EffectWindow *w, int mask, const QRegi
#endif
m_shaderManager.Unbind();
}

bool ShapeCornersEffect::hasEffect(const KWin::EffectWindow *w) const {
return m_shaderManager.IsValid()
&& m_managed.contains(w)
&& w->hasDecoration()
&& !isMaximized(w);
}
6 changes: 5 additions & 1 deletion src/ShapeCornersEffect.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#pragma once

#include <kwineffects.h>
#include <set>
#include "ShapeCornersShader.h"

#if KWIN_EFFECT_API_VERSION >= 236
Expand Down Expand Up @@ -50,7 +51,10 @@ protected Q_SLOTS:
void windowRemoved(KWin::EffectWindow *window);

private:
QSet<KWin::EffectWindow*> m_managed;
std::set<const KWin::EffectWindow*> m_managed;
ShapeCornersShader m_shaderManager;

bool hasEffect(const KWin::EffectWindow *w) const;
static bool isMaximized(const KWin::EffectWindow *w);
};