Fix: evita ricorsione allo scadere del timer; click su icona (workaround bug KDE 518024) e accessibilita' da tastiera

This commit is contained in:
enne2
2026-09-25 16:15:10 +02:00
parent 74ca562efe
commit c896b51455
+46 -7
View File
@@ -29,6 +29,7 @@ PlasmoidItem {
property string backend: "unknown" // systemd | unsupported | unknown
property int deadlineEpoch: 0
property int remainingSec: 0
property bool timerExpiring: false
property bool unitsReady: false
property string lastError: ""
@@ -102,12 +103,15 @@ PlasmoidItem {
if (deadlineEpoch > 0) {
const remaining = deadlineEpoch - Math.floor(Date.now() / 1000)
remainingSec = remaining > 0 ? remaining : 0
if (remaining <= 0) {
// il timer è scaduto: disattiva una sola volta (evita rientranze
// mentre lo stato del backend non è ancora aggiornato)
if (remaining <= 0 && !timerExpiring) {
timerExpiring = true
deactivate(true)
return
}
} else {
remainingSec = 0
timerExpiring = false
}
}
@@ -127,6 +131,7 @@ PlasmoidItem {
function activate() {
const minutes = plasmoid.configuration.autoOffMinutes
timerExpiring = false
run("on " + startMode + " " + minutes)
remainingSec = minutes > 0 ? minutes * 60 : 0
refreshDelay.restart()
@@ -148,10 +153,21 @@ PlasmoidItem {
}
}
// Gestione dei clic sull'icona di pannello.
// Sinistra: attiva/disattiva. Centrale: apre le opzioni.
function handleCompactClick(button) {
if (button === Qt.MiddleButton) {
expanded = !expanded
} else {
toggle()
}
}
function changeMode(keepScreen) {
if (!active) {
return
}
timerExpiring = false
run("switch " + (keepScreen ? "screen" : "sleep"))
refreshDelay.restart()
}
@@ -160,6 +176,7 @@ PlasmoidItem {
if (!active) {
return
}
timerExpiring = false
if (minutes > 0) {
remainingSec = minutes * 60
run("on " + startMode + " " + minutes)
@@ -232,8 +249,22 @@ PlasmoidItem {
// ------------------------------------------------- rappresentazione compatta
compactRepresentation: Item {
id: compactRoot
implicitWidth: compactRow.implicitWidth
implicitHeight: Kirigami.Units.iconSizes.smallMedium
activeFocusOnTab: true
Keys.onPressed: function(event) {
switch (event.key) {
case Qt.Key_Space:
case Qt.Key_Enter:
case Qt.Key_Return:
case Qt.Key_Select:
root.toggle()
event.accepted = true
break
}
}
RowLayout {
id: compactRow
@@ -241,6 +272,7 @@ PlasmoidItem {
spacing: Kirigami.Units.smallSpacing
Kirigami.Icon {
id: compactIcon
source: root.active ? root.iconOnPath : root.iconOffPath
implicitWidth: Kirigami.Units.iconSizes.smallMedium
implicitHeight: Kirigami.Units.iconSizes.smallMedium
@@ -259,11 +291,18 @@ PlasmoidItem {
acceptedButtons: Qt.LeftButton | Qt.MiddleButton
cursorShape: Qt.PointingHandCursor
onClicked: function(mouse) {
if (mouse.button === Qt.MiddleButton) {
root.expanded = !root.expanded
} else {
root.toggle()
}
root.handleCompactClick(mouse.button)
}
}
// Kirigami.Icon può assorbire i clic (bug KDE 518024): seconda area
// cliccabile sopra l'icona, con la stessa azione.
MouseArea {
anchors.fill: compactIcon
acceptedButtons: Qt.LeftButton | Qt.MiddleButton
cursorShape: Qt.PointingHandCursor
onClicked: function(mouse) {
root.handleCompactClick(mouse.button)
}
}
}