port all settings to a settings singleton to make it easier to make a settings ui later on

This commit is contained in:
lucy 2025-12-28 13:25:31 +01:00
parent 60b95f221b
commit 484e1a8143
18 changed files with 129 additions and 166 deletions

View File

@ -1,7 +0,0 @@
pragma Singleton
import QtQuick
QtObject {
readonly property string font: "CommitMono Nerd Font Propo"
readonly property real fontSize: 14
}

View File

@ -5,25 +5,25 @@ import Quickshell
Singleton { Singleton {
id: customColors id: customColors
// Core Backgrounds // Core Backgrounds
readonly property color background: "#272E33" readonly property color background: "#0A0E14"
readonly property color foreground: "#D3C6AA" readonly property color foreground: "#B3B1AD"
readonly property color cursor: "#D3C6AA" readonly property color cursor: "#E6B450"
// The 16 Colors of the Apocalypse // The 16 Colors of the Apocalypse
readonly property color color0: "#2E383C" readonly property color color0: "#0A0E14"
readonly property color color1: "#E67E80" readonly property color color1: "#FF3333"
readonly property color color2: "#A7C080" readonly property color color2: "#C2D94C"
readonly property color color3: "#DBBC7F" readonly property color color3: "#FF8F40"
readonly property color color4: "#7FBBB3" readonly property color color4: "#59C2FF"
readonly property color color5: "#D699B6" readonly property color color5: "#FFEE99"
readonly property color color6: "#83C092" readonly property color color6: "#95E6CB"
readonly property color color7: "#D3C6AA" readonly property color color7: "#B3B1AD"
readonly property color color8: "#5C6A72" readonly property color color8: "#4D5566"
readonly property color color9: "#F85552" readonly property color color9: "#FF3333"
readonly property color color10: "#8DA101" readonly property color color10: "#C2D94C"
readonly property color color11: "#DFA000" readonly property color color11: "#FF8F40"
readonly property color color12: "#3A94C5" readonly property color color12: "#59C2FF"
readonly property color color13: "#DF69BA" readonly property color color13: "#FFEE99"
readonly property color color14: "#35A77C" readonly property color color14: "#95E6CB"
readonly property color color15: "#DFDDC8" readonly property color color15: "#B3B1AD"
} }

View File

@ -2,11 +2,12 @@ import Quickshell
import QtQuick import QtQuick
import QtQuick.Layouts import QtQuick.Layouts
import qs import qs
import "../../"
PanelWindow { PanelWindow {
id: root id: root
required property var modelData required property var modelData
implicitHeight: 30 implicitHeight: 35
//color: Colors.background //color: Colors.background
color: Colors.background color: Colors.background
anchors { anchors {

View File

@ -1,8 +0,0 @@
import Quickshell
import QtQuick
import QtQuick.Layouts
RowLayout {
id: leftLayout
anchors.left: parent.left
}

View File

@ -1,8 +1,8 @@
import Quickshell.Services.UPower import Quickshell.Services.UPower
import QtQuick import QtQuick
import Quickshell.Widgets import Quickshell.Widgets
import "." import "../../"
import qs import "../settings/"
Item { Item {
id: root id: root
@ -22,8 +22,8 @@ Item {
id: batteryText id: batteryText
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
font.weight: 900 font.weight: 900
font.family: Appearance.font font.family: Settings.font
font.pixelSize: Appearance.fontSize font.pixelSize: Settings.fontSize
color: Colors.foreground color: Colors.foreground
text: Math.round(UPower.displayDevice.percentage * 100) + "%" text: Math.round(UPower.displayDevice.percentage * 100) + "%"
} }

View File

@ -1,26 +1,47 @@
import QtQuick import QtQuick
import Quickshell import Quickshell
import qs import QtQuick.Layouts
import "../settings/"
import "../../"
Item { Item {
id: root id: root
// FIX: Real pixels please! implicitWidth: clockLayout.implicitWidth
implicitWidth: clockText.implicitWidth implicitHeight: 35
implicitHeight: 30
Text { ColumnLayout {
id: clockText id: clockLayout
anchors.centerIn: parent anchors.centerIn: parent
font.weight: 900 spacing: 0
font.family: Appearance.font
font.pixelSize: Appearance.fontSize
color: Colors.foreground
text: Qt.formatDateTime(clock.date, "hh:mm") Text {
id: clockHoursText
font.weight: 900
font.family: Settings.font
font.pixelSize: Settings.fontSize
color: Colors.foreground
SystemClock { text: Qt.formatDateTime(clockHours.date, "hh:mm")
id: clock
precision: SystemClock.Minutes SystemClock {
id: clockHours
precision: SystemClock.Minutes
}
}
Text {
id: clockDateText
font.weight: 900
opacity: 0.7
font.family: Settings.font
font.pixelSize: Settings.fontSize - 2
color: Colors.foreground
text: Qt.formatDateTime(clockDate.date, "d.m.yy")
SystemClock {
id: clockDate
precision: SystemClock.Minutes
}
} }
} }
} }

View File

@ -5,7 +5,9 @@ import QtQuick
import QtQuick.Layouts import QtQuick.Layouts
import Quickshell import Quickshell
import Quickshell.Services.Mpris import Quickshell.Services.Mpris
import qs import Quickshell.Widgets
import "../settings/"
import "../../"
RowLayout { RowLayout {
id: root id: root
@ -16,6 +18,7 @@ RowLayout {
model: Mpris.players model: Mpris.players
delegate: RowLayout { delegate: RowLayout {
id: delegateLayout
required property var modelData required property var modelData
// 2. 🕵 FILTER LOGIC // 2. 🕵 FILTER LOGIC
// Check if this specific player is Spotify. // Check if this specific player is Spotify.
@ -39,26 +42,18 @@ RowLayout {
property string artUrl: modelData.trackArtUrl property string artUrl: modelData.trackArtUrl
property bool isPlaying: modelData.isPlaying property bool isPlaying: modelData.isPlaying
spacing: 8 spacing: 10
// 🖼 ALBUM ART // 🖼 ALBUM ART
Rectangle { ClippingWrapperRectangle {
Layout.preferredHeight: parent.height * 0.8
Layout.preferredWidth: Layout.preferredHeight
Layout.alignment: Qt.AlignVCenter Layout.alignment: Qt.AlignVCenter
radius: 4 radius: 20
color: Colors.background
clip: true
visible: parent.visible // Optimization
Image { IconImage {
anchors.fill: parent source: delegateLayout.artUrl // Access property from delegate
source: parent.parent.artUrl // Access property from delegate
fillMode: Image.PreserveAspectCrop
asynchronous: true asynchronous: true
sourceSize.width: 128 implicitSize: 24
sourceSize.height: 128
} }
} }
@ -69,66 +64,26 @@ RowLayout {
visible: parent.visible visible: parent.visible
Text { Text {
text: parent.parent.title text: delegateLayout.title
color: Colors.foreground color: Colors.foreground
font.bold: true font.bold: true
font.pixelSize: 12 font.pixelSize: Settings.fontSize
font.family: Settings.font
elide: Text.ElideRight elide: Text.ElideRight
Layout.preferredWidth: implicitWidth Layout.preferredWidth: implicitWidth
} }
Text { Text {
text: parent.parent.artist font.pixelSize: Settings.fontSize - 2
font.family: Settings.font
text: delegateLayout.artist
color: Colors.foreground color: Colors.foreground
opacity: 0.7 opacity: 0.7
font.pixelSize: 10
Layout.preferredWidth: implicitWidth Layout.preferredWidth: implicitWidth
} }
} }
// CONTROLS // CONTROLS
RowLayout {
Layout.alignment: Qt.AlignVCenter
spacing: 8
visible: parent.visible
// PREV
Text {
text: "󰒮"
color: Colors.foreground
font.pixelSize: 24
MouseArea {
anchors.fill: parent
// Use modelData to control THIS player
onClicked: modelData.previous()
cursorShape: Qt.PointingHandCursor
}
}
// PLAY / PAUSE
Text {
text: parent.parent.isPlaying ? "󰏤" : "󰐊"
color: Colors.foreground
font.pixelSize: 24
MouseArea {
anchors.fill: parent
onClicked: modelData.playPause()
cursorShape: Qt.PointingHandCursor
}
}
// NEXT
Text {
text: "󰒭"
color: Colors.foreground
font.pixelSize: 24
MouseArea {
anchors.fill: parent
onClicked: modelData.next()
cursorShape: Qt.PointingHandCursor
}
}
}
} }
} }
} }

View File

@ -1,6 +1,7 @@
import QtQuick import QtQuick
import Quickshell.Services.UPower import Quickshell.Services.UPower
import qs import "../settings/"
import "../../"
Item { Item {
id: root id: root
@ -10,11 +11,11 @@ Item {
text: PowerProfile.toString(PowerProfiles.profile) text: PowerProfile.toString(PowerProfiles.profile)
font.weight: 900 font.weight: 900
color: Colors.foreground color: Colors.foreground
font.family: Appearance.font font.family: Settings.font
font.pixelSize: Appearance.fontSize font.pixelSize: Settings.fontSize
anchors.centerIn: parent anchors.centerIn: parent
MouseArea { MouseArea {
cursorShape: Qt.PointingHandCursor cursorShape: Qt.PointingHandCursor
acceptedButtons: Qt.LeftButton | Qt.RightButton acceptedButtons: Qt.LeftButton | Qt.RightButton
anchors.fill: parent anchors.fill: parent
onClicked: mouse => { onClicked: mouse => {

View File

@ -3,6 +3,7 @@ import Quickshell.Services.Pipewire
import Quickshell.Widgets import Quickshell.Widgets
import Quickshell.Io import Quickshell.Io
import "../../" import "../../"
import "../settings/"
Item { Item {
id: root id: root
@ -69,8 +70,8 @@ Item {
width: 20 width: 20
font.weight: 900 font.weight: 900
color: Colors.foreground color: Colors.foreground
font.family: Appearance.font font.family: Settings.font
font.pixelSize: Appearance.fontSize font.pixelSize: Settings.fontSize
text: Pipewire.ready ? Math.round(Pipewire.defaultAudioSink.audio.volume * 100) + "%" : "0%" text: Pipewire.ready ? Math.round(Pipewire.defaultAudioSink.audio.volume * 100) + "%" : "0%"
} }
} }

View File

@ -2,6 +2,7 @@ pragma ComponentBehavior: Bound
import Quickshell.Hyprland import Quickshell.Hyprland
import QtQuick import QtQuick
import "../../" import "../../"
import "../settings/"
Item { Item {
id: root id: root
@ -26,8 +27,8 @@ Item {
Text { Text {
font.weight: 900 font.weight: 900
font.family: Appearance.font font.family: Settings.font
font.pixelSize: Appearance.fontSize font.pixelSize: Settings.fontSize
anchors.centerIn: workspaceNumber anchors.centerIn: workspaceNumber
text: parent.modelData.id text: parent.modelData.id
color: parent.modelData.active ? Colors.background : Colors.foreground // Set contrasting color for workspace number color: parent.modelData.active ? Colors.background : Colors.foreground // Set contrasting color for workspace number

View File

@ -0,0 +1,31 @@
pragma ComponentBehavior: Bound
pragma Singleton
import QtQuick
import Quickshell
import Quickshell.Io
Singleton {
id: store
FileView {
path: "/home/lucy/.cache/quickshell_settings.json"
onAdapterUpdated: writeAdapter()
watchChanges: true
onFileChanged: reload()
JsonAdapter {
id: adapter
property string lastWallpaper: "file:///home/lucy/.walls/mooon.png"
property string wallDir: "file:///home/lucy/.walls/"
property string font: "CodeNewRoman Nerd Font Propo"
property real fontSize: 14
}
}
property alias currentWall: adapter.lastWallpaper
property alias font: adapter.font
property alias fontSize: adapter.fontSize
property alias wallDir: adapter.wallDir
}

1
modules/settings/qmldir Normal file
View File

@ -0,0 +1 @@
singleton Settings 1.0 Settings.qml

View File

@ -3,8 +3,8 @@ import QtQuick
import Qt.labs.folderlistmodel 2.15 // <--- The magic file scanner! import Qt.labs.folderlistmodel 2.15 // <--- The magic file scanner!
import Quickshell import Quickshell
import Quickshell.Hyprland import Quickshell.Hyprland
import Quickshell.Io
import "../../" import "../../"
import "../settings/"
FloatingWindow { FloatingWindow {
id: root id: root
@ -26,13 +26,13 @@ FloatingWindow {
// Make it float above everything else // Make it float above everything else
Text { Text {
id: titleText id: titleText
text: "Wallpapers in " + WallpaperStore.wallDir text: "Wallpapers in " + Settings.wallDir.replace("file://", "")
anchors.horizontalCenter: parent.horizontalCenter anchors.horizontalCenter: parent.horizontalCenter
anchors.top: parent.top anchors.top: parent.top
font.pixelSize: 20 font.pixelSize: 20
topPadding: 20 topPadding: 20
bottomPadding: 10 bottomPadding: 10
font.family: Appearance.font font.family: Settings.font
color: Colors.foreground color: Colors.foreground
} }
@ -41,7 +41,7 @@ FloatingWindow {
// 1. The File Scanner // 1. The File Scanner
FolderListModel { FolderListModel {
id: folderModel id: folderModel
folder: "file:///home/lucy/.walls/" // <--- Your stash! folder: Settings.wallDir // <--- Your stash!
nameFilters: ["*.png", "*.jpg", "*.jpeg"] nameFilters: ["*.png", "*.jpg", "*.jpeg"]
showDirs: false showDirs: false
} }
@ -60,6 +60,7 @@ FloatingWindow {
model: folderModel model: folderModel
delegate: Item { delegate: Item {
property string cleanPath: modelData.fileUrl.toString().replace("file://", "")
required property var modelData required property var modelData
width: 200 width: 200
height: 100 height: 100
@ -84,8 +85,7 @@ FloatingWindow {
anchors.fill: parent anchors.fill: parent
onClicked: { onClicked: {
let cleanPath = parent.modelData.fileUrl.toString().replace("file://", ""); let cleanPath = parent.modelData.fileUrl.toString().replace("file://", "");
// Update the Singleton! Settings.currentWall = parent.modelData.fileUrl.toString();
WallpaperStore.currentWall = parent.modelData.fileUrl.toString();
} }
} }
} }

View File

@ -1,8 +1,8 @@
pragma ComponentBehavior: Bound pragma ComponentBehavior: Bound
import QtQuick import QtQuick
import QtQuick.Controls // <--- Needed for StackView import QtQuick.Controls // <--- Needed for StackView
import Quickshell
import Quickshell.Wayland import Quickshell.Wayland
import "../settings/"
WlrLayershell { WlrLayershell {
id: root id: root
@ -64,12 +64,11 @@ WlrLayershell {
// 5. The Trigger 🔫 // 5. The Trigger 🔫
// We listen for the singleton to change, then tell the Stack to update // We listen for the singleton to change, then tell the Stack to update
Connections { Connections {
target: WallpaperStore target: Settings
function onCurrentWallChanged() { function onCurrentWallChanged() {
// "Replace the current item with a new wallComponent using the new source"
wallStack.replace(wallComponent, { wallStack.replace(wallComponent, {
"source": WallpaperStore.currentWall "source": Settings.currentWall
}); });
} }
} }

View File

@ -1,31 +0,0 @@
pragma Singleton
import QtQuick
import Quickshell.Io // <--- Import for FileView and JsonAdapter
QtObject {
id: store
// 1. The File Manager
property string wallDir: "~/.walls/"
property var settings: FileView {
path: "/home/lucy/.cache/quickshell_settings.json"
// Auto-save when properties change
onAdapterUpdated: writeAdapter()
// Auto-load when the file changes on disk
watchChanges: true
onFileChanged: reload()
// 2. The Magic Adapter
JsonAdapter {
id: adapter
// This property corresponds to a key in your JSON file!
property string lastWallpaper: "/home/lucy/.walls/mooon.png"
}
}
// 3. Create a helper property for the rest of your app to use
// This keeps the "WallpaperStore.currentWall" name working!
property alias currentWall: adapter.lastWallpaper
}

View File

@ -1,4 +1,3 @@
singleton WallpaperStore 1.0 WallpaperStore.qml
Wallpaper 1.0 Wallpaper.qml Wallpaper 1.0 Wallpaper.qml
WallSwitcher 1.0 WallSwitcher.qml WallSwitcher 1.0 WallSwitcher.qml
Overlay 1.0 Overlay.qml Overlay 1.0 Overlay.qml

1
qmldir
View File

@ -1,2 +1 @@
singleton Colors 1.0 Colors.qml singleton Colors 1.0 Colors.qml
singleton Appearance 1.0 Appearance.qml

View File

@ -6,7 +6,6 @@ import "./modules/wallpaper/"
import "./modules/notifications/" import "./modules/notifications/"
ShellRoot { ShellRoot {
WallSwitcher {}
Variants { Variants {
id: barVariants id: barVariants
model: Quickshell.screens model: Quickshell.screens
@ -28,5 +27,6 @@ ShellRoot {
screen: modelData screen: modelData
} }
} }
WallSwitcher {}
NotiPopup {} NotiPopup {}
} }