fix(bluetooth): remove cog next to toggle

This makes the page behave as if the settings cog toggle is always enabled.
This commit is contained in:
Vukašin Vojinović 2024-12-04 03:25:56 +01:00 committed by Ashley Wulber
parent 3ee44da4b6
commit d01e0d85fb
3 changed files with 34 additions and 94 deletions

6
Cargo.lock generated
View file

@ -3993,9 +3993,9 @@ dependencies = [
[[package]] [[package]]
name = "io-lifetimes" name = "io-lifetimes"
version = "2.0.3" version = "2.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5a611371471e98973dbcab4e0ec66c31a10bc356eeb4d54a0e05eac8158fe38c" checksum = "06432fb54d3be7964ecd3649233cddf80db2832f47fec34c01f65b3d9d774983"
[[package]] [[package]]
name = "is_terminal_polyfill" name = "is_terminal_polyfill"
@ -7775,7 +7775,7 @@ checksum = "c89532cc712a2adb119eb4d09694b402576052254d0bb284f82ac1c47fb786ad"
dependencies = [ dependencies = [
"bitflags 2.6.0", "bitflags 2.6.0",
"downcast-rs", "downcast-rs",
"io-lifetimes 2.0.3", "io-lifetimes 2.0.4",
"rustix 0.38.41", "rustix 0.38.41",
"wayland-backend", "wayland-backend",
"wayland-scanner", "wayland-scanner",

View file

@ -4,8 +4,7 @@
use cosmic::iced::{color, Alignment, Length}; use cosmic::iced::{color, Alignment, Length};
use cosmic::iced_core::text::Wrapping; use cosmic::iced_core::text::Wrapping;
use cosmic::widget::{self, settings, text}; use cosmic::widget::{self, settings, text};
use cosmic::Task; use cosmic::{theme, Apply, Element, Task};
use cosmic::{Apply, Element};
use cosmic_settings_page::{self as page, section, Section}; use cosmic_settings_page::{self as page, section, Section};
use futures::channel::oneshot; use futures::channel::oneshot;
use slab::Slab; use slab::Slab;
@ -50,7 +49,6 @@ pub struct Page {
devices: HashMap<OwnedObjectPath, Device>, devices: HashMap<OwnedObjectPath, Device>,
popup_setting: bool, popup_setting: bool,
popup_device: Option<OwnedObjectPath>, popup_device: Option<OwnedObjectPath>,
show_device_without_alias: bool,
subscription: Option<tokio::sync::oneshot::Sender<()>>, subscription: Option<tokio::sync::oneshot::Sender<()>>,
} }
@ -102,7 +100,6 @@ impl page::Page<crate::pages::Message> for Page {
self.devices.clear(); self.devices.clear();
self.popup_device = None; self.popup_device = None;
self.popup_setting = false; self.popup_setting = false;
self.show_device_without_alias = false;
Task::none() Task::none()
} }
@ -127,7 +124,7 @@ impl page::Page<crate::pages::Message> for Page {
let control = widget::column::with_capacity(2) let control = widget::column::with_capacity(2)
.push(description) .push(description)
.push(pin) .push(pin)
.spacing(cosmic::theme::active().cosmic().spacing.space_xxs); .spacing(theme::active().cosmic().space_xxs());
let confirm_button = let confirm_button =
widget::button::suggested(fl!("confirm")).on_press(Message::PinConfirm); widget::button::suggested(fl!("confirm")).on_press(Message::PinConfirm);
@ -174,7 +171,6 @@ pub enum Message {
SetActive(bool), SetActive(bool),
SetAdapters(HashMap<OwnedObjectPath, Adapter>), SetAdapters(HashMap<OwnedObjectPath, Adapter>),
SetDevices(HashMap<OwnedObjectPath, Device>), SetDevices(HashMap<OwnedObjectPath, Device>),
ShowDeviceWithoutAlias(bool),
UpdatedAdapter(OwnedObjectPath, Vec<AdapterUpdate>), UpdatedAdapter(OwnedObjectPath, Vec<AdapterUpdate>),
UpdatedDevice(OwnedObjectPath, Vec<DeviceUpdate>), UpdatedDevice(OwnedObjectPath, Vec<DeviceUpdate>),
} }
@ -402,9 +398,6 @@ impl Page {
Message::PopupSetting(popup) => { Message::PopupSetting(popup) => {
self.popup_setting = popup; self.popup_setting = popup;
} }
Message::ShowDeviceWithoutAlias(show_device_without_alias) => {
self.show_device_without_alias = show_device_without_alias;
}
Message::SelectAdapter(adapter_maybe) => { Message::SelectAdapter(adapter_maybe) => {
tracing::debug!("Adapter selected: {adapter_maybe:?}"); tracing::debug!("Adapter selected: {adapter_maybe:?}");
self.selected_adapter = adapter_maybe; self.selected_adapter = adapter_maybe;
@ -575,9 +568,7 @@ impl Page {
fn status() -> Section<crate::pages::Message> { fn status() -> Section<crate::pages::Message> {
let mut descriptions = Slab::new(); let mut descriptions = Slab::new();
let bluetooth_heading = descriptions.insert(fl!("bluetooth")); let bluetooth = descriptions.insert(fl!("bluetooth"));
let bluetooth_opt_device_without_name =
descriptions.insert(fl!("bluetooth", "show-device-without-name"));
Section::default() Section::default()
.descriptions(descriptions) .descriptions(descriptions)
@ -587,67 +578,30 @@ fn status() -> Section<crate::pages::Message> {
let status = page let status = page
.get_selected_adapter() .get_selected_adapter()
.map_or(page.active, |(_, adapter)| adapter.enabled); .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() widget::list_column()
.add(settings::item::item_row(vec![ .add(bluetooth_toggle.control(
if matches!(status, Active::Enabling | Active::Enabled) { widget::toggler(status == Active::Enabled).on_toggle(Message::SetActive),
widget::column::with_capacity(2) ))
.push(text::body(&descriptions[bluetooth_heading])) .apply(Element::from)
.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)
.map(crate::pages::Message::Bluetooth) .map(crate::pages::Message::Bluetooth)
}) })
} }
fn popup_button(message: Option<Message>, text: &str) -> Element<'_, Message> { fn popup_button(message: Option<Message>, text: &str) -> Element<'_, Message> {
let theme = cosmic::theme::active(); let theme = theme::active();
let theme = theme.cosmic(); let theme = theme.cosmic();
widget::text::body(text) widget::text::body(text)
.align_y(Alignment::Center) .align_y(Alignment::Center)
.apply(widget::button::custom) .apply(widget::button::custom)
.padding([theme.space_xxxs(), theme.space_xs()]) .padding([theme.space_xxxs(), theme.space_xs()])
.width(Length::Fill) .width(Length::Fill)
.class(cosmic::theme::Button::MenuItem) .class(theme::Button::MenuItem)
.on_press_maybe(message) .on_press_maybe(message)
.into() .into()
} }
@ -681,9 +635,6 @@ fn connected_devices() -> Section<crate::pages::Message> {
if !device.paired { if !device.paired {
return None; return None;
} }
if !page.show_device_without_alias && !device.has_alias() {
return None;
}
let device_menu: Element<_> = if page let device_menu: Element<_> = if page
.popup_device .popup_device
@ -697,8 +648,6 @@ fn connected_devices() -> Section<crate::pages::Message> {
.position(widget::popover::Position::Bottom) .position(widget::popover::Position::Bottom)
.on_close(Message::PopupDevice(None)) .on_close(Message::PopupDevice(None))
.popup({ .popup({
let theme = cosmic::theme::active();
let theme = theme.cosmic();
widget::container( widget::container(
widget::column() widget::column()
.push_maybe(device.is_connected().then(|| { .push_maybe(device.is_connected().then(|| {
@ -713,8 +662,8 @@ fn connected_devices() -> Section<crate::pages::Message> {
)), )),
) )
.width(Length::Fixed(200.0)) .width(Length::Fixed(200.0))
.padding(theme.space_xxxs()) .padding(theme::active().cosmic().space_xxxs())
.class(cosmic::theme::Container::Dialog) .class(theme::Container::Dialog)
}) })
.into() .into()
} else { } else {
@ -739,10 +688,10 @@ fn connected_devices() -> Section<crate::pages::Message> {
match device.enabled { match device.enabled {
Active::Enabled => widget::text(&descriptions[device_connected]).into(), Active::Enabled => widget::text(&descriptions[device_connected]).into(),
Active::Enabling => widget::text(&descriptions[device_connecting]) 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(), .into(),
Active::Disabling => widget::text(&descriptions[device_disconnecting]) 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(), .into(),
Active::Disabled => widget::button::text(&descriptions[device_connect]) Active::Disabled => widget::button::text(&descriptions[device_connect])
.on_press(Message::ConnectDevice(path.clone())) .on_press(Message::ConnectDevice(path.clone()))
@ -753,7 +702,7 @@ fn connected_devices() -> Section<crate::pages::Message> {
])) ]))
}) })
.fold(section, settings::Section::add) .fold(section, settings::Section::add)
.apply(cosmic::Element::from) .apply(Element::from)
.map(crate::pages::Message::Bluetooth) .map(crate::pages::Message::Bluetooth)
}) })
} }
@ -768,9 +717,8 @@ fn available_devices() -> Section<crate::pages::Message> {
.descriptions(descriptions) .descriptions(descriptions)
.show_while::<Page>(|page| { .show_while::<Page>(|page| {
page.selected_adapter.as_ref().map(|adapter| { page.selected_adapter.as_ref().map(|adapter| {
page.devices_for_adapter(adapter).any(|(_, device)| { page.devices_for_adapter(adapter)
!device.paired && (page.show_device_without_alias || device.has_alias()) .any(|(_, device)| !device.paired)
})
}) == Some(true) }) == Some(true)
&& page.active != Active::Disabled && page.active != Active::Disabled
}) })
@ -783,9 +731,6 @@ fn available_devices() -> Section<crate::pages::Message> {
if device.paired { if device.paired {
return None::<Element<'_, Message>>; return None::<Element<'_, Message>>;
} }
if !page.show_device_without_alias && !device.has_alias() {
return None::<Element<'_, Message>>;
}
let mut items = vec![ let mut items = vec![
widget::icon::from_name(device.icon).size(16).into(), widget::icon::from_name(device.icon).size(16).into(),
@ -796,22 +741,18 @@ fn available_devices() -> Section<crate::pages::Message> {
if device.enabled == Active::Enabling { if device.enabled == Active::Enabling {
items.push( items.push(
text(&descriptions[device_connecting]) text(&descriptions[device_connecting])
.class(cosmic::theme::Text::Color(color!(128, 128, 128))) .class(theme::Text::Color(color!(128, 128, 128)))
.into(), .into(),
); );
} }
let theme = cosmic::theme::active();
let theme = theme.cosmic();
Some( Some(
widget::mouse_area( widget::mouse_area(settings::item_row(items))
settings::item_row(items).padding([theme.space_xxs(), theme.space_m()]), .on_press(Message::ConnectDevice(path.clone()))
) .into(),
.on_press(Message::ConnectDevice(path.clone()))
.into(),
) )
}) })
.fold(section, settings::Section::add) .fold(section, settings::Section::add)
.apply(cosmic::Element::from) .apply(Element::from)
.map(crate::pages::Message::Bluetooth) .map(crate::pages::Message::Bluetooth)
}) })
} }
@ -828,8 +769,6 @@ fn multiple_adapter() -> Section<crate::pages::Message> {
.view::<Page>(move |_binder, page, section| { .view::<Page>(move |_binder, page, section| {
let descriptions = &section.descriptions; let descriptions = &section.descriptions;
let section = settings::section().title(&section.title); let section = settings::section().title(&section.title);
let theme = cosmic::theme::active();
let theme = theme.cosmic();
page.adapters page.adapters
.iter() .iter()
@ -838,7 +777,9 @@ fn multiple_adapter() -> Section<crate::pages::Message> {
widget::icon::from_name("bluetooth-symbolic") widget::icon::from_name("bluetooth-symbolic")
.size(20) .size(20)
.into(), .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(), text(&adapter.alias).wrapping(Wrapping::Word).into(),
widget::horizontal_space().into(), widget::horizontal_space().into(),
widget::icon::from_name("go-next-symbolic").into(), widget::icon::from_name("go-next-symbolic").into(),
@ -855,7 +796,7 @@ fn multiple_adapter() -> Section<crate::pages::Message> {
.on_press(Message::SelectAdapter(Some(path.clone()))) .on_press(Message::SelectAdapter(Some(path.clone())))
}) })
.fold(section, settings::Section::add) .fold(section, settings::Section::add)
.apply(cosmic::Element::from) .apply(Element::from)
.map(crate::pages::Message::Bluetooth) .map(crate::pages::Message::Bluetooth)
}) })
} }

View file

@ -115,7 +115,6 @@ bluetooth = Bluetooth
.disconnect = Disconnect .disconnect = Disconnect
.forget = Forget .forget = Forget
.dbus-error = An error has occurred while interacting with DBus: { $why } .dbus-error = An error has occurred while interacting with DBus: { $why }
.show-device-without-name = Show devices without name
bluetooth-paired = Previously Connected Devices bluetooth-paired = Previously Connected Devices
.connect = Connect .connect = Connect