From 1d7b47ee4ce68772f71b32f170c7830ce0d68a9f Mon Sep 17 00:00:00 2001 From: quadbyte Date: Tue, 19 Aug 2025 13:31:13 -0400 Subject: [PATCH] Formatting --- Commons/Settings.qml | 2 +- Modules/Background/ScreenCorners.qml | 10 +- Modules/Bar/BluetoothMenu.qml | 8 +- Modules/Bar/TrayMenu.qml | 2 +- Modules/Bar/WiFiMenu.qml | 8 +- Modules/SettingsPanel/Tabs/ColorSchemeTab.qml | 14 +- Modules/SettingsPanel/Tabs/NetworkTab.qml | 118 ++++----- Modules/SettingsPanel/Tabs/WallpaperTab.qml | 14 +- Modules/Toast/ToastManager.qml | 22 +- Services/BluetoothService.qml | 2 +- Services/CompositorService.qml | 6 +- Services/ScalingService.qml | 1 + Services/ToastService.qml | 227 +++++++++--------- Widgets/NToast.qml | 87 ++++--- 14 files changed, 267 insertions(+), 254 deletions(-) diff --git a/Commons/Settings.qml b/Commons/Settings.qml index 1b6b33c..bc5d6c4 100644 --- a/Commons/Settings.qml +++ b/Commons/Settings.qml @@ -109,7 +109,7 @@ Singleton { property JsonObject bar bar: JsonObject { - property string position: "top" // Possible values: "top", "bottom" + property string position: "top" // Possible values: "top", "bottom" property bool showActiveWindow: true property bool showSystemInfo: false property bool showMedia: false diff --git a/Modules/Background/ScreenCorners.qml b/Modules/Background/ScreenCorners.qml index ba04642..f8c612f 100644 --- a/Modules/Background/ScreenCorners.qml +++ b/Modules/Background/ScreenCorners.qml @@ -43,12 +43,10 @@ NLoader { } margins { - top: (Settings.data.bar.monitors.includes(modelData.name) - || (Settings.data.bar.monitors.length === 0)) && Settings.data.bar.position === "top" - ? Math.floor(Style.barHeight * scaling) : 0 - bottom: (Settings.data.bar.monitors.includes(modelData.name) - || (Settings.data.bar.monitors.length === 0)) && Settings.data.bar.position === "bottom" - ? Math.floor(Style.barHeight * scaling) : 0 + top: (Settings.data.bar.monitors.includes(modelData.name) || (Settings.data.bar.monitors.length === 0)) + && Settings.data.bar.position === "top" ? Math.floor(Style.barHeight * scaling) : 0 + bottom: (Settings.data.bar.monitors.includes(modelData.name) || (Settings.data.bar.monitors.length === 0)) + && Settings.data.bar.position === "bottom" ? Math.floor(Style.barHeight * scaling) : 0 } // Source we want to show only as a ring diff --git a/Modules/Bar/BluetoothMenu.qml b/Modules/Bar/BluetoothMenu.qml index 7198f40..e0eff50 100644 --- a/Modules/Bar/BluetoothMenu.qml +++ b/Modules/Bar/BluetoothMenu.qml @@ -76,10 +76,10 @@ NLoader { anchors { right: parent.right rightMargin: Style.marginXS * scaling - top: Settings.data.bar.position === "top" ? parent.top : undefined - bottom: Settings.data.bar.position === "bottom" ? parent.bottom : undefined - topMargin: Settings.data.bar.position === "top" ? Style.marginXS * scaling : undefined - bottomMargin: Settings.data.bar.position === "bottom" ? Style.barHeight * scaling + Style.marginXS * scaling : undefined + top: Settings.data.bar.position === "top" ? parent.top : undefined + bottom: Settings.data.bar.position === "bottom" ? parent.bottom : undefined + topMargin: Settings.data.bar.position === "top" ? Style.marginXS * scaling : undefined + bottomMargin: Settings.data.bar.position === "bottom" ? Style.barHeight * scaling + Style.marginXS * scaling : undefined } // Animation properties diff --git a/Modules/Bar/TrayMenu.qml b/Modules/Bar/TrayMenu.qml index eb87abc..a3a24fd 100644 --- a/Modules/Bar/TrayMenu.qml +++ b/Modules/Bar/TrayMenu.qml @@ -254,4 +254,4 @@ PopupWindow { } } } -} \ No newline at end of file +} diff --git a/Modules/Bar/WiFiMenu.qml b/Modules/Bar/WiFiMenu.qml index 94c8998..f66f9cf 100644 --- a/Modules/Bar/WiFiMenu.qml +++ b/Modules/Bar/WiFiMenu.qml @@ -91,10 +91,10 @@ NLoader { anchors { right: parent.right rightMargin: Style.marginXS * scaling - top: Settings.data.bar.position === "top" ? parent.top : undefined - bottom: Settings.data.bar.position === "bottom" ? parent.bottom : undefined - topMargin: Settings.data.bar.position === "top" ? Style.marginXS * scaling : undefined - bottomMargin: Settings.data.bar.position === "bottom" ? Style.barHeight * scaling + Style.marginXS * scaling : undefined + top: Settings.data.bar.position === "top" ? parent.top : undefined + bottom: Settings.data.bar.position === "bottom" ? parent.bottom : undefined + topMargin: Settings.data.bar.position === "top" ? Style.marginXS * scaling : undefined + bottomMargin: Settings.data.bar.position === "bottom" ? Style.barHeight * scaling + Style.marginXS * scaling : undefined } // Animation properties diff --git a/Modules/SettingsPanel/Tabs/ColorSchemeTab.qml b/Modules/SettingsPanel/Tabs/ColorSchemeTab.qml index 02a8306..a1d74a2 100644 --- a/Modules/SettingsPanel/Tabs/ColorSchemeTab.qml +++ b/Modules/SettingsPanel/Tabs/ColorSchemeTab.qml @@ -346,19 +346,19 @@ ColumnLayout { id: matugenCheck command: ["which", "matugen"] running: false - - onExited: function(exitCode) { + + onExited: function (exitCode) { if (exitCode === 0) { // Matugen exists, enable it Settings.data.colorSchemes.useWallpaperColors = true ColorSchemeService.changedWallpaper() - ToastService.showNotice("Matugen", "Enabled!") - } else { - // Matugen not found - ToastService.showWarning("Matugen", "Not installed!") + ToastService.showNotice("Matugen", "Enabled!") + } else { + // Matugen not found + ToastService.showWarning("Matugen", "Not installed!") } } - + stdout: StdioCollector {} stderr: StdioCollector {} } diff --git a/Modules/SettingsPanel/Tabs/NetworkTab.qml b/Modules/SettingsPanel/Tabs/NetworkTab.qml index 031b33d..7029ecb 100644 --- a/Modules/SettingsPanel/Tabs/NetworkTab.qml +++ b/Modules/SettingsPanel/Tabs/NetworkTab.qml @@ -8,69 +8,69 @@ import qs.Services import qs.Widgets ColumnLayout { - id: root - spacing: 0 + id: root + spacing: 0 - ScrollView { - id: scrollView + ScrollView { + id: scrollView + Layout.fillWidth: true + Layout.fillHeight: true + padding: Style.marginM * scaling + clip: true + + ScrollBar.horizontal.policy: ScrollBar.AlwaysOff + ScrollBar.vertical.policy: ScrollBar.AsNeeded + + ColumnLayout { + width: scrollView.availableWidth + spacing: 0 + + Item { Layout.fillWidth: true - Layout.fillHeight: true - padding: Style.marginM * scaling - clip: true + Layout.preferredHeight: 0 + } - ScrollBar.horizontal.policy: ScrollBar.AlwaysOff - ScrollBar.vertical.policy: ScrollBar.AsNeeded + ColumnLayout { + spacing: Style.marginL * scaling + Layout.fillWidth: true - ColumnLayout { - width: scrollView.availableWidth - spacing: 0 - - Item { - Layout.fillWidth: true - Layout.preferredHeight: 0 - } - - ColumnLayout { - spacing: Style.marginL * scaling - Layout.fillWidth: true - - NText { - text: "Interfaces" - font.pointSize: Style.fontSizeXXL * scaling - font.weight: Style.fontWeightBold - color: Color.mOnSurface - } - - NToggle { - label: "WiFi Enabled" - description: "Enable WiFi connectivity." - checked: Settings.data.network.wifiEnabled - onToggled: checked => { - Settings.data.network.wifiEnabled = checked - NetworkService.setWifiEnabled(checked) - if (checked) { - ToastService.showNotice("WiFi", "Enabled") - } else { - ToastService.showNotice("WiFi", "Disabled") - } - } - } - - NToggle { - label: "Bluetooth Enabled" - description: "Enable Bluetooth connectivity." - checked: Settings.data.network.bluetoothEnabled - onToggled: checked => { - Settings.data.network.bluetoothEnabled = checked - BluetoothService.setBluetoothEnabled(checked) - if (checked) { - ToastService.showNotice("Bluetooth", "Enabled") - } else { - ToastService.showNotice("Bluetooth", "Disabled") - } - } - } - } + NText { + text: "Interfaces" + font.pointSize: Style.fontSizeXXL * scaling + font.weight: Style.fontWeightBold + color: Color.mOnSurface } + + NToggle { + label: "WiFi Enabled" + description: "Enable WiFi connectivity." + checked: Settings.data.network.wifiEnabled + onToggled: checked => { + Settings.data.network.wifiEnabled = checked + NetworkService.setWifiEnabled(checked) + if (checked) { + ToastService.showNotice("WiFi", "Enabled") + } else { + ToastService.showNotice("WiFi", "Disabled") + } + } + } + + NToggle { + label: "Bluetooth Enabled" + description: "Enable Bluetooth connectivity." + checked: Settings.data.network.bluetoothEnabled + onToggled: checked => { + Settings.data.network.bluetoothEnabled = checked + BluetoothService.setBluetoothEnabled(checked) + if (checked) { + ToastService.showNotice("Bluetooth", "Enabled") + } else { + ToastService.showNotice("Bluetooth", "Disabled") + } + } + } + } } + } } diff --git a/Modules/SettingsPanel/Tabs/WallpaperTab.qml b/Modules/SettingsPanel/Tabs/WallpaperTab.qml index a87b421..5353714 100644 --- a/Modules/SettingsPanel/Tabs/WallpaperTab.qml +++ b/Modules/SettingsPanel/Tabs/WallpaperTab.qml @@ -348,19 +348,19 @@ ColumnLayout { id: swwwCheck command: ["which", "swww"] running: false - - onExited: function(exitCode) { + + onExited: function (exitCode) { if (exitCode === 0) { // SWWW exists, enable it Settings.data.wallpaper.swww.enabled = true WallpaperService.startSWWWDaemon() - ToastService.showNotice("SWWW", "Enabled!") - } else { - // SWWW not found - ToastService.showWarning("SWWW", "Not installed!") + ToastService.showNotice("SWWW", "Enabled!") + } else { + // SWWW not found + ToastService.showWarning("SWWW", "Not installed!") } } - + stdout: StdioCollector {} stderr: StdioCollector {} } diff --git a/Modules/Toast/ToastManager.qml b/Modules/Toast/ToastManager.qml index 1eb69ff..35fe01e 100644 --- a/Modules/Toast/ToastManager.qml +++ b/Modules/Toast/ToastManager.qml @@ -24,18 +24,18 @@ Variants { left: true right: true } - + // Set margins based on bar position margins.top: Settings.data.bar.position === "top" ? (Style.barHeight + Style.marginS) * scaling : 0 margins.bottom: Settings.data.bar.position === "bottom" ? (Style.barHeight + Style.marginS) * scaling : 0 - + // Small height when hidden, appropriate height when visible implicitHeight: toast.visible ? toast.height + Style.marginS * scaling : 1 // Transparent background color: Color.transparent - - // High layer to appear above other panels + + // High layer to appear above other panels //WlrLayershell.layer: WlrLayer.Overlay WlrLayershell.keyboardFocus: WlrKeyboardFocus.None exclusionMode: PanelWindow.ExclusionMode.Ignore @@ -43,22 +43,20 @@ Variants { NToast { id: toast scaling: root.scaling - + // Simple positioning - margins already account for bar targetY: Style.marginS * scaling - + // Hidden position based on bar location - hiddenY: Settings.data.bar.position === "top" - ? -toast.height - 20 - : toast.height + 20 - + hiddenY: Settings.data.bar.position === "top" ? -toast.height - 20 : toast.height + 20 + Component.onCompleted: { // Register this toast with the service ToastService.currentToast = toast - + // Connect dismissal signal toast.dismissed.connect(ToastService.onToastDismissed) } } } -} \ No newline at end of file +} diff --git a/Services/BluetoothService.qml b/Services/BluetoothService.qml index b81d6d2..ba354fb 100644 --- a/Services/BluetoothService.qml +++ b/Services/BluetoothService.qml @@ -147,7 +147,7 @@ Singleton { console.warn("BluetoothService: No adapter available") return } - + adapter.enabled = enabled } } diff --git a/Services/CompositorService.qml b/Services/CompositorService.qml index 8cf2bba..a84d831 100644 --- a/Services/CompositorService.qml +++ b/Services/CompositorService.qml @@ -145,7 +145,7 @@ Singleton { try { const hlToplevels = Hyprland.toplevels.values const windowsList = [] - + for (var i = 0; i < hlToplevels.length; i++) { const toplevel = hlToplevels[i] windowsList.push({ @@ -158,7 +158,7 @@ Singleton { } windows = windowsList - + // Update focused window index focusedWindowIndex = -1 for (var j = 0; j < windowsList.length; j++) { @@ -167,7 +167,7 @@ Singleton { break } } - + updateFocusedWindowTitle() activeWindowChanged() } catch (e) { diff --git a/Services/ScalingService.qml b/Services/ScalingService.qml index 812daf0..9679bc5 100644 --- a/Services/ScalingService.qml +++ b/Services/ScalingService.qml @@ -20,6 +20,7 @@ Singleton { } } } catch (e) { + //Logger.warn(e) } diff --git a/Services/ToastService.qml b/Services/ToastService.qml index 5553986..b08a366 100644 --- a/Services/ToastService.qml +++ b/Services/ToastService.qml @@ -6,177 +6,184 @@ import qs.Commons QtObject { id: root - + // Queue of pending toast messages property var messageQueue: [] property bool isShowingToast: false - + // Reference to the current toast instance (set by ToastManager) property var currentToast: null - + // Methods to show different types of messages function showNotice(label, description = "", persistent = false, duration = 3000) { showToast(label, description, "notice", persistent, duration) } - + function showWarning(label, description = "", persistent = false, duration = 4000) { showToast(label, description, "warning", persistent, duration) } - + // Utility function to check if a command exists and show appropriate toast function checkCommandAndToast(command, successMessage, failMessage, onSuccess = null) { var checkProcess = Qt.createQmlObject(` - import QtQuick - import Quickshell.Io - Process { - id: checkProc - command: ["which", "${command}"] - running: true - - property var onSuccessCallback: null - property bool hasFinished: false - - onExited: { - if (!hasFinished) { - hasFinished = true - if (exitCode === 0) { - ToastService.showNotice("${successMessage}") - if (onSuccessCallback) onSuccessCallback() - } else { - ToastService.showWarning("${failMessage}") - } - checkProc.destroy() - } - } - - // Fallback collectors to prevent issues - stdout: StdioCollector {} - stderr: StdioCollector {} - } - `, root) - + import QtQuick + import Quickshell.Io + Process { + id: checkProc + command: ["which", "${command}"] + running: true + + property var onSuccessCallback: null + property bool hasFinished: false + + onExited: { + if (!hasFinished) { + hasFinished = true + if (exitCode === 0) { + ToastService.showNotice("${successMessage}") + if (onSuccessCallback) onSuccessCallback() + } else { + ToastService.showWarning("${failMessage}") + } + checkProc.destroy() + } + } + + // Fallback collectors to prevent issues + stdout: StdioCollector {} + stderr: StdioCollector {} + } + `, root) + checkProcess.onSuccessCallback = onSuccess } - + // Simple function to show a random toast (useful for testing or fun messages) function showRandomToast() { - var messages = [ - { type: "notice", text: "Everything is working smoothly!" }, - { type: "notice", text: "Noctalia is looking great today!" }, - { type: "notice", text: "Your desktop setup is amazing!" }, - { type: "warning", text: "Don't forget to take a break!" }, - { type: "notice", text: "Configuration saved successfully!" }, - { type: "warning", text: "Remember to backup your settings!" } - ] - + var messages = [{ + "type": "notice", + "text": "Everything is working smoothly!" + }, { + "type": "notice", + "text": "Noctalia is looking great today!" + }, { + "type": "notice", + "text": "Your desktop setup is amazing!" + }, { + "type": "warning", + "text": "Don't forget to take a break!" + }, { + "type": "notice", + "text": "Configuration saved successfully!" + }, { + "type": "warning", + "text": "Remember to backup your settings!" + }] + var randomMessage = messages[Math.floor(Math.random() * messages.length)] showToast(randomMessage.text, randomMessage.type) } - + // Convenience function for quick notifications function quickNotice(message) { showNotice(message, false, 2000) // Short duration } - + function quickWarning(message) { showWarning(message, false, 3000) // Medium duration } - + // Generic command runner with toast feedback function runCommandWithToast(command, args, successMessage, failMessage, onSuccess = null) { var fullCommand = [command].concat(args || []) var runProcess = Qt.createQmlObject(` - import QtQuick - import Quickshell.Io - Process { - id: runProc - command: ${JSON.stringify(fullCommand)} - running: true - - property var onSuccessCallback: null - property bool hasFinished: false - - onExited: { - if (!hasFinished) { - hasFinished = true - if (exitCode === 0) { - ToastService.showNotice("${successMessage}") - if (onSuccessCallback) onSuccessCallback() - } else { - ToastService.showWarning("${failMessage}") - } - runProc.destroy() - } - } - - stdout: StdioCollector {} - stderr: StdioCollector {} - } - `, root) - + import QtQuick + import Quickshell.Io + Process { + id: runProc + command: ${JSON.stringify(fullCommand)} + running: true + + property var onSuccessCallback: null + property bool hasFinished: false + + onExited: { + if (!hasFinished) { + hasFinished = true + if (exitCode === 0) { + ToastService.showNotice("${successMessage}") + if (onSuccessCallback) onSuccessCallback() + } else { + ToastService.showWarning("${failMessage}") + } + runProc.destroy() + } + } + + stdout: StdioCollector {} + stderr: StdioCollector {} + } + `, root) + runProcess.onSuccessCallback = onSuccess } - + // Check if a file/directory exists function checkPathAndToast(path, successMessage, failMessage, onSuccess = null) { runCommandWithToast("test", ["-e", path], successMessage, failMessage, onSuccess) } - + // Show toast after a delay (useful for delayed feedback) function delayedToast(message, type = "notice", delayMs = 1000) { var timer = Qt.createQmlObject(` - import QtQuick - Timer { - interval: ${delayMs} - repeat: false - running: true - onTriggered: { - ToastService.showToast("${message}", "${type}") - destroy() - } - } - `, root) + import QtQuick + Timer { + interval: ${delayMs} + repeat: false + running: true + onTriggered: { + ToastService.showToast("${message}", "${type}") + destroy() + } + } + `, root) } - + // Generic method to show a toast function showToast(label, description = "", type = "notice", persistent = false, duration = 3000) { var toastData = { - label: label, - description: description, - type: type, - persistent: persistent, - duration: duration, - timestamp: Date.now() + "label": label, + "description": description, + "type": type, + "persistent": persistent, + "duration": duration, + "timestamp": Date.now() } - - // Add to queue messageQueue.push(toastData) - + // Process queue if not currently showing a toast if (!isShowingToast) { processQueue() } } - + // Process the message queue function processQueue() { if (messageQueue.length === 0 || !currentToast) { isShowingToast = false return } - + if (isShowingToast) { // Wait for current toast to finish return } - + var toastData = messageQueue.shift() isShowingToast = true - - // Configure and show toast currentToast.label = toastData.label currentToast.description = toastData.description @@ -185,32 +192,32 @@ QtObject { currentToast.duration = toastData.duration currentToast.show() } - + // Called when a toast is dismissed function onToastDismissed() { isShowingToast = false - + // Small delay before showing next toast - Qt.callLater(function() { + Qt.callLater(function () { processQueue() }) } - + // Clear all pending messages function clearQueue() { messageQueue = [] } - + // Hide current toast function hideCurrentToast() { if (currentToast && isShowingToast) { currentToast.hide() } } - + Component.onCompleted: { } -} \ No newline at end of file +} diff --git a/Widgets/NToast.qml b/Widgets/NToast.qml index 227966b..2483c33 100644 --- a/Widgets/NToast.qml +++ b/Widgets/NToast.qml @@ -7,29 +7,29 @@ import qs.Widgets Item { id: root - + property string label: "" property string description: "" property string type: "notice" // "notice", "warning" property int duration: 5000 // Auto-hide after 5 seconds, 0 = no auto-hide property bool persistent: false // If true, requires manual dismiss - + property real scaling: 1.0 // Will be set by parent - + // Animation properties property real targetY: 0 property real hiddenY: -height - 20 - - signal dismissed() - + + signal dismissed + width: Math.min(500 * scaling, parent.width * 0.8) height: Math.max(60 * scaling, contentLayout.implicitHeight + Style.marginL * 2 * scaling) - + // Position at top center of parent anchors.horizontalCenter: parent.horizontalCenter y: hiddenY z: 1000 // High z-index to appear above everything - + function show() { visible = true showAnimation.start() @@ -37,18 +37,18 @@ Item { autoHideTimer.start() } } - + function hide() { hideAnimation.start() } - + // Auto-hide timer Timer { id: autoHideTimer interval: root.duration onTriggered: hide() } - + // Show animation PropertyAnimation { id: showAnimation @@ -58,7 +58,7 @@ Item { duration: Style.animationNormal easing.type: Easing.OutCubic } - + // Hide animation PropertyAnimation { id: hideAnimation @@ -72,26 +72,29 @@ Item { root.dismissed() } } - + // Main toast container Rectangle { id: container anchors.fill: parent radius: Style.radiusL * scaling - + // Clean surface background color: Color.mSurface - + // Simple colored border all around border.color: { switch (root.type) { - case "warning": return Color.mError - case "notice": return Color.mPrimary - default: return Color.mOutline + case "warning": + return Color.mError + case "notice": + return Color.mPrimary + default: + return Color.mOutline } } border.width: Math.max(2, Style.borderM * scaling) - + // Drop shadow effect layer.enabled: true layer.effect: MultiEffect { @@ -100,43 +103,49 @@ Item { shadowBlur: 20 * scaling shadowVerticalOffset: 4 * scaling } - + RowLayout { id: contentLayout anchors.fill: parent anchors.margins: Style.marginM * scaling spacing: Style.marginS * scaling - + // Icon NIcon { id: icon text: { switch (root.type) { - case "warning": return "warning" - case "notice": return "info" - default: return "info" + case "warning": + return "warning" + case "notice": + return "info" + default: + return "info" } } - + color: { switch (root.type) { - case "warning": return Color.mError - case "notice": return Color.mPrimary - default: return Color.mPrimary + case "warning": + return Color.mError + case "notice": + return Color.mPrimary + default: + return Color.mPrimary } } - + font.pointSize: Style.fontSizeXXL * 1.5 * scaling // 150% size to cover two lines Layout.alignment: Qt.AlignVCenter } - + // Label and description Column { id: textColumn spacing: Style.marginXXS * scaling Layout.fillWidth: true Layout.alignment: Qt.AlignVCenter - + NText { id: labelText text: root.label @@ -147,7 +156,7 @@ Item { width: parent.width visible: text.length > 0 } - + NText { id: descriptionText text: root.description @@ -158,23 +167,23 @@ Item { visible: text.length > 0 } } - + // Close button (only if persistent or manual dismiss needed) NIconButton { id: closeButton icon: "close" visible: root.persistent || root.duration === 0 - + color: Color.mOnSurface - + fontPointSize: Style.fontSize * scaling sizeMultiplier: 0.8 Layout.alignment: Qt.AlignTop - + onClicked: hide() } } - + // Click to dismiss (if not persistent) MouseArea { anchors.fill: parent @@ -183,9 +192,9 @@ Item { cursorShape: Qt.PointingHandCursor } } - + // Initial state Component.onCompleted: { visible = false } -} \ No newline at end of file +}