From d01e0d85fbd2836489d8092381fc4637fc51ce25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vuka=C5=A1in=20Vojinovi=C4=87?= Date: Wed, 4 Dec 2024 03:25:56 +0100 Subject: [PATCH] fix(bluetooth): remove cog next to toggle This makes the page behave as if the settings cog toggle is always enabled. --- Cargo.lock | 6 +- cosmic-settings/src/pages/bluetooth/mod.rs | 121 ++++++--------------- i18n/en/cosmic_settings.ftl | 1 - 3 files changed, 34 insertions(+), 94 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f0f880d..300c524 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3993,9 +3993,9 @@ dependencies = [ [[package]] name = "io-lifetimes" -version = "2.0.3" +version = "2.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a611371471e98973dbcab4e0ec66c31a10bc356eeb4d54a0e05eac8158fe38c" +checksum = "06432fb54d3be7964ecd3649233cddf80db2832f47fec34c01f65b3d9d774983" [[package]] name = "is_terminal_polyfill" @@ -7775,7 +7775,7 @@ checksum = "c89532cc712a2adb119eb4d09694b402576052254d0bb284f82ac1c47fb786ad" dependencies = [ "bitflags 2.6.0", "downcast-rs", - "io-lifetimes 2.0.3", + "io-lifetimes 2.0.4", "rustix 0.38.41", "wayland-backend", "wayland-scanner", diff --git a/cosmic-settings/src/pages/bluetooth/mod.rs b/cosmic-settings/src/pages/bluetooth/mod.rs index cafba63..a3f9555 100644 --- a/cosmic-settings/src/pages/bluetooth/mod.rs +++ b/cosmic-settings/src/pages/bluetooth/mod.rs @@ -4,8 +4,7 @@ use cosmic::iced::{color, Alignment, Length}; use cosmic::iced_core::text::Wrapping; use cosmic::widget::{self, settings, text}; -use cosmic::Task; -use cosmic::{Apply, Element}; +use cosmic::{theme, Apply, Element, Task}; use cosmic_settings_page::{self as page, section, Section}; use futures::channel::oneshot; use slab::Slab; @@ -50,7 +49,6 @@ pub struct Page { devices: HashMap, popup_setting: bool, popup_device: Option, - show_device_without_alias: bool, subscription: Option>, } @@ -102,7 +100,6 @@ impl page::Page for Page { self.devices.clear(); self.popup_device = None; self.popup_setting = false; - self.show_device_without_alias = false; Task::none() } @@ -127,7 +124,7 @@ impl page::Page for Page { let control = widget::column::with_capacity(2) .push(description) .push(pin) - .spacing(cosmic::theme::active().cosmic().spacing.space_xxs); + .spacing(theme::active().cosmic().space_xxs()); let confirm_button = widget::button::suggested(fl!("confirm")).on_press(Message::PinConfirm); @@ -174,7 +171,6 @@ pub enum Message { SetActive(bool), SetAdapters(HashMap), SetDevices(HashMap), - ShowDeviceWithoutAlias(bool), UpdatedAdapter(OwnedObjectPath, Vec), UpdatedDevice(OwnedObjectPath, Vec), } @@ -402,9 +398,6 @@ impl Page { Message::PopupSetting(popup) => { self.popup_setting = popup; } - Message::ShowDeviceWithoutAlias(show_device_without_alias) => { - self.show_device_without_alias = show_device_without_alias; - } Message::SelectAdapter(adapter_maybe) => { tracing::debug!("Adapter selected: {adapter_maybe:?}"); self.selected_adapter = adapter_maybe; @@ -575,9 +568,7 @@ impl Page { fn status() -> Section { let mut descriptions = Slab::new(); - let bluetooth_heading = descriptions.insert(fl!("bluetooth")); - let bluetooth_opt_device_without_name = - descriptions.insert(fl!("bluetooth", "show-device-without-name")); + let bluetooth = descriptions.insert(fl!("bluetooth")); Section::default() .descriptions(descriptions) @@ -587,67 +578,30 @@ fn status() -> Section { let status = page .get_selected_adapter() .map_or(page.active, |(_, adapter)| adapter.enabled); + + let mut bluetooth_toggle = settings::item::builder(&descriptions[bluetooth]); + if matches!(status, Active::Enabling | Active::Enabled) { + bluetooth_toggle = bluetooth_toggle.description(&page.heading); + } + widget::list_column() - .add(settings::item::item_row(vec![ - if matches!(status, Active::Enabling | Active::Enabled) { - widget::column::with_capacity(2) - .push(text::body(&descriptions[bluetooth_heading])) - .push(text::caption(&page.heading)) - .into() - } else { - text::body(&descriptions[bluetooth_heading]).into() - }, - widget::horizontal_space().into(), - if page.popup_setting { - widget::popover( - widget::button::icon(widget::icon::from_name( - "preferences-system-symbolic", - )) - .on_press(Message::PopupSetting(false)), - ) - .position(widget::popover::Position::Bottom) - .on_close(Message::PopupSetting(false)) - .popup({ - let theme = cosmic::theme::active(); - let theme = theme.cosmic(); - widget::container( - settings::item::builder( - &descriptions[bluetooth_opt_device_without_name], - ) - .toggler( - page.show_device_without_alias, - Message::ShowDeviceWithoutAlias, - ), - ) - .width(Length::Fixed(300.0)) - .height(Length::Shrink) - .padding([theme.space_xs(), theme.space_xxxs()]) - .class(cosmic::theme::Container::Dialog) - }) - .into() - } else { - widget::button::icon(widget::icon::from_name("preferences-system-symbolic")) - .on_press(Message::PopupSetting(true)) - .into() - }, - widget::toggler(status == Active::Enabled) - .on_toggle(Message::SetActive) - .into(), - ])) - .apply(cosmic::Element::from) + .add(bluetooth_toggle.control( + widget::toggler(status == Active::Enabled).on_toggle(Message::SetActive), + )) + .apply(Element::from) .map(crate::pages::Message::Bluetooth) }) } fn popup_button(message: Option, text: &str) -> Element<'_, Message> { - let theme = cosmic::theme::active(); + let theme = theme::active(); let theme = theme.cosmic(); widget::text::body(text) .align_y(Alignment::Center) .apply(widget::button::custom) .padding([theme.space_xxxs(), theme.space_xs()]) .width(Length::Fill) - .class(cosmic::theme::Button::MenuItem) + .class(theme::Button::MenuItem) .on_press_maybe(message) .into() } @@ -681,9 +635,6 @@ fn connected_devices() -> Section { if !device.paired { return None; } - if !page.show_device_without_alias && !device.has_alias() { - return None; - } let device_menu: Element<_> = if page .popup_device @@ -697,8 +648,6 @@ fn connected_devices() -> Section { .position(widget::popover::Position::Bottom) .on_close(Message::PopupDevice(None)) .popup({ - let theme = cosmic::theme::active(); - let theme = theme.cosmic(); widget::container( widget::column() .push_maybe(device.is_connected().then(|| { @@ -713,8 +662,8 @@ fn connected_devices() -> Section { )), ) .width(Length::Fixed(200.0)) - .padding(theme.space_xxxs()) - .class(cosmic::theme::Container::Dialog) + .padding(theme::active().cosmic().space_xxxs()) + .class(theme::Container::Dialog) }) .into() } else { @@ -739,10 +688,10 @@ fn connected_devices() -> Section { match device.enabled { Active::Enabled => widget::text(&descriptions[device_connected]).into(), Active::Enabling => widget::text(&descriptions[device_connecting]) - .class(cosmic::theme::Text::Color(color!(128, 128, 128))) + .class(theme::Text::Color(color!(128, 128, 128))) .into(), Active::Disabling => widget::text(&descriptions[device_disconnecting]) - .class(cosmic::theme::Text::Color(color!(128, 128, 128))) + .class(theme::Text::Color(color!(128, 128, 128))) .into(), Active::Disabled => widget::button::text(&descriptions[device_connect]) .on_press(Message::ConnectDevice(path.clone())) @@ -753,7 +702,7 @@ fn connected_devices() -> Section { ])) }) .fold(section, settings::Section::add) - .apply(cosmic::Element::from) + .apply(Element::from) .map(crate::pages::Message::Bluetooth) }) } @@ -768,9 +717,8 @@ fn available_devices() -> Section { .descriptions(descriptions) .show_while::(|page| { page.selected_adapter.as_ref().map(|adapter| { - page.devices_for_adapter(adapter).any(|(_, device)| { - !device.paired && (page.show_device_without_alias || device.has_alias()) - }) + page.devices_for_adapter(adapter) + .any(|(_, device)| !device.paired) }) == Some(true) && page.active != Active::Disabled }) @@ -783,9 +731,6 @@ fn available_devices() -> Section { if device.paired { return None::>; } - if !page.show_device_without_alias && !device.has_alias() { - return None::>; - } let mut items = vec![ widget::icon::from_name(device.icon).size(16).into(), @@ -796,22 +741,18 @@ fn available_devices() -> Section { if device.enabled == Active::Enabling { items.push( text(&descriptions[device_connecting]) - .class(cosmic::theme::Text::Color(color!(128, 128, 128))) + .class(theme::Text::Color(color!(128, 128, 128))) .into(), ); } - let theme = cosmic::theme::active(); - let theme = theme.cosmic(); Some( - widget::mouse_area( - settings::item_row(items).padding([theme.space_xxs(), theme.space_m()]), - ) - .on_press(Message::ConnectDevice(path.clone())) - .into(), + widget::mouse_area(settings::item_row(items)) + .on_press(Message::ConnectDevice(path.clone())) + .into(), ) }) .fold(section, settings::Section::add) - .apply(cosmic::Element::from) + .apply(Element::from) .map(crate::pages::Message::Bluetooth) }) } @@ -828,8 +769,6 @@ fn multiple_adapter() -> Section { .view::(move |_binder, page, section| { let descriptions = §ion.descriptions; let section = settings::section().title(§ion.title); - let theme = cosmic::theme::active(); - let theme = theme.cosmic(); page.adapters .iter() @@ -838,7 +777,9 @@ fn multiple_adapter() -> Section { widget::icon::from_name("bluetooth-symbolic") .size(20) .into(), - widget::horizontal_space().width(theme.space_xxs()).into(), + widget::horizontal_space() + .width(theme::active().cosmic().space_xxs()) + .into(), text(&adapter.alias).wrapping(Wrapping::Word).into(), widget::horizontal_space().into(), widget::icon::from_name("go-next-symbolic").into(), @@ -855,7 +796,7 @@ fn multiple_adapter() -> Section { .on_press(Message::SelectAdapter(Some(path.clone()))) }) .fold(section, settings::Section::add) - .apply(cosmic::Element::from) + .apply(Element::from) .map(crate::pages::Message::Bluetooth) }) } diff --git a/i18n/en/cosmic_settings.ftl b/i18n/en/cosmic_settings.ftl index ed301ad..089daac 100644 --- a/i18n/en/cosmic_settings.ftl +++ b/i18n/en/cosmic_settings.ftl @@ -115,7 +115,6 @@ bluetooth = Bluetooth .disconnect = Disconnect .forget = Forget .dbus-error = An error has occurred while interacting with DBus: { $why } - .show-device-without-name = Show devices without name bluetooth-paired = Previously Connected Devices .connect = Connect