more efficient desktop icons
Lint & Format (JS/TS) / lint-format (pull_request) Successful in 9s
Python / lint-format (pull_request) Successful in 16s
Python / test (pull_request) Successful in 30s
Lint & Format (Rust) / lint-format (pull_request) Successful in 1m6s

This commit is contained in:
2026-06-10 14:40:39 +02:00
parent 01556e66f3
commit 6b77ebd9be
9 changed files with 413 additions and 336 deletions
+54 -51
View File
@@ -6,16 +6,19 @@ import qs.Components
import qs.Helpers
Item {
id: delegateRoot
id: root
property var appEntry: fileName.endsWith(".desktop") ? DesktopEntries.byId(DesktopUtils.getAppId(fileName)) : null
property bool fileIsDir: model.isDir
property string fileName: model.fileName
property string filePath: model.filePath
property int gridX: model.gridX
property int gridY: model.gridY
required property var contextMenu
property bool fileIsDir: modelData.isDir
property string fileName: modelData.fileName
property string filePath: modelData.filePath
property int gridX: modelData.gridX
property int gridY: modelData.gridY
required property Item iconsRoot
property bool isSnapping: snapAnimX.running || snapAnimY.running
property bool lassoActive
required property var modelData
property string resolvedIcon: {
if (fileName.endsWith(".desktop")) {
if (appEntry && appEntry.icon && appEntry.icon !== "")
@@ -29,8 +32,8 @@ Item {
}
function compensateAndSnap(absVisX, absVisY) {
dragContainer.x = absVisX - delegateRoot.x;
dragContainer.y = absVisY - delegateRoot.y;
dragContainer.x = absVisX - root.x;
dragContainer.y = absVisY - root.y;
snapAnimX.start();
snapAnimY.start();
}
@@ -43,19 +46,19 @@ Item {
return dragContainer.y;
}
height: root.cellHeight
width: root.cellWidth
x: gridX * root.cellWidth
y: gridY * root.cellHeight
height: root.iconsRoot.cellHeight
width: root.iconsRoot.cellWidth
x: gridX * root.iconsRoot.cellWidth
y: gridY * root.iconsRoot.cellHeight
Behavior on x {
enabled: !mouseArea.drag.active && !isSnapping && !root.selectedIcons.includes(filePath)
enabled: !mouseArea.drag.active && !root.isSnapping && !root.iconsRoot.selectedIcons.includes(root.filePath)
Anim {
}
}
Behavior on y {
enabled: !mouseArea.drag.active && !isSnapping && !root.selectedIcons.includes(filePath)
enabled: !mouseArea.drag.active && !root.isSnapping && !root.iconsRoot.selectedIcons.includes(root.filePath)
Anim {
}
@@ -78,8 +81,8 @@ Item {
}
}
transform: Translate {
x: (root.selectedIcons.includes(filePath) && root.dragLeader !== "" && root.dragLeader !== filePath) ? root.groupDragX : 0
y: (root.selectedIcons.includes(filePath) && root.dragLeader !== "" && root.dragLeader !== filePath) ? root.groupDragY : 0
x: (root.iconsRoot.selectedIcons.includes(root.filePath) && root.iconsRoot.dragLeader !== "" && root.iconsRoot.dragLeader !== root.filePath) ? root.iconsRoot.groupDragX : 0
y: (root.iconsRoot.selectedIcons.includes(root.filePath) && root.iconsRoot.dragLeader !== "" && root.iconsRoot.dragLeader !== root.filePath) ? root.iconsRoot.groupDragY : 0
}
transitions: Transition {
Anim {
@@ -88,14 +91,14 @@ Item {
onXChanged: {
if (mouseArea.drag.active) {
root.dragLeader = filePath;
root.groupDragX = x;
root.iconsRoot.dragLeader = root.filePath;
root.iconsRoot.groupDragX = x;
}
}
onYChanged: {
if (mouseArea.drag.active) {
root.dragLeader = filePath;
root.groupDragY = y;
root.iconsRoot.dragLeader = root.filePath;
root.iconsRoot.groupDragY = y;
}
}
@@ -127,10 +130,10 @@ Item {
anchors.horizontalCenter: parent.horizontalCenter
implicitSize: 48
source: {
if (delegateRoot.resolvedIcon.startsWith("file://") || delegateRoot.resolvedIcon.startsWith("/")) {
return delegateRoot.resolvedIcon;
if (root.resolvedIcon.startsWith("file://") || root.resolvedIcon.startsWith("/")) {
return root.resolvedIcon;
} else {
return Quickshell.iconPath(delegateRoot.resolvedIcon, fileIsDir ? "folder" : "text-x-generic");
return Quickshell.iconPath(root.resolvedIcon, root.fileIsDir ? "folder" : "text-x-generic");
}
}
}
@@ -147,7 +150,7 @@ Item {
maximumLineCount: 2
style: Text.Outline
styleColor: "black"
text: (appEntry && appEntry.name !== "") ? appEntry.name : fileName
text: (root.appEntry && root.appEntry.name !== "") ? root.appEntry.name : root.fileName
visible: !renameLoader.active
wrapMode: Text.Wrap
}
@@ -155,7 +158,7 @@ Item {
Loader {
id: renameLoader
active: root.editingFilePath === filePath
active: root.iconsRoot.editingFilePath === root.filePath
anchors.centerIn: parent
height: 24
width: 110
@@ -165,7 +168,7 @@ Item {
anchors.margins: 2
color: "white"
horizontalAlignment: Text.AlignHCenter
text: fileName
text: root.fileName
wrapMode: Text.Wrap
Component.onCompleted: {
@@ -174,22 +177,22 @@ Item {
}
Keys.onPressed: function (event) {
if (event.key === Qt.Key_Return || event.key === Qt.Key_Enter) {
if (text.trim() !== "" && text !== fileName) {
if (text.trim() !== "" && text !== root.fileName) {
let newName = text.trim();
let newPath = filePath.substring(0, filePath.lastIndexOf('/') + 1) + newName;
let newPath = root.filePath.substring(0, root.filePath.lastIndexOf('/') + 1) + newName;
Quickshell.execDetached(["mv", filePath, newPath]);
Quickshell.execDetached(["mv", root.filePath, newPath]);
}
root.editingFilePath = "";
root.iconsRoot.editingFilePath = "";
event.accepted = true;
} else if (event.key === Qt.Key_Escape) {
root.editingFilePath = "";
root.iconsRoot.editingFilePath = "";
event.accepted = true;
}
}
onActiveFocusChanged: {
if (!activeFocus && root.editingFilePath === filePath) {
root.editingFilePath = "";
if (!activeFocus && root.iconsRoot.editingFilePath === root.filePath) {
root.iconsRoot.editingFilePath = "";
}
}
}
@@ -201,7 +204,7 @@ Item {
anchors.fill: parent
anchors.margins: 4
color: "white"
opacity: root.selectedIcons.includes(filePath) ? 0.2 : 0.0
opacity: root.iconsRoot.selectedIcons.includes(root.filePath) ? 0.2 : 0.0
radius: Appearance.rounding.smallest
Behavior on opacity {
@@ -215,45 +218,45 @@ Item {
acceptedButtons: Qt.LeftButton | Qt.RightButton
anchors.fill: parent
cursorShape: root.lassoActive ? undefined : Qt.PointingHandCursor
cursorShape: root.iconsRoot.lassoActive ? undefined : Qt.PointingHandCursor
drag.target: dragContainer
hoverEnabled: true
onClicked: mouse => {
root.forceActiveFocus();
root.iconsRoot.forceActiveFocus();
if (mouse.button === Qt.RightButton) {
if (!root.selectedIcons.includes(filePath)) {
root.selectedIcons = [filePath];
if (!root.iconsRoot.selectedIcons.includes(root.filePath)) {
root.iconsRoot.selectedIcons = [root.filePath];
}
let pos = mapToItem(root, mouse.x, mouse.y);
root.contextMenu.openAt(pos.x, pos.y, filePath, fileIsDir, appEntry, root.width, root.height, root.selectedIcons);
let pos = mapToItem(root.iconsRoot, mouse.x, mouse.y);
root.contextMenu.openAt(pos.x, pos.y, root.filePath, root.fileIsDir, root.appEntry, root.iconsRoot.width, root.iconsRoot.height, root.iconsRoot.selectedIcons);
} else {
root.selectedIcons = [filePath];
root.iconsRoot.selectedIcons = [root.filePath];
root.contextMenu.close();
}
}
onDoubleClicked: mouse => {
if (mouse.button === Qt.LeftButton) {
if (filePath.endsWith(".desktop") && appEntry)
appEntry.execute();
if (root.filePath.endsWith(".desktop") && root.appEntry)
root.appEntry.execute();
else
root.exec(filePath, fileIsDir);
root.iconsRoot.exec(root.filePath, root.fileIsDir);
}
}
onPressed: mouse => {
if (mouse.button === Qt.LeftButton && !root.selectedIcons.includes(filePath)) {
root.selectedIcons = [filePath];
if (mouse.button === Qt.LeftButton && !root.iconsRoot.selectedIcons.includes(root.filePath)) {
root.iconsRoot.selectedIcons = [root.filePath];
}
}
onReleased: {
if (drag.active) {
let absoluteX = delegateRoot.x + dragContainer.x;
let absoluteY = delegateRoot.y + dragContainer.y;
let snapX = Math.max(0, Math.round(absoluteX / root.cellWidth));
let snapY = Math.max(0, Math.round(absoluteY / root.cellHeight));
let absoluteX = root.x + dragContainer.x;
let absoluteY = root.y + dragContainer.y;
let snapX = Math.max(0, Math.round(absoluteX / root.iconsRoot.cellWidth));
let snapY = Math.max(0, Math.round(absoluteY / root.iconsRoot.cellHeight));
root.performMassDrop(filePath, snapX, snapY);
root.iconsRoot.performMassDrop(root.filePath, snapX, snapY);
}
}