From 6c6066f9f350f9b5ed948c03e3e1dd0ef61ea9a1 Mon Sep 17 00:00:00 2001 From: Zacharias-Brohn Date: Mon, 2 Feb 2026 14:18:31 +0100 Subject: [PATCH] working polkit update --- Components/CustomButton.qml | 33 ++++ Components/CustomCheckbox.qml | 39 ++++ Modules/Bar/BarLoader.qml | 1 + Modules/Content.qml | 1 + Modules/Polkit/Polkit.qml | 336 ++++++++++++++++++++++++++++++++++ shell.qml | 3 + 6 files changed, 413 insertions(+) create mode 100644 Components/CustomButton.qml create mode 100644 Components/CustomCheckbox.qml create mode 100644 Modules/Polkit/Polkit.qml diff --git a/Components/CustomButton.qml b/Components/CustomButton.qml new file mode 100644 index 0000000..62586bc --- /dev/null +++ b/Components/CustomButton.qml @@ -0,0 +1,33 @@ +import QtQuick +import QtQuick.Controls + +Button { + id: control + + required property color textColor + required property color bgColor + property int radius: 4 + + contentItem: CustomText { + text: control.text + + opacity: control.enabled ? 1.0 : 0.5 + color: control.textColor + horizontalAlignment: Text.AlignHCenter + verticalAlignment: Text.AlignVCenter + } + + background: CustomRect { + opacity: control.enabled ? 1.0 : 0.5 + + radius: control.radius + color: control.bgColor + } + + StateLayer { + radius: control.radius + function onClicked(): void { + control.clicked(); + } + } +} diff --git a/Components/CustomCheckbox.qml b/Components/CustomCheckbox.qml new file mode 100644 index 0000000..2749781 --- /dev/null +++ b/Components/CustomCheckbox.qml @@ -0,0 +1,39 @@ +import QtQuick +import QtQuick.Controls +import qs.Config + +CheckBox { + id: control + + property int checkWidth: 20 + property int checkHeight: 20 + + indicator: CustomRect { + implicitWidth: control.checkWidth + implicitHeight: control.checkHeight + // x: control.leftPadding + // y: parent.implicitHeight / 2 - implicitHeight / 2 + border.color: control.checked ? DynamicColors.palette.m3primary : "transparent" + color: DynamicColors.palette.m3surfaceVariant + + radius: 4 + + CustomRect { + implicitWidth: control.checkWidth - (x * 2) + implicitHeight: control.checkHeight - (y * 2) + x: 4 + y: 4 + radius: 3 + color: DynamicColors.palette.m3primary + visible: control.checked + } + } + + contentItem: CustomText { + text: control.text + font.pointSize: control.font.pointSize + anchors.verticalCenter: parent.verticalCenter + anchors.left: parent.left + anchors.leftMargin: control.checkWidth + control.leftPadding + 8 + } +} diff --git a/Modules/Bar/BarLoader.qml b/Modules/Bar/BarLoader.qml index af63ff4..4d09208 100644 --- a/Modules/Bar/BarLoader.qml +++ b/Modules/Bar/BarLoader.qml @@ -8,6 +8,7 @@ import qs.Modules import qs.Config import qs.Helpers import qs.Daemons +import qs.Modules.Polkit RowLayout { id: root diff --git a/Modules/Content.qml b/Modules/Content.qml index 3d6d580..af91265 100644 --- a/Modules/Content.qml +++ b/Modules/Content.qml @@ -6,6 +6,7 @@ import QtQuick import qs.Config import qs.Modules.Calendar import qs.Modules.WSOverview +import qs.Modules.Polkit Item { id: root diff --git a/Modules/Polkit/Polkit.qml b/Modules/Polkit/Polkit.qml new file mode 100644 index 0000000..194493f --- /dev/null +++ b/Modules/Polkit/Polkit.qml @@ -0,0 +1,336 @@ +import Quickshell +import Quickshell.Services.Polkit +import Quickshell.Wayland +import Quickshell.Hyprland +import Quickshell.Widgets +import QtQuick +import QtQuick.Layouts +import QtQuick.Controls +import qs.Components +import qs.Modules +import qs.Config + +Scope { + id: root + + property alias polkitAgent: polkitAgent + property bool shouldShow: false + + PanelWindow { + id: panelWindow + + WlrLayershell.keyboardFocus: WlrKeyboardFocus.Exclusive + WlrLayershell.namespace: "ZShell-Auth" + WlrLayershell.layer: WlrLayer.Overlay + visible: false + color: "transparent" + property bool detailsOpen: false + + Connections { + target: root + + onShouldShowChanged: { + if ( root.shouldShow ) { + panelWindow.visible = true + openAnim.start() + } else { + closeAnim.start() + } + } + } + + Anim { + id: openAnim + target: inputPanel + property: "opacity" + to: 1 + duration: MaterialEasing.expressiveEffectsTime + } + + Anim { + id: closeAnim + target: inputPanel + property: "opacity" + to: 0 + duration: MaterialEasing.expressiveEffectsTime + onStarted: { + panelWindow.detailsOpen = false + } + onFinished: { + panelWindow.visible = false + } + } + + anchors { + left: true + right: true + top: true + bottom: true + } + + // mask: Region { item: inputPanel } + + Rectangle { + id: inputPanel + + color: DynamicColors.tPalette.m3surface + opacity: 0 + + anchors.centerIn: parent + radius: 24 + + implicitWidth: layout.childrenRect.width + 32 + implicitHeight: layout.childrenRect.height + 28 + ColumnLayout { + id: layout + anchors.centerIn: parent + + RowLayout { + id: contentRow + spacing: 24 + + IconImage { + source: Quickshell.iconPath(polkitAgent.flow?.iconName) ?? "" + implicitSize: 64 + mipmap: true + + Layout.preferredWidth: implicitSize + Layout.preferredHeight: implicitSize + Layout.leftMargin: 16 + Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter + } + + ColumnLayout { + id: contentColumn + Layout.fillWidth: true + Layout.fillHeight: true + + CustomText { + Layout.preferredWidth: Math.min(600, contentWidth) + Layout.alignment: Qt.AlignLeft + + text: polkitAgent.flow?.message + wrapMode: Text.WordWrap + font.pointSize: 16 + font.bold: true + } + + CustomText { + Layout.preferredWidth: Math.min(600, contentWidth) + Layout.alignment: Qt.AlignLeft + + text: polkitAgent.flow?.supplementaryMessage || "No Additional Information" + color: DynamicColors.tPalette.m3onSurfaceVariant + wrapMode: Text.WordWrap + font.pointSize: 12 + font.bold: true + } + + TextField { + id: passInput + + echoMode: polkitAgent.flow?.responseVisible ? TextInput.Normal : TextInput.Password + selectByMouse: true + onAccepted: okButton.clicked() + + Layout.preferredWidth: contentColumn.implicitWidth + Layout.preferredHeight: 40 + + background: CustomRect { + radius: 8 + implicitHeight: 40 + color: passInput.enabled ? DynamicColors.tPalette.m3surfaceVariant : DynamicColors.tPalette.m3onSurfaceVariant + } + } + + CustomCheckbox { + id: showPassCheckbox + text: "Show Password" + checked: polkitAgent.flow?.responseVisible + onCheckedChanged: { + passInput.echoMode = checked ? TextInput.Normal : TextInput.Password + passInput.forceActiveFocus() + } + + Layout.alignment: Qt.AlignLeft + } + } + } + + CustomRect { + id: detailsPanel + + visible: true + color: DynamicColors.tPalette.m3surfaceContainerLow + radius: 16 + clip: true + implicitHeight: 0 + Layout.fillWidth: true + Layout.preferredHeight: implicitHeight + + property bool open: panelWindow.detailsOpen + + Behavior on open { + ParallelAnimation { + Anim { + target: detailsPanel + + property: "implicitHeight" + to: !detailsPanel.open ? textDetailsColumn.childrenRect.height + 16 : 0 + duration: MaterialEasing.expressiveEffectsTime + } + + Anim { + target: textDetailsColumn + + property: "opacity" + to: !detailsPanel.open ? 1 : 0 + duration: MaterialEasing.expressiveEffectsTime + } + + Anim { + target: textDetailsColumn + + property: "scale" + to: !detailsPanel.open ? 1 : 0.9 + duration: MaterialEasing.expressiveEffectsTime + } + } + } + + ColumnLayout { + id: textDetailsColumn + spacing: 8 + anchors.centerIn: parent + opacity: 0 + scale: 0.9 + + CustomText { + Layout.preferredWidth: 650 + text: `cookie: ${polkitAgent.flow?.cookie}` + wrapMode: Text.WordWrap + } + + CustomText { + Layout.preferredWidth: 650 + text: `actionId: ${polkitAgent.flow?.actionId}` + wrapMode: Text.WordWrap + } + + CustomText { + Layout.preferredWidth: 650 + text: `selectedIdentity: ${polkitAgent.flow?.selectedIdentity}` + wrapMode: Text.WordWrap + } + } + } + + RowLayout { + spacing: 8 + Layout.preferredWidth: contentRow.implicitWidth + + CustomButton { + id: detailsButton + text: "Details" + textColor: DynamicColors.palette.m3onSurface + bgColor: DynamicColors.palette.m3surfaceContainer + enabled: true + radius: 1000 + + Layout.preferredWidth: 92 + Layout.preferredHeight: 40 + Layout.alignment: Qt.AlignLeft + + onClicked: { + panelWindow.detailsOpen = !panelWindow.detailsOpen + console.log(panelWindow.detailsOpen) + } + } + + Item { + id: spacer + Layout.fillWidth: true + } + + CustomButton { + id: okButton + text: "OK" + textColor: DynamicColors.palette.m3onPrimary + bgColor: DynamicColors.palette.m3primary + enabled: passInput.text.length > 0 || !!polkitAgent.flow?.isResponseRequired + radius: 1000 + Layout.preferredWidth: 76 + Layout.preferredHeight: 40 + Layout.alignment: Qt.AlignRight + onClicked: { + polkitAgent.flow.submit(passInput.text) + root.shouldShow = false + passInput.text = "" + passInput.forceActiveFocus() + } + } + + CustomButton { + id: cancelButton + text: "Cancel" + textColor: DynamicColors.palette.m3onSurface + bgColor: DynamicColors.palette.m3surfaceContainer + enabled: passInput.text.length > 0 || !!polkitAgent.flow?.isResponseRequired + radius: 1000 + Layout.preferredWidth: 76 + Layout.preferredHeight: 40 + Layout.alignment: Qt.AlignRight + onClicked: { + root.shouldShow = false + polkitAgent.flow.cancelAuthenticationRequest() + passInput.text = "" + } + } + } + } + } + + Connections { + target: polkitAgent.flow + + function onIsResponseRequiredChanged() { + passInput.text = "" + if ( polkitAgent.flow?.isResponseRequired ) { + root.shouldShow = true + passInput.forceActiveFocus() + } else { + root.shouldShow = false + } + } + } + } + + PolkitAgent { + id: polkitAgent + } + + Variants { + model: Quickshell.screens + + PanelWindow { + + required property var modelData + + color: root.shouldShow ? "#80000000" : "transparent" + screen: modelData + exclusionMode: ExclusionMode.Ignore + visible: panelWindow.visible + + Behavior on color { + CAnim {} + } + + anchors { + left: true + right: true + top: true + bottom: true + } + } + } +} diff --git a/shell.qml b/shell.qml index 6b28ebf..66f3ed6 100644 --- a/shell.qml +++ b/shell.qml @@ -4,6 +4,7 @@ import Quickshell import qs.Modules import qs.Modules.Lock import qs.Helpers +import qs.Modules.Polkit Scope { Bar {} @@ -21,4 +22,6 @@ Scope { NotificationCenter { } + + Polkit {} }