Skip to content

Commit

Permalink
feat: add filter by active windows for maximized preset auto-loading
Browse files Browse the repository at this point in the history
refs: #107
  • Loading branch information
luisbocanegra committed Nov 3, 2024
1 parent 2bfe9c2 commit c6dfe49
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 13 deletions.
33 changes: 21 additions & 12 deletions package/contents/ui/TasksModel.qml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*/

import QtQuick
import org.kde.taskmanager 0.1 as TaskManager
import org.kde.taskmanager as TaskManager

Item {

Expand All @@ -34,11 +34,15 @@ Item {
property var isWindow: abstractTasksModel.IsWindow
property var isFullScreen: abstractTasksModel.IsFullScreen
property var isMinimized: abstractTasksModel.IsMinimized
property bool filterByActive: false
property var activeTask: null

Connections {
target: plasmoid.configuration
function onValueChanged() {
updateWindowsinfo()
if (!updateTimer.running) {
updateTimer.start()
}
}
}

Expand All @@ -63,13 +67,17 @@ Item {
filterByActivity: true
filterMinimized: true

onActiveTaskChanged: {
updateWindowsinfo()
}
onDataChanged: {
updateWindowsinfo()
if (!updateTimer.running) {
updateTimer.start()
}
}
onCountChanged: {
}

Timer {
id: updateTimer
interval: 5
onTriggered: {
updateWindowsinfo()
}
}
Expand All @@ -80,13 +88,14 @@ Item {
let maximizedCount = 0
for (var i = 0; i < tasksModel.count; i++) {
const currentTask = tasksModel.index(i, 0)
if (currentTask === undefined) continue
if (tasksModel.data(currentTask, isWindow)) {
if (tasksModel.data(currentTask, isMaximized) || tasksModel.data(currentTask, isFullScreen)) maximizedCount+=1
}
if (currentTask === undefined || !tasksModel.data(currentTask, isWindow)) continue
const active = tasksModel.data(currentTask, isActive)
if (filterByActive && !active) continue
if (active) activeTask = currentTask
if (tasksModel.data(currentTask, isMaximized)) maximizedCount += 1
}
root.visibleExists = visibleCount > 0
root.maximizedExists = maximizedCount > 0
root.maximizedExists = filterByActive ? tasksModel.data(activeTask, isMaximized) : maximizedCount > 0
root.activeExists = activeCount > 0
}
}
Expand Down
13 changes: 12 additions & 1 deletion package/contents/ui/configPresetAutoload.qml
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,25 @@ KCM.SimpleKCM {
ComboBox {
model: presetsModel
textRole: "name"
Kirigami.FormData.label: i18n("Maximized window is shown:")
Kirigami.FormData.label: i18n("Maximized window:")
onCurrentIndexChanged: {
autoLoadConfig.maximized = model.get(currentIndex)["value"]
updateConfig()
}
currentIndex: getIndex(model, autoLoadConfig.maximized)
}

CheckBox {
// Kirigami.FormData.label: i18n("Active window only:")
text: i18n("Active window only")
checked: autoLoadConfig.maximizedFilterByActive
onCheckedChanged: {
autoLoadConfig.maximizedFilterByActive = checked
updateConfig()
}
enabled: autoLoadConfig.maximized ?? "" !== ""
}

ComboBox {
model: presetsModel
textRole: "name"
Expand Down
1 change: 1 addition & 0 deletions package/contents/ui/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -1321,6 +1321,7 @@ PlasmoidItem {
TasksModel {
id: tasksModel
screenGeometry: Plasmoid.containment.screenGeometry
filterByActive: presetAutoloading.maximizedFilterByActive ?? false
}

RunCommand {
Expand Down

0 comments on commit c6dfe49

Please sign in to comment.