mirror of
https://github.com/kittywitch/nixfiles.git
synced 2026-02-09 20:39:18 -08:00
feat: battery, refactor
This commit is contained in:
parent
9ae22c832f
commit
1ba98534eb
15 changed files with 122 additions and 6 deletions
122
quickshell/Components/SystemTray/SystemTray.qml
Normal file
122
quickshell/Components/SystemTray/SystemTray.qml
Normal file
|
|
@ -0,0 +1,122 @@
|
|||
import QtQuick
|
||||
import QtQuick.Layouts
|
||||
import Quickshell
|
||||
import QtQuick.Controls
|
||||
import Quickshell.Widgets
|
||||
import Quickshell.Services.SystemTray
|
||||
import "root:/DataSources"
|
||||
|
||||
RowLayout {
|
||||
id: systray
|
||||
|
||||
anchors.centerIn: parent
|
||||
Layout.alignment: Qt.AlignCenter
|
||||
property string openItemId
|
||||
|
||||
Repeater {
|
||||
model: SystemTray.items
|
||||
|
||||
delegate: Item {
|
||||
id: delegateItem
|
||||
required property SystemTrayItem modelData
|
||||
|
||||
width: 24
|
||||
height: 24
|
||||
|
||||
IconImage {
|
||||
source: modelData.icon
|
||||
width: 20
|
||||
height: 20
|
||||
anchors.centerIn: parent
|
||||
}
|
||||
|
||||
MouseArea {
|
||||
id: ma
|
||||
anchors.fill: parent
|
||||
hoverEnabled: true
|
||||
|
||||
onClicked: function(mouseEvent) {
|
||||
var m = delegateItem.QsWindow.mapFromItem(delegateItem, delegateItem.width/2.0, delegateItem.height/2.0);
|
||||
var offset = popupLoader.item.width / 2.0;
|
||||
popupLoader.clicky = m.x - offset;
|
||||
if (openItemId == modelData.id) {
|
||||
openItemId = null
|
||||
} else {
|
||||
openItemId = modelData.id
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QsMenuOpener {
|
||||
id: menu
|
||||
menu: modelData.menu
|
||||
}
|
||||
|
||||
LazyLoader {
|
||||
id: popupLoader
|
||||
|
||||
property real clicky
|
||||
|
||||
loading: true
|
||||
|
||||
PopupWindow {
|
||||
id: popup
|
||||
anchor.window: delegateItem.QsWindow.window
|
||||
anchor.rect.x: popupLoader.clicky
|
||||
anchor.rect.y: if (visible) { parentWindow.height } else { systray.height }
|
||||
|
||||
visible: openItemId == modelData.id
|
||||
color: "transparent"
|
||||
|
||||
property real childHeight: 5
|
||||
|
||||
implicitWidth: 300
|
||||
implicitHeight: childHeight
|
||||
|
||||
Rectangle {
|
||||
anchors.fill: parent
|
||||
color: Stylix.base02
|
||||
radius: 5
|
||||
}
|
||||
|
||||
ListView {
|
||||
model: menu.children
|
||||
|
||||
anchors {
|
||||
top: parent.top
|
||||
topMargin: 5
|
||||
bottom: parent.bottom
|
||||
bottomMargin: 5
|
||||
}
|
||||
|
||||
width: parent.width
|
||||
height: parent.height
|
||||
spacing: 5
|
||||
|
||||
ScrollBar.horizontal: ScrollBar {}
|
||||
|
||||
delegate: Loader {
|
||||
required property QsMenuHandle modelData
|
||||
id: trayItemLoader
|
||||
|
||||
width: parent.width
|
||||
|
||||
Component.onCompleted: {
|
||||
if (modelData.text != null && modelData.text != "") {
|
||||
trayItemLoader.setSource("SystemTrayButton.qml", {
|
||||
"modelData": modelData,
|
||||
})
|
||||
childHeight += 30
|
||||
} else {
|
||||
trayItemLoader.setSource("SystemTraySeparator.qml", {})
|
||||
childHeight += 2
|
||||
}
|
||||
childHeight += 5
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
47
quickshell/Components/SystemTray/SystemTrayButton.qml
Normal file
47
quickshell/Components/SystemTray/SystemTrayButton.qml
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
import QtQuick
|
||||
import QtQuick.Layouts
|
||||
import Quickshell
|
||||
import QtQuick.Controls
|
||||
import Quickshell.Widgets
|
||||
import Quickshell.Services.SystemTray
|
||||
import "root:/DataSources"
|
||||
|
||||
Item {
|
||||
required property QsMenuHandle modelData
|
||||
|
||||
width: parent.width
|
||||
height: 30
|
||||
|
||||
Rectangle {
|
||||
anchors {
|
||||
fill: parent
|
||||
leftMargin: 5
|
||||
rightMargin: 5
|
||||
}
|
||||
|
||||
color: Stylix.base01
|
||||
radius: 5
|
||||
|
||||
Text {
|
||||
anchors {
|
||||
centerIn: parent
|
||||
}
|
||||
width: parent.width - 10
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
text: modelData?.text ?? ""
|
||||
color: Stylix.base05
|
||||
font.pointSize: 12
|
||||
elide: Text.ElideRight
|
||||
}
|
||||
|
||||
MouseArea {
|
||||
anchors.fill: parent
|
||||
hoverEnabled: true
|
||||
|
||||
onClicked: mouse => {
|
||||
modelData.triggered();
|
||||
popup.visible = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
22
quickshell/Components/SystemTray/SystemTraySeparator.qml
Normal file
22
quickshell/Components/SystemTray/SystemTraySeparator.qml
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
import QtQuick
|
||||
import QtQuick.Layouts
|
||||
import Quickshell
|
||||
import QtQuick.Controls
|
||||
import Quickshell.Widgets
|
||||
import Quickshell.Services.SystemTray
|
||||
import "root:/DataSources"
|
||||
|
||||
Item {
|
||||
width: parent.width
|
||||
height: 2
|
||||
|
||||
Rectangle {
|
||||
anchors {
|
||||
fill: parent
|
||||
leftMargin: 5
|
||||
rightMargin: 5
|
||||
}
|
||||
color: Stylix.base00
|
||||
radius: 5
|
||||
}
|
||||
}
|
||||
50
quickshell/Components/SystemTray/SystemTrayWrapper.qml
Normal file
50
quickshell/Components/SystemTray/SystemTrayWrapper.qml
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
import QtQuick
|
||||
import QtQuick.Layouts
|
||||
import Quickshell
|
||||
import "root:/DataSources"
|
||||
|
||||
Item {
|
||||
id: root
|
||||
Layout.alignment: Qt.AlignVCenter;
|
||||
implicitWidth: 25
|
||||
implicitHeight: parent.height
|
||||
property list<string> textStates: ["", ""]
|
||||
Text {
|
||||
id: texty
|
||||
anchors.centerIn: parent
|
||||
text: textStates[0]
|
||||
color: Stylix.base05
|
||||
}
|
||||
MouseArea {
|
||||
id: ma
|
||||
anchors.fill: parent
|
||||
hoverEnabled: true
|
||||
|
||||
onClicked: function(mouseEvent) {
|
||||
var m = root.QsWindow.mapFromItem(ma, ma.width/2.0, ma.height/2.0);
|
||||
var offset = wrapperPopup.width / 2.0;
|
||||
wrapperPopup.clicky = m.x - offset;
|
||||
wrapperPopup.visible = !wrapperPopup.visible;
|
||||
|
||||
texty.text = root.textStates[wrapperPopup.visible ? 1 : 0];
|
||||
}
|
||||
}
|
||||
PopupWindow {
|
||||
property real clicky
|
||||
id: wrapperPopup
|
||||
anchor.window: root.QsWindow.window
|
||||
anchor.rect.y: parentWindow?.height ?? 0
|
||||
anchor.rect.x: clicky
|
||||
implicitWidth: systray.width + 10
|
||||
implicitHeight: systray?.height + 10
|
||||
color: "transparent"
|
||||
Rectangle {
|
||||
anchors.fill: parent
|
||||
color: Stylix.base01
|
||||
radius: 5
|
||||
SystemTray {
|
||||
id: systray
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue