Skip to content

Commit

Permalink
#38: use KWindowSystem to detect showingDesktop state
Browse files Browse the repository at this point in the history
  • Loading branch information
antroids committed Jul 9, 2024
1 parent de29647 commit 94d9353
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 12 deletions.
38 changes: 28 additions & 10 deletions package/contents/ui/ActiveTasksModel.qml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,21 @@ TaskManager.TasksModel {
property TaskManager.ActivityInfo activityInfo
property Repeater filteredTasksRepeater
property var activeTaskIndex: getInvalidIndex()
property Loader showingDesktopStateListener: Loader {
property bool showingDesktop: false

source: "KWindowSystemAdapter.qml"
onStatusChanged: function () {
if (status == Loader.Ready) {
showingDesktop = Qt.binding(function () {
return item.showingDesktop;
});
} else {
showingDesktop = false;
}
}
onShowingDesktopChanged: updateActiveTaskIndex()
}

function getInvalidIndex() {
return index(-1, -1);
Expand All @@ -31,14 +46,18 @@ TaskManager.TasksModel {
}

function updateActiveTaskIndex() {
switch (plasmoid.configuration.widgetActiveTaskSource) {
case ActiveTasksModel.ActiveTaskSource.ActiveTask:
activeTaskIndex = filterTask(activeTask) ? activeTask : getInvalidIndex();
break;
case ActiveTasksModel.ActiveTaskSource.LastActiveTask:
case ActiveTasksModel.ActiveTaskSource.LastActiveMaximized:
activeTaskIndex = hasIndex(0, 0) && filterTask(getFirstRowIndex()) ? getFirstRowIndex() : getInvalidIndex();
break;
if (showingDesktopStateListener.showingDesktop) {
activeTaskIndex = getInvalidIndex();
} else {
switch (plasmoid.configuration.widgetActiveTaskSource) {
case ActiveTasksModel.ActiveTaskSource.ActiveTask:
activeTaskIndex = filterTask(activeTask) ? activeTask : getInvalidIndex();
break;
case ActiveTasksModel.ActiveTaskSource.LastActiveTask:
case ActiveTasksModel.ActiveTaskSource.LastActiveMaximized:
activeTaskIndex = hasIndex(0, 0) && filterTask(getFirstRowIndex()) ? getFirstRowIndex() : getInvalidIndex();
break;
}
}
activeWindow.update();
}
Expand Down Expand Up @@ -72,8 +91,7 @@ TaskManager.TasksModel {
groupMode: TaskManager.TasksModel.GroupDisabled
Component.onCompleted: updateActiveTaskIndex()

virtualDesktopInfo: TaskManager.VirtualDesktopInfo {
}
virtualDesktopInfo: TaskManager.VirtualDesktopInfo {}

activityInfo: TaskManager.ActivityInfo {
readonly property string nullUuid: "00000000-0000-0000-0000-000000000000"
Expand Down
11 changes: 11 additions & 0 deletions package/contents/ui/KWindowSystemAdapter.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* SPDX-FileCopyrightText: 2024 Anton Kharuzhy <[email protected]>
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
import QtQuick
import org.kde.kwindowsystem

QtObject {
property bool showingDesktop: KWindowSystem.showingDesktop
}
5 changes: 4 additions & 1 deletion package/contents/ui/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,10 @@ PlasmoidItem {
titleTextResult = plasmoid.configuration.windowTitleUndefined;
break;
}
return Utils.Replacement.applyReplacementList(titleTextResult, titleTextReplacements);
if (titleTextResult) {
titleTextResult = Utils.Replacement.applyReplacementList(titleTextResult, titleTextReplacements);
}
return titleTextResult;
}

Layout.leftMargin: !hideEmpty ? plasmoid.configuration.windowTitleMarginsLeft : 0
Expand Down
2 changes: 1 addition & 1 deletion package/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"Id": "com.github.antroids.application-title-bar",
"Name": "Application Title Bar",
"License": "GPL-3.0+",
"Version": "0.6.5",
"Version": "0.6.6",
"Website": "https://github.com/antroids/application-title-bar",
"FormFactors": [
"desktop"
Expand Down

0 comments on commit 94d9353

Please sign in to comment.