Commit 24900b33 authored by Kai Uwe Broulik's avatar Kai Uwe Broulik 🍇
Browse files

[Notifications] Move out of the way of dialog rather than just hiding

When e.g. connecting to a network with captive portal, it leaves you sitting there wondering what's going on.
The notification won't time out until it becomes visible again but still there's been complaints that the notifications go missing.
This patch makes them move out of the way vertically.
It is pretty crude but covers the majority ("System Tray covers notifications") case.

Differential Revision: https://phabricator.kde.org/D25566
parent c70fb9df
......@@ -126,6 +126,9 @@ QtObject {
}
}
readonly property QtObject focusDialog: plasmoid.nativeInterface.focussedPlasmaDialog
onFocusDialogChanged: positionPopups()
// The raw width of the popup's content item, the Dialog itself adds some margins
property int popupWidth: units.gridUnit * 18
property int popupEdgeDistance: units.largeSpacing * 2
......@@ -212,6 +215,13 @@ QtObject {
});
}
function rectIntersect(rect1 /*dialog*/, rect2 /*popup*/) {
return rect1.x < rect2.x + rect2.width
&& rect2.x < rect1.x + rect1.width
&& rect1.y < rect2.y + rect2.height
&& rect2.y < rect1.y + rect1.height;
}
function positionPopups() {
if (!plasmoid) {
return;
......@@ -251,12 +261,22 @@ QtObject {
}
if (popupLocation & Qt.AlignTop) {
// We want to calculate the new position based on its original target position to avoid positioning it and then
// positioning it again, hence the temporary Qt.rect with explicit "y" and not just the popup as a whole
if (focusDialog && focusDialog.visible && focusDialog !== popup
&& rectIntersect(focusDialog, Qt.rect(popup.x, y, popup.width, popup.height))) {
y = focusDialog.y + focusDialog.height + popupEdgeDistance;
}
popup.y = y;
// If the popup isn't ready yet, ignore its occupied space for now.
// We'll reposition everything in onHeightChanged eventually.
y += popup.height + (popup.height > 0 ? popupSpacing : 0);
} else {
y -= popup.height;
if (focusDialog && focusDialog.visible && focusDialog !== popup
&& rectIntersect(focusDialog, Qt.rect(popup.x, y, popup.width, popup.height))) {
y = focusDialog.y - popup.height - popupEdgeDistance;
}
popup.y = y;
if (popup.height > 0) {
y -= popupSpacing;
......@@ -273,18 +293,7 @@ QtObject {
}
}
popup.visible = Qt.binding(function() {
const dialog = plasmoid.nativeInterface.focussedPlasmaDialog;
if (dialog && dialog.visible && dialog !== popup) {
// If the notification obscures any other Plasma dialog, hide it
// No rect intersects in JS...
if (dialog.x < popup.x + popup.width && popup.x < dialog.x + dialog.width && dialog.y < popup.y + popup.height && popup.y < dialog.y + dialog.height) {
return false;
}
}
return visible;
});
popup.visible = visible;
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment