From 9177d1b378a02230234c19d585b1a9359a67c1cb Mon Sep 17 00:00:00 2001 From: Chintan Patel <216989679+Chintanpatel24@users.noreply.github.com> Date: Mon, 16 Nov 2026 11:59:20 +0530 Subject: [PATCH] fix(wifi): resolve connection status flapping, inline password input focus, and credential update --- crates/agility-cli/src/tools/connectivity.rs | 217 ++++++++-- .../Components/ControlCenterListDelegate.qml | 55 ++- .../QuickSettings/Components/WifiControl.qml | 53 ++- .../QuickSettings/Components/WifiList.qml | 369 +++++++++++++++--- .../Widgets/QuickSettings/QuickSettings.qml | 6 + 5 files changed, 579 insertions(+), 121 deletions(-) diff --git a/crates/agility-cli/src/tools/connectivity.rs b/crates/agility-cli/src/tools/connectivity.rs index aa435061..ca061272 100644 --- a/crates/agility-cli/src/tools/connectivity.rs +++ b/crates/agility-cli/src/tools/connectivity.rs @@ -142,6 +142,31 @@ pub fn run_bluetooth(args: &[String]) -> i32 { // ─── WiFi ─── +fn split_nmcli_escaped(line: &str) -> Vec { + let mut fields = Vec::new(); + let mut current = String::new(); + let mut chars = line.chars().peekable(); + while let Some(c) = chars.next() { + if c == '\\' { + if let Some(&next_c) = chars.peek() { + if next_c == ':' || next_c == '\\' { + current.push(next_c); + chars.next(); + continue; + } + } + current.push('\\'); + } else if c == ':' { + fields.push(current.clone()); + current.clear(); + } else { + current.push(c); + } + } + fields.push(current); + fields +} + #[derive(Debug, Clone, Serialize, Deserialize)] pub struct WifiStatus { pub radio: bool, @@ -172,6 +197,33 @@ pub fn get_wifi_status() -> WifiStatus { .unwrap_or_default(); let radio = radio_out.contains("enabled"); + let mut interface = String::new(); + let mut connected_ssid = "Disconnected".to_string(); + let mut strength = 0; + + // 1. Direct query of active in-use wifi network (highest accuracy) + let sig_out = Command::new("nmcli") + .args(["-t", "-f", "IN-USE,SSID,SIGNAL", "device", "wifi"]) + .output() + .ok() + .and_then(|o| String::from_utf8(o.stdout).ok()) + .unwrap_or_default(); + + for line in sig_out.lines() { + let parts = split_nmcli_escaped(line); + if parts.len() >= 2 && parts[0].contains('*') { + let ssid = parts[1].trim(); + if !ssid.is_empty() && ssid != "--" { + connected_ssid = ssid.to_string(); + } + if parts.len() >= 3 { + strength = parts[2].trim().parse::().unwrap_or(0); + } + break; + } + } + + // 2. Discover interface and connection name from nmcli device let dev_out = Command::new("nmcli") .args(["-t", "-f", "DEVICE,TYPE,STATE,CONNECTION", "device"]) .output() @@ -179,32 +231,31 @@ pub fn get_wifi_status() -> WifiStatus { .and_then(|o| String::from_utf8(o.stdout).ok()) .unwrap_or_default(); - let mut interface = String::new(); - let mut connected_ssid = "Disconnected".to_string(); - for line in dev_out.lines() { - let parts: Vec<&str> = line.split(':').collect(); + let parts = split_nmcli_escaped(line); if parts.len() >= 3 && parts[1] == "wifi" { - interface = parts[0].to_string(); - if parts[2] == "connected" && parts.len() >= 4 && !parts[3].is_empty() { - connected_ssid = parts[3].to_string(); + if interface.is_empty() { + interface = parts[0].to_string(); + } + if parts[2].starts_with("connected") && parts.len() >= 4 && !parts[3].is_empty() { + if connected_ssid == "Disconnected" { + connected_ssid = parts[3].to_string(); + } + } + if parts[2].starts_with("connected") { + interface = parts[0].to_string(); + break; } - break; } } - let mut strength = 0; - if connected_ssid != "Disconnected" { - let sig_out = Command::new("nmcli") - .args(["-t", "-f", "IN-USE,SIGNAL", "device", "wifi"]) - .output() - .ok() - .and_then(|o| String::from_utf8(o.stdout).ok()) - .unwrap_or_default(); + // If strength wasn't resolved yet but we are connected, query signal for this SSID + if connected_ssid != "Disconnected" && strength == 0 { for line in sig_out.lines() { - if line.starts_with('*') { - if let Some(s) = line.split(':').nth(1) { - strength = s.trim().parse::().unwrap_or(0); + let parts = split_nmcli_escaped(line); + if parts.len() >= 3 && parts[1].trim() == connected_ssid { + strength = parts[2].trim().parse::().unwrap_or(0); + if strength > 0 { break; } } @@ -244,7 +295,7 @@ pub fn get_wifi_networks() -> Vec { let mut saved_ssids = std::collections::HashSet::new(); for line in saved_out.lines() { - let parts: Vec<&str> = line.split(':').collect(); + let parts = split_nmcli_escaped(line); if parts.len() >= 2 && (parts[1].contains("wireless") || parts[1].contains("wifi") @@ -268,36 +319,80 @@ pub fn get_wifi_networks() -> Vec { .and_then(|o| String::from_utf8(o.stdout).ok()) .unwrap_or_default(); - let mut networks = Vec::new(); - let mut seen_ssids = std::collections::HashSet::new(); + // Map by SSID to correctly aggregate multi-BSSID networks (e.g. 2.4GHz + 5GHz) + let mut network_map: std::collections::HashMap = + std::collections::HashMap::new(); + for line in out.lines() { - let parts: Vec<&str> = line.split(':').collect(); + let parts = split_nmcli_escaped(line); if parts.len() >= 4 { - let in_use = parts[0] == "*"; + let in_use = parts[0].contains('*'); let ssid = parts[1].trim().to_string(); if ssid.is_empty() || ssid == "--" { continue; } - if seen_ssids.contains(&ssid) { - continue; - } - seen_ssids.insert(ssid.clone()); let strength = parts[2].trim().parse::().unwrap_or(0); let security = parts[3].trim().to_string(); let saved = saved_ssids.contains(&ssid) || in_use; - networks.push(WifiNetwork { - ssid, - in_use, - active: in_use, - strength, - signal: strength, - security, - saved, - }); + if let Some(existing) = network_map.get_mut(&ssid) { + if in_use { + existing.in_use = true; + existing.active = true; + existing.saved = true; + } + if strength > existing.strength { + existing.strength = strength; + existing.signal = strength; + } + if (existing.security.is_empty() || existing.security == "--") && !security.is_empty() { + existing.security = security; + } + } else { + network_map.insert( + ssid.clone(), + WifiNetwork { + ssid, + in_use, + active: in_use, + strength, + signal: strength, + security, + saved, + }, + ); + } } } + // Cross-reference with current wifi status so active connection is always flagged + let current_status = get_wifi_status(); + if current_status.connected_ssid != "Disconnected" && !current_status.connected_ssid.is_empty() { + if let Some(entry) = network_map.get_mut(¤t_status.connected_ssid) { + entry.in_use = true; + entry.active = true; + entry.saved = true; + if current_status.strength > entry.strength { + entry.strength = current_status.strength; + entry.signal = current_status.strength; + } + } else { + network_map.insert( + current_status.connected_ssid.clone(), + WifiNetwork { + ssid: current_status.connected_ssid.clone(), + in_use: true, + active: true, + strength: current_status.strength, + signal: current_status.strength, + security: "Secured".to_string(), + saved: true, + }, + ); + } + } + + let mut networks: Vec = network_map.into_values().collect(); networks.sort_by(|a, b| { b.in_use .cmp(&a.in_use) @@ -338,7 +433,7 @@ pub fn run_wifi(args: &[String]) -> i32 { if let Some(ssid) = args.get(1) { let password = args.get(2).map(|s| s.as_str()).unwrap_or(""); - // 1. If password is not explicitly provided, try activating an existing saved NetworkManager connection first + // 1. If password is not provided, try activating existing connection first if password.is_empty() { let up_out = Command::new("nmcli") .args(["connection", "up", "id", ssid]) @@ -352,7 +447,7 @@ pub fn run_wifi(args: &[String]) -> i32 { } } - // 2. Connect directly to device wifi (works for unsecured or password-provided networks) + // 2. Connect directly to device wifi let mut cmd = Command::new("nmcli"); cmd.args(["device", "wifi", "connect", ssid]); if !password.is_empty() { @@ -366,8 +461,48 @@ pub fn run_wifi(args: &[String]) -> i32 { println!("{}", msg.trim()); 0 } else { - // If direct connect failed and no password was passed, try fallback connection up - if password.is_empty() { + // If direct connect failed with a password, the connection profile might already exist with old settings. + // Update the existing profile or delete and recreate with the new password. + if !password.is_empty() { + // Try updating the existing connection's password + let _ = Command::new("nmcli") + .args([ + "connection", + "modify", + "id", + ssid, + "802-11-wireless-security.key-mgmt", + "wpa-psk", + "802-11-wireless-security.psk", + password, + ]) + .output(); + if let Ok(retry) = Command::new("nmcli") + .args(["connection", "up", "id", ssid]) + .output() + { + if retry.status.success() { + let msg = String::from_utf8_lossy(&retry.stdout); + println!("{}", msg.trim()); + return 0; + } + } + + // If modifying didn't work, delete old connection profile and re-run connect with password + let _ = Command::new("nmcli") + .args(["connection", "delete", "id", ssid]) + .output(); + if let Ok(fresh) = Command::new("nmcli") + .args(["device", "wifi", "connect", ssid, "password", password]) + .output() + { + if fresh.status.success() { + let msg = String::from_utf8_lossy(&fresh.stdout); + println!("{}", msg.trim()); + return 0; + } + } + } else { if let Ok(retry) = Command::new("nmcli") .args(["connection", "up", "id", ssid]) .output() diff --git a/quickshell/agility/Modules/ControlCenter/Widgets/QuickSettings/Components/ControlCenterListDelegate.qml b/quickshell/agility/Modules/ControlCenter/Widgets/QuickSettings/Components/ControlCenterListDelegate.qml index 8f54a09a..e3a031be 100644 --- a/quickshell/agility/Modules/ControlCenter/Widgets/QuickSettings/Components/ControlCenterListDelegate.qml +++ b/quickshell/agility/Modules/ControlCenter/Widgets/QuickSettings/Components/ControlCenterListDelegate.qml @@ -11,19 +11,36 @@ Rectangle { property string iconName: "" property bool isActive: false property bool canForget: false + property bool canEditPassword: false + property bool isConnecting: false signal clicked() signal actionClicked() signal disconnectClicked() signal forgetClicked() + signal editPasswordClicked() Layout.fillWidth: true width: parent ? parent.width : 280 implicitHeight: 52 radius: Constants.sizeSm - color: Theme.bgTertiary + color: rootHover.hovered ? Theme.bgSecondary : Theme.bgTertiary border.width: 1 - border.color: Theme.border + border.color: rootHover.hovered ? Theme.accent : Theme.border + + HoverHandler { + id: rootHover + cursorShape: Qt.PointingHandCursor + } + + TapHandler { + onTapped: { + if (root.isActive) + root.disconnectClicked(); + else + root.clicked(); + } + } RowLayout { anchors.fill: parent @@ -80,6 +97,36 @@ Rectangle { } + Rectangle { + id: keyBtn + + visible: root.canEditPassword + Layout.alignment: Qt.AlignVCenter + implicitWidth: Constants.size2Xl + 4 + implicitHeight: Constants.size2Xl + 4 + radius: Constants.sizeSm + color: keyHover.hovered ? Theme.bgSecondary : "transparent" + border.width: 1 + border.color: keyHover.hovered ? Theme.border : "transparent" + + SvgIcon { + anchors.centerIn: parent + icon: "lock" + iconColor: keyHover.hovered ? Theme.accent : Theme.muted + iconSize: Constants.sizeSm + 2 + flat: true + } + + HoverHandler { + id: keyHover + cursorShape: Qt.PointingHandCursor + } + + TapHandler { + onTapped: root.editPasswordClicked() + } + } + Rectangle { id: forgetBtn @@ -126,8 +173,8 @@ Rectangle { ThemedText { id: btnText - text: root.isActive ? "Disconnect" : "Connect" - color: root.isActive ? Theme.accentComplementary : Theme.fg + text: root.isConnecting ? "Connecting..." : (root.isActive ? "Disconnect" : "Connect") + color: root.isConnecting ? Theme.accent : (root.isActive ? Theme.accentComplementary : Theme.fg) customSize: Constants.sizeXs + 2 font.bold: true anchors.centerIn: parent diff --git a/quickshell/agility/Modules/ControlCenter/Widgets/QuickSettings/Components/WifiControl.qml b/quickshell/agility/Modules/ControlCenter/Widgets/QuickSettings/Components/WifiControl.qml index 9c8a7fed..79bafd2d 100644 --- a/quickshell/agility/Modules/ControlCenter/Widgets/QuickSettings/Components/WifiControl.qml +++ b/quickshell/agility/Modules/ControlCenter/Widgets/QuickSettings/Components/WifiControl.qml @@ -12,12 +12,17 @@ QuickSettingsTile { property bool expanded: false property bool isScanning: wifiScanProc.running + property bool isConnecting: wifiConnectProc.running + property string connectingSsid: "" + property string connectError: "" + property bool isPromptOpen: false property var wifiList: [] property string connectedSsid: "Disconnected" property string currentSsid: { if (!isActive) return "Off"; - + if (isConnecting && connectingSsid.length > 0) + return "Connecting..."; return connectedSsid; } property bool isVisible: true @@ -29,7 +34,7 @@ QuickSettingsTile { } function scan(forceRescan) { - if (!root.isActive) + if (!root.isActive || root.isPromptOpen) return ; let rescan = (forceRescan === undefined) ? true : forceRescan; @@ -39,6 +44,8 @@ QuickSettingsTile { } function connect(ssid, password) { + root.connectingSsid = ssid; + root.connectError = ""; let cmd = ["python3", Quickshell.shellDir + "/Modules/ControlCenter/scripts/wifi.py", "connect", ssid]; if (password) { cmd.push(password); @@ -53,35 +60,39 @@ QuickSettingsTile { subtitle: root.currentSsid onClicked: root.toggle() onExpandedChanged: { - if (expanded) + if (expanded && !isPromptOpen) scan(true); } onIsActiveChanged: { if (isActive) { - scan(false); - if (expanded) - scan(true); + if (!isPromptOpen) { + scan(false); + if (expanded) + scan(true); + } } else { wifiList = []; connectedSsid = "Disconnected"; + connectingSsid = ""; + connectError = ""; } } onIsVisibleChanged: { - if (isVisible && isActive && root.wifiList.length === 0) + if (isVisible && isActive && root.wifiList.length === 0 && !isPromptOpen) scan(false); } Component.onCompleted: { - if (isActive && root.wifiList.length === 0) + if (isActive && root.wifiList.length === 0 && !isPromptOpen) scan(false); } Timer { interval: 2000 - running: root.isVisible + running: root.isVisible && !root.isPromptOpen repeat: true triggeredOnStart: true onTriggered: { @@ -102,7 +113,13 @@ QuickSettingsTile { try { let st = JSON.parse(data.trim()); root.isActive = st.radio; - root.connectedSsid = st.connected_ssid || "Disconnected"; + if (st.connected_ssid && st.connected_ssid !== "" && st.connected_ssid !== "Disconnected") { + root.connectedSsid = st.connected_ssid; + } else if (!st.radio) { + root.connectedSsid = "Disconnected"; + } else if (!root.isConnecting) { + root.connectedSsid = "Disconnected"; + } } catch (e) { } } @@ -127,7 +144,7 @@ QuickSettingsTile { stdout: SplitParser { onRead: (data) => { - if (!data) + if (!data || root.isPromptOpen) return ; try { @@ -145,10 +162,22 @@ QuickSettingsTile { Process { id: wifiConnectProc + stderr: SplitParser { + onRead: (data) => { + if (data && data.trim().length > 0) { + root.connectError = data.trim(); + } + } + } + onRunningChanged: { if (!running) { + if (root.connectError.length === 0) { + root.connectingSsid = ""; + } wifiGetProc.running = true; - root.scan(true); + if (!root.isPromptOpen) + root.scan(true); } } } diff --git a/quickshell/agility/Modules/ControlCenter/Widgets/QuickSettings/Components/WifiList.qml b/quickshell/agility/Modules/ControlCenter/Widgets/QuickSettings/Components/WifiList.qml index fb6228e6..9b3e3d45 100644 --- a/quickshell/agility/Modules/ControlCenter/Widgets/QuickSettings/Components/WifiList.qml +++ b/quickshell/agility/Modules/ControlCenter/Widgets/QuickSettings/Components/WifiList.qml @@ -13,6 +13,10 @@ Rectangle { property bool isActive: false property var wifiList: [] property bool isScanning: false + property bool isConnecting: false + property string connectingSsid: "" + property string errorMessage: "" + property string lastAttemptedSsid: "" property bool timedOut: false property bool isVisible: true property string passwordPromptSsid: "" @@ -155,25 +159,188 @@ Rectangle { Repeater { model: root.savedList - ControlCenterListDelegate { + ColumnLayout { Layout.fillWidth: true - width: parent.width - titleText: modelData.ssid - subtitleText: (modelData.active || modelData.in_use) ? ("Connected • " + ((modelData.signal || modelData.strength) > 75 ? "Excellent signal" : ((modelData.signal || modelData.strength) > 50 ? "Good signal" : "Weak signal"))) : ((modelData.signal || modelData.strength) > 75 ? "Excellent signal" : ((modelData.signal || modelData.strength) > 50 ? "Good signal" : "Weak signal")) - iconName: root.getWifiIcon(modelData.signal || modelData.strength) - isActive: modelData.active || modelData.in_use - canForget: true - onClicked: root.connect(modelData.ssid, "") - onActionClicked: { - settingsProc.running = true; - } - onDisconnectClicked: { - disconnectProc.command = ["python3", Quickshell.shellDir + "/Modules/ControlCenter/scripts/wifi.py", "disconnect", modelData.ssid]; - disconnectProc.running = true; + spacing: Constants.size2Xs + + ControlCenterListDelegate { + Layout.fillWidth: true + width: parent.width + titleText: modelData.ssid + subtitleText: { + if (modelData.active || modelData.in_use) { + let sig = (modelData.signal || modelData.strength); + let quality = sig > 75 ? "Excellent signal" : (sig > 50 ? "Good signal" : "Weak signal"); + return "Connected • " + quality; + } + if (root.isConnecting && root.connectingSsid === modelData.ssid) + return "Connecting..."; + if (root.errorMessage !== "" && root.lastAttemptedSsid === modelData.ssid) + return root.errorMessage; + let sig = (modelData.signal || modelData.strength); + return sig > 75 ? "Excellent signal" : (sig > 50 ? "Good signal" : "Weak signal"); + } + iconName: root.getWifiIcon(modelData.signal || modelData.strength) + isActive: modelData.active || modelData.in_use + isConnecting: root.isConnecting && root.connectingSsid === modelData.ssid + canForget: true + canEditPassword: (modelData.security && modelData.security !== "--" && modelData.security !== "none") + onClicked: { + if (modelData.active || modelData.in_use) { + disconnectProc.command = ["python3", Quickshell.shellDir + "/Modules/ControlCenter/scripts/wifi.py", "disconnect", modelData.ssid]; + disconnectProc.running = true; + } else { + root.lastAttemptedSsid = modelData.ssid; + root.connect(modelData.ssid, ""); + } + } + onEditPasswordClicked: { + root.passwordPromptSsid = (root.passwordPromptSsid === modelData.ssid) ? "" : modelData.ssid; + } + onActionClicked: { + settingsProc.running = true; + } + onDisconnectClicked: { + disconnectProc.command = ["python3", Quickshell.shellDir + "/Modules/ControlCenter/scripts/wifi.py", "disconnect", modelData.ssid]; + disconnectProc.running = true; + } + onForgetClicked: { + forgetProc.command = ["python3", Quickshell.shellDir + "/Modules/ControlCenter/scripts/wifi.py", "forget", modelData.ssid]; + forgetProc.running = true; + } } - onForgetClicked: { - forgetProc.command = ["python3", Quickshell.shellDir + "/Modules/ControlCenter/scripts/wifi.py", "forget", modelData.ssid]; - forgetProc.running = true; + + // Inline password card for saved network (change password) + Rectangle { + id: savedPasswordCard + visible: root.passwordPromptSsid === modelData.ssid + Layout.fillWidth: true + implicitHeight: 46 + radius: Constants.sizeSm + color: Theme.bgSecondary + border.width: 1 + border.color: Theme.accent + + FocusScope { + anchors.fill: parent + focus: true + + RowLayout { + anchors.fill: parent + anchors.leftMargin: Constants.sizeSm + anchors.rightMargin: Constants.sizeSm + spacing: Constants.sizeSm + + SvgIcon { + icon: "lock" + iconSize: Constants.sizeSm + 2 + iconColor: Theme.accent + flat: true + Layout.alignment: Qt.AlignVCenter + } + + TextField { + id: savedPwField + Layout.fillWidth: true + Layout.fillHeight: true + Layout.alignment: Qt.AlignVCenter + verticalAlignment: TextInput.AlignVCenter + placeholderText: "Enter New Wi-Fi Password" + echoMode: savedRevealPass ? TextInput.Normal : TextInput.Password + color: Theme.fg + placeholderTextColor: Theme.muted + background: null + font.pixelSize: Constants.sizeSm + selectByMouse: true + focus: true + + property bool savedRevealPass: false + + Component.onCompleted: { + if (savedPasswordCard.visible) { + forceActiveFocus(); + Qt.callLater(() => forceActiveFocus()); + } + } + + Connections { + target: savedPasswordCard + function onVisibleChanged() { + if (savedPasswordCard.visible) { + savedPwField.text = ""; + savedPwField.forceActiveFocus(); + Qt.callLater(() => savedPwField.forceActiveFocus()); + } + } + } + + Keys.priority: Keys.BeforeItem + Keys.onEscapePressed: function(event) { + root.passwordPromptSsid = ""; + event.accepted = true; + } + + onAccepted: { + if (text.length > 0) { + root.lastAttemptedSsid = modelData.ssid; + root.connect(modelData.ssid, text); + root.passwordPromptSsid = ""; + } + } + } + + SvgIconButton { + icon: savedPwField.savedRevealPass ? "eye" : "eye-off" + iconSize: Constants.sizeSm + iconColor: Theme.muted + hoverColor: Theme.accent + flat: true + Layout.alignment: Qt.AlignVCenter + onClicked: { + savedPwField.savedRevealPass = !savedPwField.savedRevealPass; + savedPwField.forceActiveFocus(); + } + } + + Rectangle { + implicitWidth: 64 + implicitHeight: 28 + radius: Constants.sizeXs + color: savedPwField.text.length > 0 ? Theme.accent : Theme.bgTertiary + Layout.alignment: Qt.AlignVCenter + + ThemedText { + anchors.centerIn: parent + text: (root.isConnecting && root.connectingSsid === modelData.ssid) ? "..." : "Save" + customSize: Constants.sizeXs + 2 + font.bold: true + color: savedPwField.text.length > 0 ? Theme.bg : Theme.muted + } + + MouseArea { + anchors.fill: parent + cursorShape: Qt.PointingHandCursor + onClicked: { + if (savedPwField.text.length > 0) { + root.lastAttemptedSsid = modelData.ssid; + root.connect(modelData.ssid, savedPwField.text); + root.passwordPromptSsid = ""; + } + } + } + } + + SvgIconButton { + icon: "x" + iconSize: Constants.sizeSm + flat: true + Layout.alignment: Qt.AlignVCenter + onClicked: { + root.passwordPromptSsid = ""; + } + } + } + } } } @@ -208,20 +375,33 @@ Rectangle { Layout.fillWidth: true width: parent.width titleText: modelData.ssid - subtitleText: (modelData.security && modelData.security !== "--" && modelData.security !== "none") ? ("Secured (" + modelData.security + ")") : ((modelData.signal || modelData.strength) > 75 ? "Excellent signal" : ((modelData.signal || modelData.strength) > 50 ? "Good signal" : "Weak signal")) + subtitleText: { + if (root.isConnecting && root.connectingSsid === modelData.ssid) + return "Connecting..."; + if (root.errorMessage !== "" && root.lastAttemptedSsid === modelData.ssid) + return root.errorMessage; + let isSecured = (modelData.security && modelData.security !== "--" && modelData.security !== "none"); + let sec = isSecured ? ("Secured (" + modelData.security + ") • ") : ""; + let sig = (modelData.signal || modelData.strength); + let quality = sig > 75 ? "Excellent signal" : (sig > 50 ? "Good signal" : "Weak signal"); + return sec + quality; + } iconName: root.getWifiIcon(modelData.signal || modelData.strength) isActive: false + isConnecting: root.isConnecting && root.connectingSsid === modelData.ssid onClicked: { if (modelData.security && modelData.security !== "--" && modelData.security !== "none") { root.passwordPromptSsid = (root.passwordPromptSsid === modelData.ssid) ? "" : modelData.ssid; } else { + root.lastAttemptedSsid = modelData.ssid; root.connect(modelData.ssid, ""); } } } - // Inline password card for secured network + // Inline password card for secured available network Rectangle { + id: availablePasswordCard visible: root.passwordPromptSsid === modelData.ssid Layout.fillWidth: true implicitHeight: 46 @@ -230,62 +410,123 @@ Rectangle { border.width: 1 border.color: Theme.accent - RowLayout { + FocusScope { anchors.fill: parent - anchors.leftMargin: Constants.sizeSm - anchors.rightMargin: Constants.sizeSm - spacing: Constants.sizeSm - - TextField { - id: pwField - Layout.fillWidth: true - placeholderText: "Enter Wi-Fi Password" - echoMode: TextInput.Password - color: Theme.fg - placeholderTextColor: Theme.muted - background: null - font.pixelSize: Constants.sizeSm - onAccepted: { - if (text.length > 0) { - root.connect(modelData.ssid, text); + focus: true + + RowLayout { + anchors.fill: parent + anchors.leftMargin: Constants.sizeSm + anchors.rightMargin: Constants.sizeSm + spacing: Constants.sizeSm + + SvgIcon { + icon: "lock" + iconSize: Constants.sizeSm + 2 + iconColor: Theme.accent + flat: true + Layout.alignment: Qt.AlignVCenter + } + + TextField { + id: pwField + Layout.fillWidth: true + Layout.fillHeight: true + Layout.alignment: Qt.AlignVCenter + verticalAlignment: TextInput.AlignVCenter + placeholderText: "Enter Wi-Fi Password" + echoMode: revealPass ? TextInput.Normal : TextInput.Password + color: Theme.fg + placeholderTextColor: Theme.muted + background: null + font.pixelSize: Constants.sizeSm + selectByMouse: true + focus: true + + property bool revealPass: false + + Component.onCompleted: { + if (availablePasswordCard.visible) { + forceActiveFocus(); + Qt.callLater(() => forceActiveFocus()); + } + } + + Connections { + target: availablePasswordCard + function onVisibleChanged() { + if (availablePasswordCard.visible) { + pwField.text = ""; + pwField.forceActiveFocus(); + Qt.callLater(() => pwField.forceActiveFocus()); + } + } + } + + Keys.priority: Keys.BeforeItem + Keys.onEscapePressed: function(event) { root.passwordPromptSsid = ""; + event.accepted = true; } - } - } - Rectangle { - implicitWidth: 64 - implicitHeight: 28 - radius: Constants.sizeXs - color: pwField.text.length > 0 ? Theme.accent : Theme.bgTertiary - Layout.alignment: Qt.AlignVCenter - - ThemedText { - anchors.centerIn: parent - text: "Join" - customSize: Constants.sizeXs + 2 - font.bold: true - color: pwField.text.length > 0 ? Theme.bg : Theme.muted + onAccepted: { + if (text.length > 0) { + root.lastAttemptedSsid = modelData.ssid; + root.connect(modelData.ssid, text); + root.passwordPromptSsid = ""; + } + } } - MouseArea { - anchors.fill: parent - cursorShape: Qt.PointingHandCursor + SvgIconButton { + icon: pwField.revealPass ? "eye" : "eye-off" + iconSize: Constants.sizeSm + iconColor: Theme.muted + hoverColor: Theme.accent + flat: true + Layout.alignment: Qt.AlignVCenter onClicked: { - if (pwField.text.length > 0) { - root.connect(modelData.ssid, pwField.text); - root.passwordPromptSsid = ""; + pwField.revealPass = !pwField.revealPass; + pwField.forceActiveFocus(); + } + } + + Rectangle { + implicitWidth: 64 + implicitHeight: 28 + radius: Constants.sizeXs + color: pwField.text.length > 0 ? Theme.accent : Theme.bgTertiary + Layout.alignment: Qt.AlignVCenter + + ThemedText { + anchors.centerIn: parent + text: (root.isConnecting && root.connectingSsid === modelData.ssid) ? "..." : "Join" + customSize: Constants.sizeXs + 2 + font.bold: true + color: pwField.text.length > 0 ? Theme.bg : Theme.muted + } + + MouseArea { + anchors.fill: parent + cursorShape: Qt.PointingHandCursor + onClicked: { + if (pwField.text.length > 0) { + root.lastAttemptedSsid = modelData.ssid; + root.connect(modelData.ssid, pwField.text); + root.passwordPromptSsid = ""; + } } } } - } - SvgIconButton { - icon: "x" - iconSize: Constants.sizeSm - flat: true - onClicked: { - root.passwordPromptSsid = ""; + SvgIconButton { + icon: "x" + iconSize: Constants.sizeSm + flat: true + Layout.alignment: Qt.AlignVCenter + onClicked: { + root.passwordPromptSsid = ""; + } } } } diff --git a/quickshell/agility/Modules/ControlCenter/Widgets/QuickSettings/QuickSettings.qml b/quickshell/agility/Modules/ControlCenter/Widgets/QuickSettings/QuickSettings.qml index fddfb81a..12f86e9a 100644 --- a/quickshell/agility/Modules/ControlCenter/Widgets/QuickSettings/QuickSettings.qml +++ b/quickshell/agility/Modules/ControlCenter/Widgets/QuickSettings/QuickSettings.qml @@ -247,12 +247,18 @@ Item { isActive: wifiControl.isActive wifiList: wifiControl.wifiList isScanning: wifiControl.isScanning + isConnecting: wifiControl.isConnecting + connectingSsid: wifiControl.connectingSsid + errorMessage: wifiControl.connectError onConnect: (ssid, password) => { return wifiControl.connect(ssid, password); } onRefreshRequested: { wifiControl.scan(true); } + onPasswordPromptSsidChanged: { + wifiControl.isPromptOpen = (passwordPromptSsid !== ""); + } } Behavior on x {