forked from Shinonome/dots-hyprland
119 lines
3.5 KiB
QML
119 lines
3.5 KiB
QML
pragma ComponentBehavior: Bound
|
|
import QtQuick
|
|
import Quickshell
|
|
import Quickshell.Services.SystemTray
|
|
import Quickshell.Widgets
|
|
import Qt5Compat.GraphicalEffects
|
|
import qs.services
|
|
import qs.modules.common
|
|
import qs.modules.common.widgets
|
|
import qs.modules.common.functions
|
|
|
|
ButtonMouseArea {
|
|
id: root
|
|
required property SystemTrayItem item
|
|
property bool targetMenuOpen: false
|
|
|
|
signal menuOpened(qsWindow: var)
|
|
signal menuClosed()
|
|
|
|
hoverEnabled: true
|
|
acceptedButtons: Qt.LeftButton | Qt.RightButton
|
|
property real iconSize: 20
|
|
property real backgroundSize: 26
|
|
implicitWidth: iconSize
|
|
implicitHeight: iconSize
|
|
onPressed: (event) => {
|
|
switch (event.button) {
|
|
case Qt.LeftButton:
|
|
item.activate();
|
|
break;
|
|
case Qt.RightButton:
|
|
if (item.hasMenu)
|
|
if (menu.active && menu.item && typeof menu.item.close === "function")
|
|
menu.item.close();
|
|
else
|
|
menu.open();
|
|
break;
|
|
}
|
|
event.accepted = true;
|
|
}
|
|
onEntered: {
|
|
tooltip.text = TrayService.getTooltipForItem(root.item);
|
|
}
|
|
|
|
StateOverlay {
|
|
id: hoverOverlay
|
|
anchors.centerIn: parent
|
|
width: root.backgroundSize
|
|
height: root.backgroundSize
|
|
radius: root.backgroundSize / 2
|
|
hover: root.containsMouse
|
|
press: root.containsPress
|
|
}
|
|
|
|
Loader {
|
|
id: menu
|
|
function open() {
|
|
menu.active = true;
|
|
}
|
|
active: false
|
|
sourceComponent: SysTrayMenu {
|
|
Component.onCompleted: this.open();
|
|
trayItemMenuHandle: root.item.menu
|
|
trayItemId: root.item.id
|
|
anchor {
|
|
window: root.QsWindow.window
|
|
item: root
|
|
gravity: Config.options.bar.vertical
|
|
? (Config.options.bar.bottom ? Edges.Left : Edges.Right)
|
|
: (Config.options.bar.bottom ? Edges.Top : Edges.Bottom)
|
|
edges: Config.options.bar.vertical
|
|
? (Config.options.bar.bottom ? Edges.Left : Edges.Right)
|
|
: (Config.options.bar.bottom ? Edges.Top : Edges.Bottom)
|
|
}
|
|
onMenuOpened: (window) => root.menuOpened(window);
|
|
onMenuClosed: {
|
|
root.menuClosed();
|
|
menu.active = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
IconImage {
|
|
id: trayIcon
|
|
visible: !Config.options.tray.monochromeIcons
|
|
source: root.item.icon
|
|
anchors.centerIn: parent
|
|
width: root.iconSize
|
|
height: root.iconSize
|
|
}
|
|
|
|
Loader {
|
|
active: Config.options.tray.monochromeIcons
|
|
anchors.fill: trayIcon
|
|
sourceComponent: Item {
|
|
Desaturate {
|
|
id: desaturatedIcon
|
|
visible: false // There's already color overlay
|
|
anchors.fill: parent
|
|
source: trayIcon
|
|
desaturation: 0.8 // 1.0 means fully grayscale
|
|
}
|
|
ColorOverlay {
|
|
anchors.fill: desaturatedIcon
|
|
source: desaturatedIcon
|
|
color: ColorUtils.transparentize(Appearance.colors.colOnLayer0, 0.9)
|
|
}
|
|
}
|
|
}
|
|
|
|
PopupToolTip {
|
|
id: tooltip
|
|
extraVisibleCondition: root.containsMouse
|
|
alternativeVisibleCondition: extraVisibleCondition
|
|
anchorEdges: (!Config.options.bar.bottom && !Config.options.bar.vertical) ? Edges.Bottom : Edges.Top
|
|
}
|
|
|
|
}
|