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
+211 -174
View File
@@ -6,227 +6,264 @@ import qs.Components
import qs.Config
Item {
id: contextMenu
id: contextMenu
anchors.fill: parent
z: 999
visible: false
property real menuX: 0
property real menuY: 0
property var targetAppEntry: null
property string targetFilePath: ""
property bool targetIsDir: false
property var targetPaths: []
property string targetFilePath: ""
property bool targetIsDir: false
property var targetAppEntry: null
signal openFileRequested(string path, bool isDir)
signal renameRequested(string path)
property var targetPaths: []
function close() {
visible = false;
}
signal openFileRequested(string path, bool isDir)
signal renameRequested(string path)
function openAt(mouseX, mouseY, path, isDir, appEnt, parentW, parentH, selectionArray) {
targetFilePath = path;
targetIsDir = isDir;
targetAppEntry = appEnt;
property real menuX: 0
property real menuY: 0
targetPaths = (selectionArray && selectionArray.length > 0) ? selectionArray : [path];
CustomClippingRect {
id: popupBackground
readonly property real padding: Appearance.padding.small
menuX = Math.floor(Math.min(mouseX, parentW - popupBackground.implicitWidth));
menuY = Math.floor(Math.min(mouseY, parentH - popupBackground.implicitHeight));
x: contextMenu.menuX
y: contextMenu.menuY
visible = true;
}
color: DynamicColors.tPalette.m3surface
radius: Appearance.rounding.normal
anchors.fill: parent
visible: false
z: 999
implicitWidth: menuLayout.implicitWidth + padding * 2
implicitHeight: menuLayout.implicitHeight + padding * 2
CustomClippingRect {
id: popupBackground
Behavior on opacity { Anim {} }
opacity: contextMenu.visible ? 1 : 0
readonly property real padding: Appearance.padding.small
ColumnLayout {
id: menuLayout
anchors.centerIn: parent
spacing: 0
color: DynamicColors.tPalette.m3surface
implicitHeight: menuLayout.implicitHeight + padding * 2
implicitWidth: menuLayout.implicitWidth + padding * 2
opacity: contextMenu.visible ? 1 : 0
radius: Appearance.rounding.normal
x: contextMenu.menuX
y: contextMenu.menuY
CustomRect {
Layout.preferredWidth: 160
radius: popupBackground.radius - popupBackground.padding
implicitHeight: openRow.implicitHeight + Appearance.padding.small * 2
Behavior on opacity {
Anim {
}
}
RowLayout {
id: openRow
spacing: 8
anchors.fill: parent
anchors.leftMargin: Appearance.padding.smaller
ColumnLayout {
id: menuLayout
MaterialIcon { text: "open_in_new"; font.pointSize: 20 }
CustomText { text: "Open"; Layout.fillWidth: true }
}
anchors.centerIn: parent
spacing: 0
StateLayer {
anchors.fill: parent
CustomRect {
Layout.preferredWidth: 160
implicitHeight: openRow.implicitHeight + Appearance.padding.small * 2
radius: popupBackground.radius - popupBackground.padding
onClicked: {
for (let i = 0; i < contextMenu.targetPaths.length; i++) {
let p = contextMenu.targetPaths[i];
if (p === contextMenu.targetFilePath) {
if (p.endsWith(".desktop") && contextMenu.targetAppEntry) contextMenu.targetAppEntry.execute()
else contextMenu.openFileRequested(p, contextMenu.targetIsDir)
} else {
Quickshell.execDetached(["xdg-open", p])
}
}
contextMenu.close()
}
}
}
RowLayout {
id: openRow
CustomRect {
Layout.fillWidth: true
radius: popupBackground.radius - popupBackground.padding
implicitHeight: openWithRow.implicitHeight + Appearance.padding.small * 2
anchors.fill: parent
anchors.leftMargin: Appearance.padding.smaller
spacing: 8
RowLayout {
id: openWithRow
spacing: 8
anchors.fill: parent
anchors.leftMargin: Appearance.padding.smaller
MaterialIcon {
font.pointSize: 20
text: "open_in_new"
}
MaterialIcon { text: contextMenu.targetIsDir ? "terminal" : "apps"; font.pointSize: 20 }
CustomText { text: contextMenu.targetIsDir ? "Open in terminal" : "Open with..."; Layout.fillWidth: true }
}
CustomText {
Layout.fillWidth: true
text: "Open"
}
}
StateLayer {
anchors.fill: parent
StateLayer {
anchors.fill: parent
onClicked: {
for (let i = 0; i < contextMenu.targetPaths.length; i++) {
let p = contextMenu.targetPaths[i];
if (p === contextMenu.targetFilePath) {
if (p.endsWith(".desktop") && contextMenu.targetAppEntry)
contextMenu.targetAppEntry.execute();
else
contextMenu.openFileRequested(p, contextMenu.targetIsDir);
} else {
Quickshell.execDetached(["xdg-open", p]);
}
}
contextMenu.close();
}
}
}
CustomRect {
Layout.fillWidth: true
implicitHeight: openWithRow.implicitHeight + Appearance.padding.small * 2
radius: popupBackground.radius - popupBackground.padding
RowLayout {
id: openWithRow
anchors.fill: parent
anchors.leftMargin: Appearance.padding.smaller
spacing: 8
MaterialIcon {
font.pointSize: 20
text: contextMenu.targetIsDir ? "terminal" : "apps"
}
CustomText {
Layout.fillWidth: true
text: contextMenu.targetIsDir ? "Open in terminal" : "Open with..."
}
}
StateLayer {
anchors.fill: parent
onClicked: {
if (contextMenu.targetIsDir) {
Quickshell.execDetached([Config.general.apps.terminal, "--working-directory", contextMenu.targetFilePath])
Quickshell.execDetached([Config.general.apps.terminal, "--working-directory", contextMenu.targetFilePath]);
} else {
Quickshell.execDetached(["xdg-open", contextMenu.targetFilePath])
Quickshell.execDetached(["xdg-open", contextMenu.targetFilePath]);
}
contextMenu.close()
contextMenu.close();
}
}
}
}
}
CustomRect {
Layout.fillWidth: true
implicitHeight: 1
color: DynamicColors.palette.m3outlineVariant
Layout.topMargin: 4
Layout.bottomMargin: 4
}
CustomRect {
Layout.bottomMargin: 4
Layout.fillWidth: true
Layout.topMargin: 4
color: DynamicColors.palette.m3outlineVariant
implicitHeight: 1
}
CustomRect {
Layout.fillWidth: true
radius: popupBackground.radius - popupBackground.padding
implicitHeight: copyPathRow.implicitHeight + Appearance.padding.small * 2
CustomRect {
Layout.fillWidth: true
implicitHeight: copyPathRow.implicitHeight + Appearance.padding.small * 2
radius: popupBackground.radius - popupBackground.padding
RowLayout {
id: copyPathRow
spacing: 8
anchors.fill: parent
anchors.leftMargin: Appearance.padding.smaller
RowLayout {
id: copyPathRow
MaterialIcon { text: "content_copy"; font.pointSize: 20 }
CustomText { text: "Copy path"; Layout.fillWidth: true }
}
anchors.fill: parent
anchors.leftMargin: Appearance.padding.smaller
spacing: 8
StateLayer {
anchors.fill: parent
MaterialIcon {
font.pointSize: 20
text: "content_copy"
}
onClicked: {
Quickshell.execDetached(["wl-copy", contextMenu.targetPaths.join("\n")])
contextMenu.close()
}
}
}
CustomText {
Layout.fillWidth: true
text: "Copy path"
}
}
CustomRect {
Layout.fillWidth: true
visible: contextMenu.targetPaths.length === 1
radius: popupBackground.radius - popupBackground.padding
implicitHeight: renameRow.implicitHeight + Appearance.padding.small * 2
StateLayer {
anchors.fill: parent
RowLayout {
id: renameRow
spacing: 8
anchors.fill: parent
anchors.leftMargin: Appearance.padding.smaller
onClicked: {
Quickshell.execDetached(["wl-copy", contextMenu.targetPaths.join("\n")]);
contextMenu.close();
}
}
}
MaterialIcon { text: "edit"; font.pointSize: 20 }
CustomText { text: "Rename"; Layout.fillWidth: true }
}
CustomRect {
Layout.fillWidth: true
implicitHeight: renameRow.implicitHeight + Appearance.padding.small * 2
radius: popupBackground.radius - popupBackground.padding
visible: contextMenu.targetPaths.length === 1
StateLayer {
anchors.fill: parent
RowLayout {
id: renameRow
onClicked: {
contextMenu.renameRequested(contextMenu.targetFilePath)
contextMenu.close()
}
}
}
anchors.fill: parent
anchors.leftMargin: Appearance.padding.smaller
spacing: 8
Rectangle {
Layout.fillWidth: true
implicitHeight: 1
color: DynamicColors.palette.m3outlineVariant
Layout.topMargin: 4
Layout.bottomMargin: 4
}
MaterialIcon {
font.pointSize: 20
text: "edit"
}
CustomRect {
Layout.fillWidth: true
radius: popupBackground.radius - popupBackground.padding
implicitHeight: deleteRow.implicitHeight + Appearance.padding.small * 2
CustomText {
Layout.fillWidth: true
text: "Rename"
}
}
RowLayout {
id: deleteRow
spacing: 8
anchors.fill: parent
anchors.leftMargin: Appearance.padding.smaller
StateLayer {
anchors.fill: parent
MaterialIcon {
text: "delete"
font.pointSize: 20
color: deleteButton.hovered ? DynamicColors.palette.m3onError : DynamicColors.palette.m3error
}
onClicked: {
contextMenu.renameRequested(contextMenu.targetFilePath);
contextMenu.close();
}
}
}
CustomText {
text: "Move to trash"
Layout.fillWidth: true
color: deleteButton.hovered ? DynamicColors.palette.m3onError : DynamicColors.palette.m3error
}
}
Rectangle {
Layout.bottomMargin: 4
Layout.fillWidth: true
Layout.topMargin: 4
color: DynamicColors.palette.m3outlineVariant
implicitHeight: 1
}
StateLayer {
id: deleteButton
anchors.fill: parent
color: DynamicColors.tPalette.m3error
CustomRect {
Layout.fillWidth: true
implicitHeight: deleteRow.implicitHeight + Appearance.padding.small * 2
radius: popupBackground.radius - popupBackground.padding
onClicked: {
let cmd = ["gio", "trash"].concat(contextMenu.targetPaths)
Quickshell.execDetached(cmd)
contextMenu.close()
}
}
}
}
}
RowLayout {
id: deleteRow
function openAt(mouseX, mouseY, path, isDir, appEnt, parentW, parentH, selectionArray) {
targetFilePath = path
targetIsDir = isDir
targetAppEntry = appEnt
anchors.fill: parent
anchors.leftMargin: Appearance.padding.smaller
spacing: 8
targetPaths = (selectionArray && selectionArray.length > 0) ? selectionArray : [path]
MaterialIcon {
color: deleteButton.hovered ? DynamicColors.palette.m3onError : DynamicColors.palette.m3error
font.pointSize: 20
text: "delete"
}
menuX = Math.floor(Math.min(mouseX, parentW - popupBackground.implicitWidth))
menuY = Math.floor(Math.min(mouseY, parentH - popupBackground.implicitHeight))
CustomText {
Layout.fillWidth: true
color: deleteButton.hovered ? DynamicColors.palette.m3onError : DynamicColors.palette.m3error
text: "Move to trash"
}
}
visible = true
}
StateLayer {
id: deleteButton
function close() {
visible = false
}
anchors.fill: parent
color: DynamicColors.tPalette.m3error
onClicked: {
let cmd = ["gio", "trash"].concat(contextMenu.targetPaths);
Quickshell.execDetached(cmd);
contextMenu.close();
}
}
}
}
}
}