1
0
mirror of https://github.com/AvengeMedia/DankMaterialShell.git synced 2026-01-29 07:52:50 -05:00

runningapps: fix context menu on vertical bar

This commit is contained in:
bbedward
2025-10-22 10:11:10 -04:00
parent b9b15568b4
commit ea7676c98e

View File

@@ -21,48 +21,55 @@ Item {
readonly property real horizontalPadding: SettingsData.dankBarNoBackground ? 2 : Theme.spacingS readonly property real horizontalPadding: SettingsData.dankBarNoBackground ? 2 : Theme.spacingS
property Item windowRoot: (Window.window ? Window.window.contentItem : null) property Item windowRoot: (Window.window ? Window.window.contentItem : null)
readonly property var sortedToplevels: { readonly property var sortedToplevels: {
const toplevels = CompositorService.sortedToplevels
if (!toplevels)
return []
if (SettingsData.runningAppsCurrentWorkspace) { if (SettingsData.runningAppsCurrentWorkspace) {
return CompositorService.filterCurrentWorkspace(CompositorService.sortedToplevels, parentScreen?.name); return CompositorService.filterCurrentWorkspace(toplevels, parentScreen?.name) || []
} }
return CompositorService.sortedToplevels; return toplevels
} }
readonly property var groupedWindows: { readonly property var groupedWindows: {
if (!SettingsData.runningAppsGroupByApp) { if (!SettingsData.runningAppsGroupByApp) {
return []; return []
} }
try { try {
const appGroups = new Map(); if (!sortedToplevels || sortedToplevels.length === 0) {
return []
}
const appGroups = new Map()
sortedToplevels.forEach((toplevel, index) => { sortedToplevels.forEach((toplevel, index) => {
if (!toplevel) return; if (!toplevel)
const appId = toplevel?.appId || "unknown"; return
const appId = toplevel?.appId || "unknown"
if (!appGroups.has(appId)) { if (!appGroups.has(appId)) {
appGroups.set(appId, { appGroups.set(appId, {
appId: appId, "appId": appId,
windows: [] "windows": []
}); })
} }
appGroups.get(appId).windows.push({ appGroups.get(appId).windows.push({
toplevel: toplevel, "toplevel": toplevel,
windowId: index, "windowId": index,
windowTitle: toplevel?.title || "(Unnamed)" "windowTitle": toplevel?.title || "(Unnamed)"
}); })
}); })
return Array.from(appGroups.values()); return Array.from(appGroups.values())
} catch (e) { } catch (e) {
console.error("RunningApps: groupedWindows error:", e); console.error("RunningApps: groupedWindows error:", e)
return []; return []
} }
} }
readonly property int windowCount: SettingsData.runningAppsGroupByApp ? groupedWindows.length : sortedToplevels.length readonly property int windowCount: SettingsData.runningAppsGroupByApp ? (groupedWindows?.length || 0) : (sortedToplevels?.length || 0)
readonly property int calculatedSize: { readonly property int calculatedSize: {
if (windowCount === 0) { if (windowCount === 0) {
return 0; return 0
} }
if (SettingsData.runningAppsCompactMode) { if (SettingsData.runningAppsCompactMode) {
return windowCount * 24 + (windowCount - 1) * Theme.spacingXS + horizontalPadding * 2; return windowCount * 24 + (windowCount - 1) * Theme.spacingXS + horizontalPadding * 2
} else { } else {
return windowCount * (24 + Theme.spacingXS + 120) return windowCount * (24 + Theme.spacingXS + 120) + (windowCount - 1) * Theme.spacingXS + horizontalPadding * 2
+ (windowCount - 1) * Theme.spacingXS + horizontalPadding * 2;
} }
} }
@@ -79,15 +86,15 @@ Item {
clip: false clip: false
color: { color: {
if (windowCount === 0) { if (windowCount === 0) {
return "transparent"; return "transparent"
} }
if (SettingsData.dankBarNoBackground) { if (SettingsData.dankBarNoBackground) {
return "transparent"; return "transparent"
} }
const baseColor = Theme.widgetBaseBackgroundColor; const baseColor = Theme.widgetBaseBackgroundColor
return Qt.rgba(baseColor.r, baseColor.g, baseColor.b, baseColor.a * Theme.widgetTransparency); return Qt.rgba(baseColor.r, baseColor.g, baseColor.b, baseColor.a * Theme.widgetTransparency)
} }
} }
@@ -99,83 +106,82 @@ Item {
property real scrollAccumulator: 0 property real scrollAccumulator: 0
property real touchpadThreshold: 500 property real touchpadThreshold: 500
onWheel: (wheel) => { onWheel: wheel => {
const deltaY = wheel.angleDelta.y; const deltaY = wheel.angleDelta.y
const isMouseWheel = Math.abs(deltaY) >= 120 const isMouseWheel = Math.abs(deltaY) >= 120 && (Math.abs(deltaY) % 120) === 0
&& (Math.abs(deltaY) % 120) === 0;
const windows = root.sortedToplevels; const windows = root.sortedToplevels
if (windows.length < 2) { if (windows.length < 2) {
return; return
} }
if (isMouseWheel) { if (isMouseWheel) {
// Direct mouse wheel action // Direct mouse wheel action
let currentIndex = -1; let currentIndex = -1
for (let i = 0; i < windows.length; i++) { for (var i = 0; i < windows.length; i++) {
if (windows[i].activated) { if (windows[i].activated) {
currentIndex = i; currentIndex = i
break; break
} }
} }
let nextIndex; let nextIndex
if (deltaY < 0) { if (deltaY < 0) {
if (currentIndex === -1) { if (currentIndex === -1) {
nextIndex = 0; nextIndex = 0
} else { } else {
nextIndex = (currentIndex + 1) % windows.length; nextIndex = (currentIndex + 1) % windows.length
} }
} else { } else {
if (currentIndex === -1) { if (currentIndex === -1) {
nextIndex = windows.length - 1; nextIndex = windows.length - 1
} else { } else {
nextIndex = (currentIndex - 1 + windows.length) % windows.length; nextIndex = (currentIndex - 1 + windows.length) % windows.length
} }
} }
const nextWindow = windows[nextIndex]; const nextWindow = windows[nextIndex]
if (nextWindow) { if (nextWindow) {
nextWindow.activate(); nextWindow.activate()
} }
} else { } else {
// Touchpad - accumulate small deltas // Touchpad - accumulate small deltas
scrollAccumulator += deltaY; scrollAccumulator += deltaY
if (Math.abs(scrollAccumulator) >= touchpadThreshold) { if (Math.abs(scrollAccumulator) >= touchpadThreshold) {
let currentIndex = -1; let currentIndex = -1
for (let i = 0; i < windows.length; i++) { for (var i = 0; i < windows.length; i++) {
if (windows[i].activated) { if (windows[i].activated) {
currentIndex = i; currentIndex = i
break; break
} }
} }
let nextIndex; let nextIndex
if (scrollAccumulator < 0) { if (scrollAccumulator < 0) {
if (currentIndex === -1) { if (currentIndex === -1) {
nextIndex = 0; nextIndex = 0
} else { } else {
nextIndex = (currentIndex + 1) % windows.length; nextIndex = (currentIndex + 1) % windows.length
} }
} else { } else {
if (currentIndex === -1) { if (currentIndex === -1) {
nextIndex = windows.length - 1; nextIndex = windows.length - 1
} else { } else {
nextIndex = (currentIndex - 1 + windows.length) % windows.length; nextIndex = (currentIndex - 1 + windows.length) % windows.length
} }
} }
const nextWindow = windows[nextIndex]; const nextWindow = windows[nextIndex]
if (nextWindow) { if (nextWindow) {
nextWindow.activate(); nextWindow.activate()
} }
scrollAccumulator = 0; scrollAccumulator = 0
} }
} }
wheel.accepted = true; wheel.accepted = true
} }
} }
@@ -206,14 +212,13 @@ Item {
property var toplevelObject: toplevelData property var toplevelObject: toplevelData
property int windowCount: isGrouped ? modelData.windows.length : 1 property int windowCount: isGrouped ? modelData.windows.length : 1
property string tooltipText: { property string tooltipText: {
let appName = "Unknown"; let appName = "Unknown"
if (appId) { if (appId) {
const desktopEntry = DesktopEntries.heuristicLookup(appId); const desktopEntry = DesktopEntries.heuristicLookup(appId)
appName = desktopEntry appName = desktopEntry && desktopEntry.name ? desktopEntry.name : appId
&& desktopEntry.name ? desktopEntry.name : appId;
} }
if (isGrouped && windowCount > 1) { if (isGrouped && windowCount > 1) {
return appName + " (" + windowCount + " windows)"; return appName + " (" + windowCount + " windows)"
} }
return appName + (windowTitle ? " • " + windowTitle : "") return appName + (windowTitle ? " • " + windowTitle : "")
} }
@@ -230,21 +235,9 @@ Item {
radius: Theme.cornerRadius radius: Theme.cornerRadius
color: { color: {
if (isFocused) { if (isFocused) {
return mouseArea.containsMouse ? Qt.rgba( return mouseArea.containsMouse ? Qt.rgba(Theme.primary.r, Theme.primary.g, Theme.primary.b, 0.3) : Qt.rgba(Theme.primary.r, Theme.primary.g, Theme.primary.b, 0.2)
Theme.primary.r,
Theme.primary.g,
Theme.primary.b,
0.3) : Qt.rgba(
Theme.primary.r,
Theme.primary.g,
Theme.primary.b,
0.2);
} else { } else {
return mouseArea.containsMouse ? Qt.rgba( return mouseArea.containsMouse ? Qt.rgba(Theme.primaryHover.r, Theme.primaryHover.g, Theme.primaryHover.b, 0.1) : "transparent"
Theme.primaryHover.r,
Theme.primaryHover.g,
Theme.primaryHover.b,
0.1) : "transparent";
} }
} }
@@ -292,15 +285,15 @@ Item {
} }
text: { text: {
if (!appId) { if (!appId) {
return "?"; return "?"
} }
const desktopEntry = DesktopEntries.heuristicLookup(appId); const desktopEntry = DesktopEntries.heuristicLookup(appId)
if (desktopEntry && desktopEntry.name) { if (desktopEntry && desktopEntry.name) {
return desktopEntry.name.charAt(0).toUpperCase(); return desktopEntry.name.charAt(0).toUpperCase()
} }
return appId.charAt(0).toUpperCase(); return appId.charAt(0).toUpperCase()
} }
font.pixelSize: 10 font.pixelSize: 10
color: Theme.surfaceText color: Theme.surfaceText
@@ -351,66 +344,74 @@ Item {
hoverEnabled: true hoverEnabled: true
cursorShape: Qt.PointingHandCursor cursorShape: Qt.PointingHandCursor
acceptedButtons: Qt.LeftButton | Qt.RightButton acceptedButtons: Qt.LeftButton | Qt.RightButton
onClicked: (mouse) => { onClicked: mouse => {
if (mouse.button === Qt.LeftButton) { if (mouse.button === Qt.LeftButton) {
if (isGrouped && windowCount > 1) { if (isGrouped && windowCount > 1) {
let currentIndex = -1; let currentIndex = -1
for (let i = 0; i < groupData.windows.length; i++) { for (var i = 0; i < groupData.windows.length; i++) {
if (groupData.windows[i].toplevel.activated) { if (groupData.windows[i].toplevel.activated) {
currentIndex = i; currentIndex = i
break; break
} }
} }
const nextIndex = (currentIndex + 1) % groupData.windows.length; const nextIndex = (currentIndex + 1) % groupData.windows.length
groupData.windows[nextIndex].toplevel.activate(); groupData.windows[nextIndex].toplevel.activate()
} else if (toplevelObject) { } else if (toplevelObject) {
toplevelObject.activate(); toplevelObject.activate()
} }
} else if (mouse.button === Qt.RightButton) { } else if (mouse.button === Qt.RightButton) {
if (tooltipLoader.item) { if (tooltipLoader.item) {
tooltipLoader.item.hide(); tooltipLoader.item.hide()
} }
tooltipLoader.active = false; tooltipLoader.active = false
windowContextMenuLoader.active = true; windowContextMenuLoader.active = true
if (windowContextMenuLoader.item) { if (windowContextMenuLoader.item) {
windowContextMenuLoader.item.currentWindow = toplevelObject; windowContextMenuLoader.item.currentWindow = toplevelObject
const globalPos = delegateItem.mapToGlobal(delegateItem.width / 2, 0); if (root.isVertical) {
const screenX = root.parentScreen ? root.parentScreen.x : 0; const globalPos = delegateItem.mapToGlobal(delegateItem.width / 2, delegateItem.height / 2)
const screenY = root.parentScreen ? root.parentScreen.y : 0; const screenX = root.parentScreen ? root.parentScreen.x : 0
const relativeX = globalPos.x - screenX; const screenY = root.parentScreen ? root.parentScreen.y : 0
const yPos = root.isVertical ? delegateItem.height / 2 : (Theme.barHeight + SettingsData.dankBarSpacing - 7); const relativeY = globalPos.y - screenY
windowContextMenuLoader.item.showAt(relativeX, yPos); const xPos = root.axis?.edge === "left" ? (Theme.barHeight + SettingsData.dankBarSpacing + Theme.spacingXS) : (root.parentScreen.width - Theme.barHeight - SettingsData.dankBarSpacing - Theme.spacingXS)
windowContextMenuLoader.item.showAt(xPos, relativeY, true, root.axis?.edge)
} else {
const globalPos = delegateItem.mapToGlobal(delegateItem.width / 2, 0)
const screenX = root.parentScreen ? root.parentScreen.x : 0
const relativeX = globalPos.x - screenX
const yPos = Theme.barHeight + SettingsData.dankBarSpacing - 7
windowContextMenuLoader.item.showAt(relativeX, yPos, false, "top")
}
} }
} }
} }
onEntered: { onEntered: {
root.hoveredItem = delegateItem; root.hoveredItem = delegateItem
tooltipLoader.active = true; tooltipLoader.active = true
if (tooltipLoader.item) { if (tooltipLoader.item) {
if (root.isVertical) { if (root.isVertical) {
const globalPos = delegateItem.mapToGlobal(delegateItem.width / 2, delegateItem.height / 2); const globalPos = delegateItem.mapToGlobal(delegateItem.width / 2, delegateItem.height / 2)
const screenX = root.parentScreen ? root.parentScreen.x : 0; const screenX = root.parentScreen ? root.parentScreen.x : 0
const screenY = root.parentScreen ? root.parentScreen.y : 0; const screenY = root.parentScreen ? root.parentScreen.y : 0
const relativeY = globalPos.y - screenY; const relativeY = globalPos.y - screenY
const tooltipX = root.axis?.edge === "left" ? (Theme.barHeight + SettingsData.dankBarSpacing + Theme.spacingXS) : (root.parentScreen.width - Theme.barHeight - SettingsData.dankBarSpacing - Theme.spacingXS); const tooltipX = root.axis?.edge === "left" ? (Theme.barHeight + SettingsData.dankBarSpacing + Theme.spacingXS) : (root.parentScreen.width - Theme.barHeight - SettingsData.dankBarSpacing - Theme.spacingXS)
const isLeft = root.axis?.edge === "left"; const isLeft = root.axis?.edge === "left"
tooltipLoader.item.show(delegateItem.tooltipText, screenX + tooltipX, relativeY, root.parentScreen, isLeft, !isLeft); tooltipLoader.item.show(delegateItem.tooltipText, screenX + tooltipX, relativeY, root.parentScreen, isLeft, !isLeft)
} else { } else {
const globalPos = delegateItem.mapToGlobal(delegateItem.width / 2, delegateItem.height); const globalPos = delegateItem.mapToGlobal(delegateItem.width / 2, delegateItem.height)
const tooltipY = Theme.barHeight + SettingsData.dankBarSpacing + Theme.spacingXS; const tooltipY = Theme.barHeight + SettingsData.dankBarSpacing + Theme.spacingXS
tooltipLoader.item.show(delegateItem.tooltipText, globalPos.x, tooltipY, root.parentScreen, false, false); tooltipLoader.item.show(delegateItem.tooltipText, globalPos.x, tooltipY, root.parentScreen, false, false)
} }
} }
} }
onExited: { onExited: {
if (root.hoveredItem === delegateItem) { if (root.hoveredItem === delegateItem) {
root.hoveredItem = null; root.hoveredItem = null
if (tooltipLoader.item) { if (tooltipLoader.item) {
tooltipLoader.item.hide(); tooltipLoader.item.hide()
} }
tooltipLoader.active = false; tooltipLoader.active = false
} }
} }
} }
@@ -440,14 +441,13 @@ Item {
property var toplevelObject: toplevelData property var toplevelObject: toplevelData
property int windowCount: isGrouped ? modelData.windows.length : 1 property int windowCount: isGrouped ? modelData.windows.length : 1
property string tooltipText: { property string tooltipText: {
let appName = "Unknown"; let appName = "Unknown"
if (appId) { if (appId) {
const desktopEntry = DesktopEntries.heuristicLookup(appId); const desktopEntry = DesktopEntries.heuristicLookup(appId)
appName = desktopEntry appName = desktopEntry && desktopEntry.name ? desktopEntry.name : appId
&& desktopEntry.name ? desktopEntry.name : appId;
} }
if (isGrouped && windowCount > 1) { if (isGrouped && windowCount > 1) {
return appName + " (" + windowCount + " windows)"; return appName + " (" + windowCount + " windows)"
} }
return appName + (windowTitle ? " • " + windowTitle : "") return appName + (windowTitle ? " • " + windowTitle : "")
} }
@@ -464,21 +464,9 @@ Item {
radius: Theme.cornerRadius radius: Theme.cornerRadius
color: { color: {
if (isFocused) { if (isFocused) {
return mouseArea.containsMouse ? Qt.rgba( return mouseArea.containsMouse ? Qt.rgba(Theme.primary.r, Theme.primary.g, Theme.primary.b, 0.3) : Qt.rgba(Theme.primary.r, Theme.primary.g, Theme.primary.b, 0.2)
Theme.primary.r,
Theme.primary.g,
Theme.primary.b,
0.3) : Qt.rgba(
Theme.primary.r,
Theme.primary.g,
Theme.primary.b,
0.2);
} else { } else {
return mouseArea.containsMouse ? Qt.rgba( return mouseArea.containsMouse ? Qt.rgba(Theme.primaryHover.r, Theme.primaryHover.g, Theme.primaryHover.b, 0.1) : "transparent"
Theme.primaryHover.r,
Theme.primaryHover.g,
Theme.primaryHover.b,
0.1) : "transparent";
} }
} }
@@ -524,15 +512,15 @@ Item {
} }
text: { text: {
if (!appId) { if (!appId) {
return "?"; return "?"
} }
const desktopEntry = DesktopEntries.heuristicLookup(appId); const desktopEntry = DesktopEntries.heuristicLookup(appId)
if (desktopEntry && desktopEntry.name) { if (desktopEntry && desktopEntry.name) {
return desktopEntry.name.charAt(0).toUpperCase(); return desktopEntry.name.charAt(0).toUpperCase()
} }
return appId.charAt(0).toUpperCase(); return appId.charAt(0).toUpperCase()
} }
font.pixelSize: 10 font.pixelSize: 10
color: Theme.surfaceText color: Theme.surfaceText
@@ -582,66 +570,74 @@ Item {
hoverEnabled: true hoverEnabled: true
cursorShape: Qt.PointingHandCursor cursorShape: Qt.PointingHandCursor
acceptedButtons: Qt.LeftButton | Qt.RightButton acceptedButtons: Qt.LeftButton | Qt.RightButton
onClicked: (mouse) => { onClicked: mouse => {
if (mouse.button === Qt.LeftButton) { if (mouse.button === Qt.LeftButton) {
if (isGrouped && windowCount > 1) { if (isGrouped && windowCount > 1) {
let currentIndex = -1; let currentIndex = -1
for (let i = 0; i < groupData.windows.length; i++) { for (var i = 0; i < groupData.windows.length; i++) {
if (groupData.windows[i].toplevel.activated) { if (groupData.windows[i].toplevel.activated) {
currentIndex = i; currentIndex = i
break; break
} }
} }
const nextIndex = (currentIndex + 1) % groupData.windows.length; const nextIndex = (currentIndex + 1) % groupData.windows.length
groupData.windows[nextIndex].toplevel.activate(); groupData.windows[nextIndex].toplevel.activate()
} else if (toplevelObject) { } else if (toplevelObject) {
toplevelObject.activate(); toplevelObject.activate()
} }
} else if (mouse.button === Qt.RightButton) { } else if (mouse.button === Qt.RightButton) {
if (tooltipLoader.item) { if (tooltipLoader.item) {
tooltipLoader.item.hide(); tooltipLoader.item.hide()
} }
tooltipLoader.active = false; tooltipLoader.active = false
windowContextMenuLoader.active = true; windowContextMenuLoader.active = true
if (windowContextMenuLoader.item) { if (windowContextMenuLoader.item) {
windowContextMenuLoader.item.currentWindow = toplevelObject; windowContextMenuLoader.item.currentWindow = toplevelObject
const globalPos = delegateItem.mapToGlobal(delegateItem.width / 2, 0); if (root.isVertical) {
const screenX = root.parentScreen ? root.parentScreen.x : 0; const globalPos = delegateItem.mapToGlobal(delegateItem.width / 2, delegateItem.height / 2)
const screenY = root.parentScreen ? root.parentScreen.y : 0; const screenX = root.parentScreen ? root.parentScreen.x : 0
const relativeX = globalPos.x - screenX; const screenY = root.parentScreen ? root.parentScreen.y : 0
const yPos = root.isVertical ? delegateItem.height / 2 : (Theme.barHeight + SettingsData.dankBarSpacing - 7); const relativeY = globalPos.y - screenY
windowContextMenuLoader.item.showAt(relativeX, yPos); const xPos = root.axis?.edge === "left" ? (Theme.barHeight + SettingsData.dankBarSpacing + Theme.spacingXS) : (root.parentScreen.width - Theme.barHeight - SettingsData.dankBarSpacing - Theme.spacingXS)
windowContextMenuLoader.item.showAt(xPos, relativeY, true, root.axis?.edge)
} else {
const globalPos = delegateItem.mapToGlobal(delegateItem.width / 2, 0)
const screenX = root.parentScreen ? root.parentScreen.x : 0
const relativeX = globalPos.x - screenX
const yPos = Theme.barHeight + SettingsData.dankBarSpacing - 7
windowContextMenuLoader.item.showAt(relativeX, yPos, false, "top")
}
} }
} }
} }
onEntered: { onEntered: {
root.hoveredItem = delegateItem; root.hoveredItem = delegateItem
tooltipLoader.active = true; tooltipLoader.active = true
if (tooltipLoader.item) { if (tooltipLoader.item) {
if (root.isVertical) { if (root.isVertical) {
const globalPos = delegateItem.mapToGlobal(delegateItem.width / 2, delegateItem.height / 2); const globalPos = delegateItem.mapToGlobal(delegateItem.width / 2, delegateItem.height / 2)
const screenX = root.parentScreen ? root.parentScreen.x : 0; const screenX = root.parentScreen ? root.parentScreen.x : 0
const screenY = root.parentScreen ? root.parentScreen.y : 0; const screenY = root.parentScreen ? root.parentScreen.y : 0
const relativeY = globalPos.y - screenY; const relativeY = globalPos.y - screenY
const tooltipX = root.axis?.edge === "left" ? (Theme.barHeight + SettingsData.dankBarSpacing + Theme.spacingXS) : (root.parentScreen.width - Theme.barHeight - SettingsData.dankBarSpacing - Theme.spacingXS); const tooltipX = root.axis?.edge === "left" ? (Theme.barHeight + SettingsData.dankBarSpacing + Theme.spacingXS) : (root.parentScreen.width - Theme.barHeight - SettingsData.dankBarSpacing - Theme.spacingXS)
const isLeft = root.axis?.edge === "left"; const isLeft = root.axis?.edge === "left"
tooltipLoader.item.show(delegateItem.tooltipText, screenX + tooltipX, relativeY, root.parentScreen, isLeft, !isLeft); tooltipLoader.item.show(delegateItem.tooltipText, screenX + tooltipX, relativeY, root.parentScreen, isLeft, !isLeft)
} else { } else {
const globalPos = delegateItem.mapToGlobal(delegateItem.width / 2, delegateItem.height); const globalPos = delegateItem.mapToGlobal(delegateItem.width / 2, delegateItem.height)
const tooltipY = Theme.barHeight + SettingsData.dankBarSpacing + Theme.spacingXS; const tooltipY = Theme.barHeight + SettingsData.dankBarSpacing + Theme.spacingXS
tooltipLoader.item.show(delegateItem.tooltipText, globalPos.x, tooltipY, root.parentScreen, false, false); tooltipLoader.item.show(delegateItem.tooltipText, globalPos.x, tooltipY, root.parentScreen, false, false)
} }
} }
} }
onExited: { onExited: {
if (root.hoveredItem === delegateItem) { if (root.hoveredItem === delegateItem) {
root.hoveredItem = null; root.hoveredItem = null
if (tooltipLoader.item) { if (tooltipLoader.item) {
tooltipLoader.item.hide(); tooltipLoader.item.hide()
} }
tooltipLoader.active = false; tooltipLoader.active = false
} }
} }
} }
@@ -667,18 +663,22 @@ Item {
property var currentWindow: null property var currentWindow: null
property bool isVisible: false property bool isVisible: false
property point anchorPos: Qt.point(0, 0) property point anchorPos: Qt.point(0, 0)
property bool isVertical: false
property string edge: "top"
function showAt(x, y) { function showAt(x, y, vertical, barEdge) {
screen = root.parentScreen; screen = root.parentScreen
anchorPos = Qt.point(x, y); anchorPos = Qt.point(x, y)
isVisible = true; isVertical = vertical ?? false
visible = true; edge = barEdge ?? "top"
isVisible = true
visible = true
} }
function close() { function close() {
isVisible = false; isVisible = false
visible = false; visible = false
windowContextMenuLoader.active = false; windowContextMenuLoader.active = false
} }
implicitWidth: 100 implicitWidth: 100
@@ -699,17 +699,34 @@ Item {
MouseArea { MouseArea {
anchors.fill: parent anchors.fill: parent
onClicked: contextMenuWindow.close(); onClicked: contextMenuWindow.close()
} }
Rectangle { Rectangle {
x: { x: {
const left = 10; if (contextMenuWindow.isVertical) {
const right = contextMenuWindow.width - width - 10; if (contextMenuWindow.edge === "left") {
const want = contextMenuWindow.anchorPos.x - width / 2; return Math.min(contextMenuWindow.width - width - 10, contextMenuWindow.anchorPos.x)
return Math.max(left, Math.min(right, want)); } else {
return Math.max(10, contextMenuWindow.anchorPos.x - width)
}
} else {
const left = 10
const right = contextMenuWindow.width - width - 10
const want = contextMenuWindow.anchorPos.x - width / 2
return Math.max(left, Math.min(right, want))
}
}
y: {
if (contextMenuWindow.isVertical) {
const top = 10
const bottom = contextMenuWindow.height - height - 10
const want = contextMenuWindow.anchorPos.y - height / 2
return Math.max(top, Math.min(bottom, want))
} else {
return contextMenuWindow.anchorPos.y
}
} }
y: contextMenuWindow.anchorPos.y
width: 100 width: 100
height: 32 height: 32
color: Theme.popupBackground() color: Theme.popupBackground()
@@ -738,9 +755,9 @@ Item {
cursorShape: Qt.PointingHandCursor cursorShape: Qt.PointingHandCursor
onClicked: { onClicked: {
if (contextMenuWindow.currentWindow) { if (contextMenuWindow.currentWindow) {
contextMenuWindow.currentWindow.close(); contextMenuWindow.currentWindow.close()
} }
contextMenuWindow.close(); contextMenuWindow.close()
} }
} }
} }