fix: improve popup geometry update

This should fix using wrong coordinates when text overflows
This commit is contained in:
Mikhail Zolotukhin 2021-10-23 01:54:26 +03:00
parent 8c013ac7bc
commit 1f02e47a37
2 changed files with 12 additions and 10 deletions

View File

@ -20,8 +20,7 @@ Item {
source: "popup.qml"
function show(text) {
var area = workspace.clientArea(KWin.FullScreenArea, workspace.activeScreen, workspace.currentDesktop);
this.item.show(text, area);
this.item.show(text);
}
}

View File

@ -8,6 +8,7 @@ import QtQuick.Controls 2.0
import QtQuick.Layouts 1.15
import org.kde.plasma.core 2.0 as PlasmaCore;
import org.kde.plasma.components 3.0 as PC3
import org.kde.kwin 2.0;
/*
* Component Documentation
@ -24,6 +25,12 @@ PlasmaCore.Dialog {
location: PlasmaCore.Types.Floating
outputOnly: true
property rect screenGeometry
// Spawn popup a little bit lower than the center of the screen for consistency
x: (screenGeometry.x + screenGeometry.width / 2) - width / 2;
y: (screenGeometry.y + screenGeometry.height * 2 / 3) - height / 2;
visible: false
mainItem: RowLayout {
@ -52,25 +59,21 @@ PlasmaCore.Dialog {
}
Component.onCompleted: {
// NOTE: IDK what this is, but this is necessary to keep the window working.
KWin.registerWindow(this);
}
function show(text, area) {
function show(text) {
// Abort any previous timers
hideTimer.stop();
// Update current screen information
this.screenGeometry = workspace.clientArea(KWin.FullScreenArea, workspace.activeScreen, workspace.currentDesktop);
// Set the text for the popup
messageLabel.text = text;
// Width and height are not computed before the popup is visible
// therefore we need to make is visible sooner
this.visible = true;
// Spawn popup a little bit lower than the center of the screen for consistency
this.x = (area.x + area.width / 2) - this.width / 2;
this.y = (area.y + area.height * 2 / 3) - this.height / 2;
// Start popup hide timer
hideTimer.interval = 3000;
hideTimer.start();