Skip to content

Commit c6dfe49

Browse files
committed
feat: add filter by active windows for maximized preset auto-loading
refs: #107
1 parent 2bfe9c2 commit c6dfe49

File tree

3 files changed

+34
-13
lines changed

3 files changed

+34
-13
lines changed

package/contents/ui/TasksModel.qml

+21-12
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
*/
2020

2121
import QtQuick
22-
import org.kde.taskmanager 0.1 as TaskManager
22+
import org.kde.taskmanager as TaskManager
2323

2424
Item {
2525

@@ -34,11 +34,15 @@ Item {
3434
property var isWindow: abstractTasksModel.IsWindow
3535
property var isFullScreen: abstractTasksModel.IsFullScreen
3636
property var isMinimized: abstractTasksModel.IsMinimized
37+
property bool filterByActive: false
38+
property var activeTask: null
3739

3840
Connections {
3941
target: plasmoid.configuration
4042
function onValueChanged() {
41-
updateWindowsinfo()
43+
if (!updateTimer.running) {
44+
updateTimer.start()
45+
}
4246
}
4347
}
4448

@@ -63,13 +67,17 @@ Item {
6367
filterByActivity: true
6468
filterMinimized: true
6569

66-
onActiveTaskChanged: {
67-
updateWindowsinfo()
68-
}
6970
onDataChanged: {
70-
updateWindowsinfo()
71+
if (!updateTimer.running) {
72+
updateTimer.start()
73+
}
7174
}
72-
onCountChanged: {
75+
}
76+
77+
Timer {
78+
id: updateTimer
79+
interval: 5
80+
onTriggered: {
7381
updateWindowsinfo()
7482
}
7583
}
@@ -80,13 +88,14 @@ Item {
8088
let maximizedCount = 0
8189
for (var i = 0; i < tasksModel.count; i++) {
8290
const currentTask = tasksModel.index(i, 0)
83-
if (currentTask === undefined) continue
84-
if (tasksModel.data(currentTask, isWindow)) {
85-
if (tasksModel.data(currentTask, isMaximized) || tasksModel.data(currentTask, isFullScreen)) maximizedCount+=1
86-
}
91+
if (currentTask === undefined || !tasksModel.data(currentTask, isWindow)) continue
92+
const active = tasksModel.data(currentTask, isActive)
93+
if (filterByActive && !active) continue
94+
if (active) activeTask = currentTask
95+
if (tasksModel.data(currentTask, isMaximized)) maximizedCount += 1
8796
}
8897
root.visibleExists = visibleCount > 0
89-
root.maximizedExists = maximizedCount > 0
98+
root.maximizedExists = filterByActive ? tasksModel.data(activeTask, isMaximized) : maximizedCount > 0
9099
root.activeExists = activeCount > 0
91100
}
92101
}

package/contents/ui/configPresetAutoload.qml

+12-1
Original file line numberDiff line numberDiff line change
@@ -118,14 +118,25 @@ KCM.SimpleKCM {
118118
ComboBox {
119119
model: presetsModel
120120
textRole: "name"
121-
Kirigami.FormData.label: i18n("Maximized window is shown:")
121+
Kirigami.FormData.label: i18n("Maximized window:")
122122
onCurrentIndexChanged: {
123123
autoLoadConfig.maximized = model.get(currentIndex)["value"]
124124
updateConfig()
125125
}
126126
currentIndex: getIndex(model, autoLoadConfig.maximized)
127127
}
128128

129+
CheckBox {
130+
// Kirigami.FormData.label: i18n("Active window only:")
131+
text: i18n("Active window only")
132+
checked: autoLoadConfig.maximizedFilterByActive
133+
onCheckedChanged: {
134+
autoLoadConfig.maximizedFilterByActive = checked
135+
updateConfig()
136+
}
137+
enabled: autoLoadConfig.maximized ?? "" !== ""
138+
}
139+
129140
ComboBox {
130141
model: presetsModel
131142
textRole: "name"

package/contents/ui/main.qml

+1
Original file line numberDiff line numberDiff line change
@@ -1321,6 +1321,7 @@ PlasmoidItem {
13211321
TasksModel {
13221322
id: tasksModel
13231323
screenGeometry: Plasmoid.containment.screenGeometry
1324+
filterByActive: presetAutoloading.maximizedFilterByActive ?? false
13241325
}
13251326

13261327
RunCommand {

0 commit comments

Comments
 (0)