mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2025-12-06 21:45:38 -05:00
native tray menu
This commit is contained in:
@@ -1,13 +1,15 @@
|
||||
import QtQuick
|
||||
import Quickshell
|
||||
import Quickshell.Services.SystemTray
|
||||
import qs.Common
|
||||
|
||||
Rectangle {
|
||||
id: root
|
||||
|
||||
property var parentWindow: null
|
||||
|
||||
readonly property int calculatedWidth: SystemTray.items.values.length > 0 ? SystemTray.items.values.length * 24 + (SystemTray.items.values.length - 1) * Theme.spacingXS + Theme.spacingS * 2 : 0
|
||||
|
||||
signal menuRequested(var menu, var item, real x, real y)
|
||||
|
||||
width: calculatedWidth
|
||||
height: 30
|
||||
@@ -84,16 +86,21 @@ Rectangle {
|
||||
cursorShape: Qt.PointingHandCursor
|
||||
onClicked: (mouse) => {
|
||||
if (!trayItem)
|
||||
return ;
|
||||
return
|
||||
|
||||
if (mouse.button === Qt.LeftButton) {
|
||||
if (!trayItem.onlyMenu)
|
||||
trayItem.activate();
|
||||
|
||||
trayItem.activate()
|
||||
} else if (mouse.button === Qt.RightButton) {
|
||||
if (trayItem && trayItem.hasMenu)
|
||||
root.menuRequested(null, trayItem, mouse.x, mouse.y);
|
||||
|
||||
if (trayItem.hasMenu) {
|
||||
var globalPos = mapToGlobal(0, 0)
|
||||
var currentScreen = Screen
|
||||
var screenX = currentScreen.x || 0
|
||||
var relativeX = globalPos.x - screenX
|
||||
menuAnchor.menu = trayItem.menu
|
||||
menuAnchor.anchor.window = parentWindow
|
||||
menuAnchor.anchor.rect = Qt.rect(relativeX, Theme.barHeight + Theme.spacingS, parent.width, 1)
|
||||
menuAnchor.open()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -104,4 +111,8 @@ Rectangle {
|
||||
|
||||
}
|
||||
|
||||
QsMenuAnchor {
|
||||
id: menuAnchor
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user