waffles: polkit

This commit is contained in:
end-4
2025-12-08 10:34:05 +01:00
parent 1c8339df10
commit 8b8ac44852
19 changed files with 394 additions and 79 deletions
@@ -0,0 +1,44 @@
pragma ComponentBehavior: Bound
import qs
import qs.services
import qs.modules.common
import qs.modules.common.widgets
import qs.modules.common.functions
import QtQuick
import Quickshell
import Quickshell.Wayland
Scope {
id: root
required property Component contentComponent
Loader {
active: PolkitService.active
sourceComponent: Variants {
model: Quickshell.screens
delegate: PanelWindow {
id: panelWindow
required property var modelData
screen: modelData
anchors {
top: true
left: true
right: true
bottom: true
}
color: "transparent"
WlrLayershell.namespace: "quickshell:polkit"
WlrLayershell.keyboardFocus: WlrKeyboardFocus.OnDemand
WlrLayershell.layer: WlrLayer.Overlay
exclusionMode: ExclusionMode.Ignore
Loader {
anchors.fill: parent
sourceComponent: root.contentComponent
}
}
}
}
}
@@ -6,37 +6,10 @@ import qs.modules.common.functions
import QtQuick
import Quickshell
import Quickshell.Wayland
import Quickshell.Hyprland
Scope {
FullscreenPolkitWindow {
id: root
Loader {
active: PolkitService.active
sourceComponent: Variants {
model: Quickshell.screens
delegate: PanelWindow {
id: panelWindow
required property var modelData
screen: modelData
anchors {
top: true
left: true
right: true
bottom: true
}
color: "transparent"
WlrLayershell.namespace: "quickshell:polkit"
WlrLayershell.keyboardFocus: WlrKeyboardFocus.OnDemand
WlrLayershell.layer: WlrLayer.Overlay
exclusionMode: ExclusionMode.Ignore
PolkitContent {
anchors.fill: parent
}
}
}
contentComponent: Component {
PolkitContent {}
}
}
@@ -66,12 +66,7 @@ Item {
WindowDialogParagraph {
Layout.fillWidth: true
horizontalAlignment: Text.AlignLeft
text: {
if (!PolkitService.flow) return;
return PolkitService.flow.message.endsWith(".")
? PolkitService.flow.message.slice(0, -1)
: PolkitService.flow.message
}
text: PolkitService.cleanMessage
}
MaterialTextField {
@@ -79,11 +74,7 @@ Item {
Layout.fillWidth: true
focus: true
enabled: PolkitService.interactionAvailable
placeholderText: {
const inputPrompt = PolkitService.flow?.inputPrompt.trim() ?? "";
const cleanedInputPrompt = inputPrompt.endsWith(":") ? inputPrompt.slice(0, -1) : inputPrompt;
return cleanedInputPrompt || (root.usePasswordChars ? Translation.tr("Password") : Translation.tr("Input"))
}
placeholderText: PolkitService.cleanPrompt
echoMode: root.usePasswordChars ? TextInput.Password : TextInput.Normal
onAccepted: root.submit();
@@ -67,7 +67,7 @@ Button {
}
}
CloseButton {
WindowCloseButton {
id: closeButton
}
}
@@ -91,46 +91,14 @@ Button {
}
}
component CloseButton: Button {
id: reusableCloseButton
component WindowCloseButton: CloseButton {
visible: root.hovered
Layout.leftMargin: 4
implicitHeight: 30
implicitWidth: 30
radius: Looks.radius.large - root.padding
onClicked: {
root.toplevel.close();
}
Rectangle {
z: 0
color: "transparent"
anchors.fill: closeButtonBg
anchors.margins: -1
opacity: closeButtonBg.opacity
border.width: 1
radius: closeButtonBg.radius + 1
border.color: Looks.colors.bg2Border
}
background: Rectangle {
id: closeButtonBg
z: 1
opacity: reusableCloseButton.hovered ? 1 : 0
radius: Looks.radius.large - root.padding
color: reusableCloseButton.pressed ? Looks.colors.dangerActive : Looks.colors.danger
Behavior on opacity {
animation: Looks.transition.opacity.createObject(this)
}
Behavior on color {
animation: Looks.transition.color.createObject(this)
}
}
contentItem: FluentIcon {
z: 2
anchors.centerIn: parent
icon: "dismiss"
implicitSize: 10
}
}
}
@@ -0,0 +1,48 @@
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import Qt5Compat.GraphicalEffects
import qs.services
import qs.modules.common
import qs.modules.common.functions
import qs.modules.waffle.looks
import qs.modules.waffle.bar
import Quickshell
Button {
id: reusableCloseButton
implicitHeight: 30
implicitWidth: 30
property alias radius: closeButtonBg.radius
Rectangle {
z: 0
color: "transparent"
anchors.fill: closeButtonBg
anchors.margins: -1
opacity: closeButtonBg.opacity
border.width: 1
radius: closeButtonBg.radius + 1
border.color: Looks.colors.bg2Border
}
background: Rectangle {
id: closeButtonBg
z: 1
opacity: reusableCloseButton.hovered ? 1 : 0
color: reusableCloseButton.pressed ? Looks.colors.dangerActive : Looks.colors.danger
Behavior on opacity {
animation: Looks.transition.opacity.createObject(this)
}
Behavior on color {
animation: Looks.transition.color.createObject(this)
}
}
contentItem: FluentIcon {
z: 2
anchors.centerIn: parent
icon: "dismiss"
implicitSize: 10
}
}
@@ -101,7 +101,7 @@ Singleton {
property color bg1Hover: ColorUtils.transparentize(root.dark ? root.darkColors.bg1Hover : root.lightColors.bg1Hover, root.contentTransparency)
property color bg1Active: ColorUtils.transparentize(root.dark ? root.darkColors.bg1Active : root.lightColors.bg1Active, root.contentTransparency)
property color bg1Border: ColorUtils.transparentize(root.dark ? root.darkColors.bg1Border : root.lightColors.bg1Border, root.contentTransparency)
property color bg2Base: ColorUtils.transparentize(root.dark ? root.darkColors.bg2Base : root.lightColors.bg2Base, root.backgroundTransparency)
property color bg2Base: root.dark ? root.darkColors.bg2Base : root.lightColors.bg2Base
property color bg2: ColorUtils.transparentize(root.dark ? root.darkColors.bg2 : root.lightColors.bg2, root.contentTransparency)
property color bg2Hover: ColorUtils.transparentize(root.dark ? root.darkColors.bg2Hover : root.lightColors.bg2Hover, root.contentTransparency)
property color bg2Active: ColorUtils.transparentize(root.dark ? root.darkColors.bg2Active : root.lightColors.bg2Active, root.contentTransparency)
@@ -147,6 +147,7 @@ Singleton {
property int regular: Font.Medium
property int strong: Font.DemiBold
property int stronger: (Font.DemiBold + 2*Font.Bold) / 3
property int strongest: Font.Bold
}
property QtObject pixelSize: QtObject {
property real normal: 11
@@ -17,4 +17,6 @@ Kirigami.Icon {
roundToIconSize: false
fallback: root.iconName
source: tryCustomIcon ? `${Looks.iconsPath}/${root.iconName}${!root.separateLightDark ? "" : Looks.dark ? "-dark" : "-light"}.svg` : fallback
color: Looks.colors.fg
}
@@ -8,7 +8,7 @@ Text {
color: Looks.colors.fg
font {
hintingPreference: Font.PreferFullHinting
hintingPreference: Font.PreferDefaultHinting
family: Looks.font.family.ui
pixelSize: Looks.font.pixelSize.normal
weight: Looks.font.weight.regular
@@ -0,0 +1,27 @@
import qs.modules.common
import QtQuick
import QtQuick.Controls.FluentWinUI3
import QtQuick.Controls
TextField {
id: root
clip: true
renderType: Text.NativeRendering
verticalAlignment: Text.AlignVCenter
color: Looks.colors.fg
font {
hintingPreference: Font.PreferDefaultHinting
family: Looks.font.family.ui
pixelSize: Looks.font.pixelSize.normal
weight: Looks.font.weight.regular
}
MouseArea {
anchors.fill: parent
acceptedButtons: Qt.NoButton
hoverEnabled: true
cursorShape: Qt.IBeamCursor
}
}
@@ -0,0 +1,208 @@
import QtQuick
import QtQuick.Layouts
import Quickshell
import qs.services
import qs.modules.common
import qs.modules.common.functions
import qs.modules.common.widgets
import qs.modules.waffle.looks
Rectangle {
id: root
color: "#000000"
readonly property bool usePasswordChars: !PolkitService.flow?.responseVisible ?? true
Keys.onPressed: event => { // Esc to close
if (event.key === Qt.Key_Escape) {
PolkitService.cancel();
}
}
StyledImage {
anchors.fill: parent
source: Config.options.background.wallpaperPath
fillMode: Image.PreserveAspectCrop
Rectangle {
anchors.fill: parent
color: ColorUtils.transparentize("#000000", 0.31)
PolkitDialog {
id: dialog
DragHandler {
target: null
property real startX: dialog.x
property real startY: dialog.y
onActiveChanged: {
if (!active) return;
startX = dialog.x;
startY = dialog.y;
}
xAxis.onActiveValueChanged: {
dialog.x = Math.round(startX + xAxis.activeValue);
}
yAxis.onActiveValueChanged: {
dialog.y = Math.round(startY + yAxis.activeValue);
}
}
x: Math.round((parent.width - width) / 2)
y: Math.round((parent.height - height) / 2)
}
}
}
component PolkitDialog: WPane {
borderColor: Looks.colors.ambientShadow
contentItem: WPanelPageColumn {
PolkitDialogHeader {
Layout.fillWidth: true
}
BodyRectangle {
id: dialogBody
implicitHeight: bodyContent.implicitHeight + 48
implicitWidth: 434
color: Looks.colors.bg1Base
ColumnLayout {
id: bodyContent
anchors.fill: parent
anchors.margins: 24
spacing: 20
RowLayout {
Layout.fillWidth: true
spacing: 15
WAppIcon {
iconName: PolkitService.flow?.iconName ?? "window-shield"
fallback: PolkitService.flow?.iconName == "" ? `${Looks.iconsPath}/window-shield` : PolkitService.flow.iconName
isMask: PolkitService.flow?.iconName === ""
tryCustomIcon: false
}
WText {
Layout.fillWidth: true
horizontalAlignment: Text.AlignLeft
font.pixelSize: Looks.font.pixelSize.larger
font.weight: Looks.font.weight.strongest
text: {
const iconName = PolkitService.flow?.iconName ?? "";
if (iconName === "")
return Translation.tr("Command-line-invoked Action");
const desktopEntry = DesktopEntries.applications.values.find(entry => {
return entry.icon == iconName;
});
return desktopEntry ? desktopEntry.name : Translation.tr("Unknown Application");
}
}
}
WText {
Layout.fillWidth: true
wrapMode: Text.Wrap
horizontalAlignment: Text.AlignLeft
text: PolkitService.cleanMessage
}
WTextField {
id: inputField
Layout.fillWidth: true
focus: true
enabled: PolkitService.interactionAvailable
placeholderText: PolkitService.cleanPrompt
echoMode: root.usePasswordChars ? TextInput.Password : TextInput.Normal
onAccepted: PolkitService.submit(inputField.text)
Keys.onPressed: event => { // Esc to close
if (event.key === Qt.Key_Escape) {
PolkitService.cancel();
}
}
Component.onCompleted: forceActiveFocus()
Connections {
target: PolkitService
function onInteractionAvailableChanged() {
if (!PolkitService.interactionAvailable)
return;
inputField.text = "";
inputField.forceActiveFocus();
}
}
}
}
}
BodyRectangle {
implicitHeight: 80
color: Looks.colors.bgPanelFooterBase
RowLayout {
anchors.fill: parent
anchors.margins: 24
spacing: 8
uniformCellSizes: true
WButton {
Layout.fillWidth: true
implicitHeight: 32
colBackground: Looks.colors.bg1
horizontalAlignment: Text.AlignHCenter
text: Translation.tr("Yes")
onClicked: PolkitService.submit(inputField.text)
}
WButton {
Layout.fillWidth: true
implicitHeight: 32
horizontalAlignment: Text.AlignHCenter
checked: true
text: Translation.tr("No")
onClicked: PolkitService.cancel()
}
}
}
}
}
component PolkitDialogHeader: BodyRectangle {
implicitHeight: headerContent.implicitHeight
color: Looks.colors.bg2Base
CloseButton {
anchors {
top: parent.top
right: parent.right
}
radius: 0
implicitWidth: 32
implicitHeight: 32
onClicked: {
PolkitService.cancel();
}
}
ColumnLayout {
id: headerContent
anchors.fill: parent
anchors.leftMargin: 24
anchors.rightMargin: 24
spacing: 18
WText {
Layout.topMargin: 20
Layout.fillWidth: true
horizontalAlignment: Text.AlignLeft
text: Translation.tr("Polkit")
}
WText {
Layout.fillWidth: true
Layout.bottomMargin: 12
horizontalAlignment: Text.AlignLeft
wrapMode: Text.Wrap
text: Translation.tr("Do you want to allow this app to make changes to your device?")
font.pixelSize: Looks.font.pixelSize.xlarger
font.weight: Looks.font.weight.strongest
}
}
}
}
@@ -0,0 +1,15 @@
import qs
import qs.services
import qs.modules.common
import qs.modules.common.widgets
import qs.modules.common.functions
import QtQuick
import Quickshell
import Quickshell.Wayland
FullscreenPolkitWindow {
id: root
contentComponent: Component {
WPolkitContent {}
}
}