Files
glassMxrph/quickshell/dock/DockItem.qml
T
mxandClaude Opus 5.5 99e64a7713 Add glassMxrph shell sources
Initial commit of the Quickshell desktop suite: bar, dock, launcher,
settings, Control Center, dashboard, OSD, lock screen, desktop widgets,
plugin host with the vendored Noctalia/Omarchy compatibility layer,
helpers, packaging, tests and phase documentation.

Includes the optimization work so far: usage widgets and dashboard
gauges no longer animate continuously, desktop widgets pause while
covered, system controls stop flickering on background polls, dock app
matching uses an indexed catalog, and workspace ghosts are created only
for occupied slots.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-07 22:36:17 +02:00

140 lines
5.2 KiB
QML

import QtQuick
import QtQuick.Controls
import "../services"
import "../theme"
Item {
id: root
required property var modelData
required property int index
required property var dockWindow
readonly property var group: DockModel.find(modelData.id) || modelData
readonly property bool vertical: dockWindow.vertical
readonly property var options: DockModel.options
readonly property real influence: Theme.intensity > 0 && options.magnification && dockWindow.hoveredIndex >= 0 && !DockState.draggingId ? Math.max(0, 1 - Math.abs(index - dockWindow.hoveredIndex) / 2.5) : 0
readonly property real magnification: 1 + options.magnificationStrength * influence * Theme.intensity
property bool dragging: false
property point pressedAt
property real offsetX: 0
property real offsetY: 0
width: vertical ? dockWindow.thickness - 20 : options.iconSize + 12 + options.iconSize * influence * 0.2
height: vertical ? options.iconSize + 12 + options.iconSize * influence * 0.2 : dockWindow.thickness - 20
Behavior on width {
NumberAnimation {
duration: root.dockWindow.motionDuration
}
}
Behavior on height {
NumberAnimation {
duration: root.dockWindow.motionDuration
}
}
Component.onCompleted: DockState.icons = DockState.icons.concat([root])
Component.onDestruction: DockState.removeIcon(root)
Item {
id: visual
anchors.centerIn: parent
width: root.options.iconSize
height: width
scale: mouse.pressed && !root.dragging ? 1 - 0.08 * Theme.intensity : root.magnification
transform: Translate {
x: root.offsetX
y: root.offsetY
}
Behavior on scale {
NumberAnimation {
duration: root.dockWindow.motionDuration
easing.type: Easing.OutCubic
}
}
Image {
id: icon
anchors.fill: parent
source: ApplicationsService.icon(root.group.entry)
sourceSize.width: root.options.iconSize * 2
sourceSize.height: root.options.iconSize * 2
fillMode: Image.PreserveAspectFit
}
Rectangle {
anchors.fill: parent
radius: 12
color: Theme.surfaceVariant
visible: icon.source.toString() === "" || icon.status === Image.Error
Text {
anchors.centerIn: parent
text: root.group.name.slice(0, 2).toUpperCase()
color: Theme.text
font.pixelSize: 16
}
}
}
Rectangle {
width: root.group.focused ? 15 : 5
height: 4
radius: 2
x: root.vertical ? (root.options.position === "left" ? 3 : root.width - width - 3) : (root.width - width) / 2
y: root.vertical ? (root.height - height) / 2 : root.height - height - 3
color: root.group.focused ? Theme.accent : Theme.textSecondary
visible: root.options.runningIndicators && root.group.windows.length > 0
Behavior on width {
NumberAnimation {
duration: root.dockWindow.motionDuration
}
}
}
MouseArea {
id: mouse
anchors.fill: parent
hoverEnabled: true
acceptedButtons: Qt.LeftButton | Qt.RightButton
preventStealing: root.group.pinned
onEntered: root.dockWindow.hoveredIndex = root.index
onExited: if (!pressed)
root.dockWindow.hoveredIndex = -1
onPressed: event => {
root.pressedAt = Qt.point(event.x, event.y);
root.dragging = false;
}
onPositionChanged: event => {
if (!pressed || pressedButtons !== Qt.LeftButton || !root.group.pinned)
return;
const dx = event.x - root.pressedAt.x, dy = event.y - root.pressedAt.y;
if (root.dragging || Math.hypot(dx, dy) > 8) {
root.dragging = true;
DockState.draggingId = root.group.id;
root.offsetX = dx;
root.offsetY = dy;
}
}
onReleased: event => {
if (root.dragging)
root.dockWindow.dropPin(root, event.x, event.y);
root.offsetX = 0;
root.offsetY = 0;
DockState.draggingId = "";
}
onCanceled: {
root.offsetX = 0;
root.offsetY = 0;
root.dragging = false;
DockState.draggingId = "";
}
onClicked: event => {
if (root.dragging) {
root.dragging = false;
return;
}
if (event.button === Qt.RightButton)
DockState.open(root.group.id, root, false);
else
DockState.click(root.group.id, root);
}
}
Accessible.role: Accessible.Button
Accessible.name: group.name
Accessible.onPressAction: DockState.click(group.id, root)
ToolTip.visible: options.tooltips && mouse.containsMouse && !DockState.opened && !dragging
ToolTip.delay: 500
ToolTip.text: group.name + (group.windows.length ? " · " + group.windows.length + " window(s)" : group.entry ? "" : " · unavailable")
}