pragma ComponentBehavior: Bound import QtQuick import QtQuick.Layouts import Quickshell import Quickshell.Widgets import qs.HyprChrome.Theme // Headlessly renderable visual core of the polkit authentication prompt. // // Nothing here imports Quickshell.Services.Polkit: every field an AuthFlow // exposes arrives as a plain property and every action leaves as a signal, so // the whole dialog can be rendered offscreen (tools/quickshell-preview) and // staged in DebugWindow without a real authorization request. PolkitPrompt.qml // owns the agent and does the mapping. // // `identities` is read structurally — each entry only needs `displayName` — so // the adapter can hand over the flow's QList unchanged while the // headless test passes plain JS objects. Item { id: root // ---- flow state, mirrored ---- property string message: "" property string actionId: "" property string iconName: "" property bool showIcon: true // Who may authenticate. One entry is the common case and renders as a // plain line; the picker only appears when polkit actually offers a // choice (a user in several admin groups, or root plus wheel). property var identities: [] property int selectedIdentity: 0 // PAM conversation. `responseVisible` is polkit's echo flag — it is NOT // always false: a smartcard PIN prompt or a security-question stack asks // for echoed input, and masking those makes the prompt unusable. property bool responseRequired: false property string inputPrompt: "" property bool responseVisible: false // pam_info / pam_error text, and whether the last attempt was rejected. property string supplementaryMessage: "" property bool supplementaryIsError: false property bool failed: false property alias response: responseInput.text // Masking override from the eye toggle; reset with the field, so a // revealed password never carries over to the next request. property bool revealed: false // Proton Pass logins, in their own panel under the dialog, collapsed until // Tab. Entries need only `title` and `vault`; the adapter fetches the // password for the one picked, so no secret is ever in this list. Off by // default, as in the headless render. property bool credentialsEnabled: false property var credentials: [] // Picker-only: loading / listing failure. fetchStatus shows regardless — // it is what explains an empty field after a pick. property string credentialsStatus: "" property string fetchStatus: "" property bool pickerOpen: false property int pickerIndex: 0 // Vault the list is narrowed to; "" is all of them. Kept across requests, // so a vault picked once stays picked. property string vaultFilter: "" property bool overflowMenuOpen: false // Height of the dialog alone. The adapters position on this rather than // implicitHeight, so expanding the vault panel grows downward instead of // shifting the dialog up under the cursor. readonly property real dialogHeight: panel.implicitHeight readonly property var vaultNames: { const names = []; for (const c of root.credentials) if (!names.includes(c.vault)) names.push(c.vault); return names.sort((a, b) => a.toLowerCase() < b.toLowerCase() ? -1 : a.toLowerCase() > b.toLowerCase() ? 1 : 0); } readonly property var vaultOptions: [""].concat(root.vaultNames) // A remembered vault that no longer exists falls back to all. readonly property string activeVault: root.vaultNames.includes(root.vaultFilter) ? root.vaultFilter : "" // Title A–Z within the chosen vault (or across all of them). readonly property var shownCredentials: { const q = filterInput.text.toLowerCase(); return root.credentials .filter(c => (root.activeVault === "" || c.vault === root.activeVault) && (q === "" || c.title.toLowerCase().includes(q))) .sort((a, b) => { const ta = a.title.toLowerCase(), tb = b.title.toLowerCase(); return ta < tb ? -1 : ta > tb ? 1 : 0; }); } function vaultLabel(name) { return name === "" ? "ALL" : name.toUpperCase(); } function vaultCount(name) { return name === "" ? root.credentials.length : root.credentials.filter(c => c.vault === name).length; } function tabText(name) { return root.vaultLabel(name) + " " + root.vaultCount(name); } // Tabs are sized from FontMetrics rather than their own implicitWidth, so // how many fit is known before any are laid out — the overflow split // would otherwise depend on the very tabs it decides to create. function tabWidth(text) { return Math.ceil(tabMetrics.advanceWidth(text) + text.length * tabMetrics.font.letterSpacing) + 16; } // How many leading vault options get a tab of their own; the rest go in // the overflow menu, which is always the last tab. // // The overflow tab names the selected vault when it holds it, so it is // sized for "MORE" first and, if the selection lands in the overflow, // re-split for that label. Shrinking can only push the selection further // into the overflow, so the second pass is final. readonly property int fittingTabs: { const avail = tabStrip.width; const widths = root.vaultOptions.map(v => root.tabWidth(root.tabText(v))); if (widths.reduce((a, b) => a + b, 0) <= avail) return widths.length; const split = reserve => { let used = reserve, k = 0; while (k < widths.length && used + widths[k] <= avail) used += widths[k++]; return Math.max(1, k); }; const k = split(root.tabWidth("MORE ▾")); return root.vaultOptions.indexOf(root.activeVault) >= k ? split(root.tabWidth(root.tabText(root.activeVault) + " ▾")) : k; } readonly property var overflowVaults: root.vaultOptions.slice(root.fittingTabs) signal submitted(string value) signal cancelled signal identityRequested(int index) signal credentialRequested(var entry) signal pickerOpened function focusInput() { responseInput.forceActiveFocus(); } function clearResponse() { responseInput.text = ""; root.revealed = false; root.closePicker(); } function openPicker() { if (!root.credentialsEnabled) return; filterInput.text = ""; root.pickerIndex = 0; root.overflowMenuOpen = false; root.pickerOpen = true; filterInput.forceActiveFocus(); root.pickerOpened(); } function closePicker() { if (!root.pickerOpen) return; root.overflowMenuOpen = false; root.pickerOpen = false; root.focusInput(); } function selectVault(index) { root.vaultFilter = root.vaultOptions[index] || ""; root.overflowMenuOpen = false; root.pickerIndex = 0; pickerList.positionViewAtBeginning(); filterInput.forceActiveFocus(); } function cycleVault(delta) { const n = root.vaultOptions.length; root.selectVault((Math.max(0, root.vaultOptions.indexOf(root.activeVault)) + delta + n) % n); } function pick(index) { const entry = root.shownCredentials[index]; if (!entry) return; root.closePicker(); root.credentialRequested(entry); } function movePicker(delta) { const n = root.shownCredentials.length; if (n > 0) root.pickerIndex = (root.pickerIndex + delta + n) % n; } onPickerIndexChanged: pickerList.positionViewAtIndex(root.pickerIndex, ListView.Contain) implicitWidth: 520 implicitHeight: stack.implicitHeight // Escape reaches here by propagating up the focus chain from the TextInput, // which does not consume it — so cancelling works whether or not the input // currently has focus. Keys.onEscapePressed: event => { root.cancelled(); event.accepted = true; } component MicroText: Text { color: Theme.muted font.family: Theme.microFont font.pixelSize: 8 font.letterSpacing: 0.9 elide: Text.ElideRight } // A vault tab. Sized by the caller from tabWidth(), not by its label: the // overflow split is computed before any tab exists. component VaultTab: Item { id: tab property string label: "" property bool current: false signal clicked MicroText { anchors.centerIn: parent text: tab.label color: tab.current ? Theme.accent : tabArea.containsMouse ? Theme.text : Theme.muted } Rectangle { visible: tab.current anchors.bottom: parent.bottom width: parent.width height: 2 color: Theme.accent } MouseArea { id: tabArea anchors.fill: parent hoverEnabled: true cursorShape: Qt.PointingHandCursor onClicked: tab.clicked() } } Column { id: stack width: root.width // Clears the detached corner caps between the two panels. spacing: 14 PolkitPanel { id: panel width: root.width panelId: "PKT" title: "AUTHORIZATION REQUIRED" // The action id is the one piece that says WHAT is being authorized // independently of the (localizable, often vague) message. meta: root.actionId // The body slot decides the width and the layout's implicitHeight // becomes its height, so a wrapped message or an extra pam_info line // grows the panel instead of being clipped. ColumnLayout { width: parent.width spacing: 10 // ---- what is being asked ---- RowLayout { Layout.fillWidth: true spacing: 10 IconImage { visible: root.showIcon && root.iconName !== "" implicitSize: 32 source: root.showIcon && root.iconName !== "" ? Quickshell.iconPath(root.iconName, "dialog-password") : "" } Text { Layout.fillWidth: true wrapMode: Text.Wrap text: root.message color: Theme.text font.family: Theme.displayFont font.pixelSize: 13 font.letterSpacing: 0.6 } } // ---- identity ---- // Single identity: stated, not offered. Several: chips, because a // combo box would be the only QtQuick.Controls widget in the rail. MicroText { Layout.fillWidth: true visible: root.identities.length === 1 text: "AS " + (root.identities.length === 1 ? root.identities[0].displayName : "") } Flow { Layout.fillWidth: true visible: root.identities.length > 1 spacing: 6 Repeater { model: root.identities Rectangle { id: chip required property int index required property var modelData readonly property bool current: chip.index === root.selectedIdentity width: chipLabel.implicitWidth + 14 height: chipLabel.implicitHeight + 8 color: chip.current ? Theme.accent : "transparent" border.width: 1 border.color: chip.current ? Theme.accent : Theme.disabled Text { id: chipLabel anchors.centerIn: parent text: chip.modelData.displayName color: chip.current ? Theme.surface : Theme.muted font.family: Theme.microFont font.pixelSize: 9 font.letterSpacing: 0.8 } MouseArea { anchors.fill: parent onClicked: root.identityRequested(chip.index) } } } } // ---- the conversation ---- Rectangle { Layout.fillWidth: true implicitHeight: 34 color: Theme.selection border.width: 1 border.color: root.failed ? Theme.hot : Theme.hair RowLayout { anchors.fill: parent anchors.leftMargin: 10 anchors.rightMargin: 10 spacing: 10 Text { text: ">_" color: root.responseRequired ? Theme.accent : Theme.disabled font.family: Theme.displayFont font.pixelSize: 15 font.bold: true } TextInput { id: responseInput Layout.fillWidth: true Layout.fillHeight: true verticalAlignment: TextInput.AlignVCenter enabled: root.responseRequired color: Theme.text selectionColor: Theme.accent selectedTextColor: Theme.surface font.family: Theme.displayFont font.pixelSize: 14 font.letterSpacing: 1 clip: true echoMode: root.responseVisible || root.revealed ? TextInput.Normal : TextInput.Password passwordCharacter: "▪" // Qt reveals the last typed character for a moment by // default. On a screen-visible layer-shell overlay // that is a shoulder-surfing hole, so: never. passwordMaskDelay: 0 onAccepted: { if (root.responseRequired) root.submitted(responseInput.text); } Keys.onTabPressed: event => { root.openPicker(); event.accepted = true; } // Placeholder: TextInput has none of its own, and the // PAM prompt ("Password:", "PIN:") is the only label // this field gets. Text { anchors.verticalCenter: parent.verticalCenter visible: responseInput.text.length === 0 text: root.inputPrompt color: Theme.disabled font: responseInput.font } } // Eye toggle. Hidden when PAM already asked for echoed // input — there is nothing left to reveal. Text { visible: !root.responseVisible text: root.revealed ? "" : "" color: root.revealed ? Theme.accent : (eyeArea.containsMouse ? Theme.text : Theme.muted) font.family: Theme.displayFont font.pixelSize: 14 MouseArea { id: eyeArea anchors.fill: parent anchors.margins: -6 hoverEnabled: true cursorShape: Qt.PointingHandCursor onClicked: { root.revealed = !root.revealed; root.focusInput(); } } } } } MicroText { Layout.fillWidth: true visible: root.credentialsEnabled && root.fetchStatus !== "" text: root.fetchStatus } // ---- pam_info / pam_error ---- Text { Layout.fillWidth: true visible: root.supplementaryMessage !== "" wrapMode: Text.Wrap text: root.supplementaryMessage color: root.supplementaryIsError ? Theme.hot : Theme.muted font.family: Theme.microFont font.pixelSize: 9 font.letterSpacing: 0.7 } // ---- key hints ---- RowLayout { Layout.fillWidth: true spacing: 14 MicroText { text: "ENTER AUTHENTICATE" } MicroText { text: "ESC CANCEL" } Item { Layout.fillWidth: true } MicroText { text: root.responseVisible ? "ECHO ON" : root.revealed ? "SHOWN" : "" color: Theme.hot } } } } // ---- Proton Pass ---- // Its own panel so the dialog keeps its shape; collapsed it is the header // strip alone. The MouseArea sits over that strip only — PolkitPanel's // default property is the body slot, so it cannot live inside the panel. Item { visible: root.credentialsEnabled width: root.width height: vaultPanel.implicitHeight PolkitPanel { id: vaultPanel width: parent.width panelId: "PSS" title: "PROTON PASS" collapsed: !root.pickerOpen meta: root.pickerOpen ? root.shownCredentials.length + " / " + root.credentials.length : "TAB OPEN" ColumnLayout { width: parent.width spacing: 6 // ---- vault tabs ---- // One row; tabs that do not fit move into the overflow // tab's menu. z above the filter and list, which the open // menu draws over. Item { id: tabStrip z: 2 Layout.fillWidth: true implicitHeight: 22 FontMetrics { id: tabMetrics font.family: Theme.microFont font.pixelSize: 8 font.letterSpacing: 0.9 } // The rule the tabs sit on, across the full width. Rectangle { anchors.bottom: parent.bottom width: parent.width height: 1 color: Theme.hair } Row { Repeater { model: root.vaultOptions.slice(0, root.fittingTabs) VaultTab { id: vaultTab required property int index required property string modelData width: root.tabWidth(vaultTab.label) height: tabStrip.height label: root.tabText(vaultTab.modelData) current: vaultTab.modelData === root.activeVault onClicked: root.selectVault(vaultTab.index) } } VaultTab { id: overflowTab readonly property bool holdsActive: root.overflowVaults.includes(root.activeVault) visible: root.overflowVaults.length > 0 width: root.tabWidth(overflowTab.label) height: tabStrip.height // Names the selected vault when it is one of // the hidden ones, so the selection stays visible. label: (overflowTab.holdsActive ? root.tabText(root.activeVault) : "MORE") + " ▾" current: overflowTab.holdsActive || root.overflowMenuOpen onClicked: root.overflowMenuOpen = !root.overflowMenuOpen Rectangle { visible: root.overflowMenuOpen // Right-aligned to the tab, clamped to the strip. x: Math.max(-overflowTab.x, overflowTab.width - width) y: overflowTab.height + 2 width: Math.max(180, overflowTab.width) height: overflowColumn.implicitHeight + 2 color: Theme.surface border.width: 1 border.color: Theme.accent Column { id: overflowColumn x: 1 y: 1 width: parent.width - 2 Repeater { model: root.overflowVaults Rectangle { id: option required property int index required property string modelData readonly property bool current: option.modelData === root.activeVault width: overflowColumn.width height: 22 color: optionArea.containsMouse ? Theme.selection : "transparent" Rectangle { visible: option.current width: 2 height: parent.height color: Theme.accent } MicroText { anchors.left: parent.left anchors.leftMargin: 10 anchors.verticalCenter: parent.verticalCenter text: root.vaultLabel(option.modelData) color: option.current ? Theme.accent : optionArea.containsMouse ? Theme.text : Theme.muted } MicroText { anchors.right: parent.right anchors.rightMargin: 8 anchors.verticalCenter: parent.verticalCenter text: root.vaultCount(option.modelData) } MouseArea { id: optionArea anchors.fill: parent hoverEnabled: true cursorShape: Qt.PointingHandCursor onClicked: root.selectVault(root.fittingTabs + option.index) } } } } } } } } RowLayout { Layout.fillWidth: true spacing: 8 TextInput { id: filterInput Layout.fillWidth: true color: Theme.text selectionColor: Theme.accent selectedTextColor: Theme.surface font.family: Theme.displayFont font.pixelSize: 12 clip: true onTextChanged: root.pickerIndex = 0 onAccepted: root.pick(root.pickerIndex) // Consumed so Esc backs out of the panel instead // of cancelling the whole request. Keys.onEscapePressed: event => { if (root.overflowMenuOpen) root.overflowMenuOpen = false; else root.closePicker(); event.accepted = true; } Keys.onTabPressed: event => { root.cycleVault(1); event.accepted = true; } Keys.onBacktabPressed: event => { root.cycleVault(-1); event.accepted = true; } Keys.onUpPressed: event => { root.movePicker(-1); event.accepted = true; } Keys.onDownPressed: event => { root.movePicker(1); event.accepted = true; } Text { anchors.verticalCenter: parent.verticalCenter visible: filterInput.text.length === 0 text: "filter logins" color: Theme.disabled font: filterInput.font } } } MicroText { Layout.fillWidth: true visible: text !== "" text: root.credentialsStatus !== "" ? root.credentialsStatus : root.shownCredentials.length === 0 ? "NO MATCH" : "" } ListView { id: pickerList readonly property int rowHeight: 24 Layout.fillWidth: true implicitHeight: Math.min(count, 10) * rowHeight visible: count > 0 clip: true boundsBehavior: Flickable.StopAtBounds model: root.shownCredentials delegate: Rectangle { id: row required property int index required property var modelData readonly property bool current: row.index === root.pickerIndex width: pickerList.width height: pickerList.rowHeight color: row.current ? Theme.selection : "transparent" Rectangle { visible: row.current width: 2 height: parent.height color: Theme.accent } RowLayout { anchors.fill: parent anchors.leftMargin: 10 anchors.rightMargin: 6 spacing: 10 Text { Layout.fillWidth: true text: row.modelData.title elide: Text.ElideRight color: row.current ? Theme.text : Theme.muted font.family: Theme.displayFont font.pixelSize: 12 } // Only useful when the list spans vaults. MicroText { visible: root.activeVault === "" text: row.modelData.vault.toUpperCase() } } MouseArea { anchors.fill: parent onClicked: root.pick(row.index) } } } RowLayout { Layout.fillWidth: true spacing: 14 MicroText { text: "↑↓ SELECT" } MicroText { text: "ENTER FILL" } MicroText { text: "TAB VAULT" } MicroText { text: "ESC BACK" } } } } MouseArea { width: parent.width height: vaultPanel.headerHeight cursorShape: Qt.PointingHandCursor onClicked: root.pickerOpen ? root.closePicker() : root.openPicker() } } } }