Skip to content

Commit

Permalink
fix: align blur for top/left of screen, handle widget visibility changes
Browse files Browse the repository at this point in the history
Also disabled per widget blur for now.

refs: #74
  • Loading branch information
luisbocanegra committed Sep 30, 2024
1 parent ba5ed59 commit 22c18cb
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 15 deletions.
1 change: 1 addition & 0 deletions package/contents/ui/components/FormWidgetSettings.qml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ ColumnLayout {
}
}
RowLayout {
visible: keyName !== ""
Label {
text: i18n("Blur behind:")
}
Expand Down
19 changes: 14 additions & 5 deletions package/contents/ui/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -830,18 +830,22 @@ PlasmoidItem {
}

onXChanged: {
position = Utils.getGlobalPosition(borderRec, panelElement)
updateMask()
}

onYChanged: {
position = Utils.getGlobalPosition(borderRec, panelElement)
updateMask()
}

onWidthChanged: {
position = Utils.getGlobalPosition(borderRec, panelElement)
updateMask()
}

onHeightChanged: {
position = Utils.getGlobalPosition(borderRec, panelElement)
updateMask()
}

Expand All @@ -867,17 +871,21 @@ PlasmoidItem {

// TODO find where does 16 and 8 come from instead of blindly hardcoding them
property real moveX: {
let m = horizontal ? 0 : (panelState.floating ? 16 : 0)
let m = horizontal ? 0 : (panelElement?.floating && plasmoid.location === PlasmaCore.Types.LeftEdge ? 16 : 0)
return floatigness > 0 ? 8 : m
}

property real moveY: {
let m = horizontal ? (panelState.floating ? 16 : 0) : 0
let m = horizontal ? (panelElement?.floating && plasmoid.location === PlasmaCore.Types.TopEdge ? 16 : 0) : 0
return floatigness > 0 ? 8 : m
}

onVisibleChanged: {
updateMask()
}

function updateMask() {
Qt.callLater(function() {
// Qt.callLater(function() {
if (panelColorizer === null || !blurBehind) return
panelColorizer.updatePanelMask(
maskIndex,
Expand All @@ -887,9 +895,10 @@ PlasmoidItem {
rect.corners.bottomLeftRadius,
rect.corners.bottomRightRadius,
Qt.point(rect.positionX-moveX, rect.positionY-moveY),
5
5,
visible
)
})
// })
}
}

Expand Down
14 changes: 6 additions & 8 deletions plugin/panelcolorizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ PanelColorizer::PanelColorizer(QObject *parent) : QObject(parent) {}

void PanelColorizer::updatePanelMask(int index, QRectF rect, double topLeftRadius, double topRightRadius,
double bottomLeftRadius, double bottomRightRadius, QPointF offset,
int radiusCompensation) {
int radiusCompensation, bool visible) {
// qDebug() << "updatePanelMask x:" << offset.x() << " y:" << offset.y() << " W:" << rect.width()
// << " H:" << rect.height();
topLeftRadius += (topLeftRadius != 0) ? radiusCompensation : 0;
Expand Down Expand Up @@ -50,20 +50,18 @@ void PanelColorizer::updatePanelMask(int index, QRectF rect, double topLeftRadiu
double translateY = abs(offset.y());
region.translate(translateX, translateY);

if (index >= m_regions.size()) {
m_regions.resize(index + 1);
}

m_regions[index] = region;
m_regions[index] = qMakePair(region, visible);
combineRegions();
}

QVariant PanelColorizer::mask() const { return QVariant::fromValue(m_mask); }

void PanelColorizer::combineRegions() {
QRegion combined;
for (const QRegion &region : m_regions) {
combined = combined.united(region);
for (const auto &pair : m_regions) {
if (pair.second) {
combined = combined.united(pair.first);
}
}

bool hadRegions = hasRegions();
Expand Down
5 changes: 3 additions & 2 deletions plugin/panelcolorizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class PanelColorizer : public QObject {
public:
Q_INVOKABLE void updatePanelMask(int index, QRectF rect, double topLeftRadius, double topRightRadius,
double bottomLeftRadius, double bottomRightRadius, QPointF offset,
int radiusCompensation);
int radiusCompensation, bool visible);

explicit PanelColorizer(QObject *parent = nullptr);

Expand All @@ -30,7 +30,8 @@ class PanelColorizer : public QObject {
private:
QString m_time;
qreal m_value;
QVector<QRegion> m_regions;
// QVector<QRegion> m_regions;
QMap<int, QPair<QRegion, bool>> m_regions;
QRegion m_mask;
void combineRegions();
};
Expand Down

0 comments on commit 22c18cb

Please sign in to comment.