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:
parent
3ee44da4b6
commit
d01e0d85fb
3 changed files with 34 additions and 94 deletions
6
Cargo.lock
generated
6
Cargo.lock
generated
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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<OwnedObjectPath, Device>,
|
||||
popup_setting: bool,
|
||||
popup_device: Option<OwnedObjectPath>,
|
||||
show_device_without_alias: bool,
|
||||
subscription: Option<tokio::sync::oneshot::Sender<()>>,
|
||||
}
|
||||
|
||||
|
|
@ -102,7 +100,6 @@ impl page::Page<crate::pages::Message> 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<crate::pages::Message> 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<OwnedObjectPath, Adapter>),
|
||||
SetDevices(HashMap<OwnedObjectPath, Device>),
|
||||
ShowDeviceWithoutAlias(bool),
|
||||
UpdatedAdapter(OwnedObjectPath, Vec<AdapterUpdate>),
|
||||
UpdatedDevice(OwnedObjectPath, Vec<DeviceUpdate>),
|
||||
}
|
||||
|
|
@ -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<crate::pages::Message> {
|
||||
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<crate::pages::Message> {
|
|||
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<Message>, 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<crate::pages::Message> {
|
|||
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<crate::pages::Message> {
|
|||
.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<crate::pages::Message> {
|
|||
)),
|
||||
)
|
||||
.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<crate::pages::Message> {
|
|||
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<crate::pages::Message> {
|
|||
]))
|
||||
})
|
||||
.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<crate::pages::Message> {
|
|||
.descriptions(descriptions)
|
||||
.show_while::<Page>(|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<crate::pages::Message> {
|
|||
if device.paired {
|
||||
return None::<Element<'_, Message>>;
|
||||
}
|
||||
if !page.show_device_without_alias && !device.has_alias() {
|
||||
return None::<Element<'_, Message>>;
|
||||
}
|
||||
|
||||
let mut items = vec![
|
||||
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 {
|
||||
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<crate::pages::Message> {
|
|||
.view::<Page>(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<crate::pages::Message> {
|
|||
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<crate::pages::Message> {
|
|||
.on_press(Message::SelectAdapter(Some(path.clone())))
|
||||
})
|
||||
.fold(section, settings::Section::add)
|
||||
.apply(cosmic::Element::from)
|
||||
.apply(Element::from)
|
||||
.map(crate::pages::Message::Bluetooth)
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue