chore: clippy

This commit is contained in:
Vukašin Vojinović 2025-10-27 15:16:25 +01:00 committed by Ashley Wulber
parent a8d8e14413
commit b3be053f33
27 changed files with 654 additions and 706 deletions

View file

@ -121,10 +121,10 @@ impl page::Page<crate::pages::Message> for Page {
let mut local_list = mime_apps::List::default(); let mut local_list = mime_apps::List::default();
if let Some(path) = mime_apps::local_list_path() { if let Some(path) = mime_apps::local_list_path()
if let Ok(buffer) = std::fs::read_to_string(&path) { && let Ok(buffer) = std::fs::read_to_string(&path)
local_list.load_from(&buffer); {
} local_list.load_from(&buffer);
} }
let assocs = mime_apps::associations::by_app(); let assocs = mime_apps::associations::by_app();
@ -245,10 +245,11 @@ impl Page {
meta.selected = Some(id); meta.selected = Some(id);
let appid = &meta.app_ids[id]; let appid = &meta.app_ids[id];
if category == Category::Terminal && self.shortcuts_config.is_some() { if category == Category::Terminal
if let Some(config) = self.shortcuts_config.as_ref() { && self.shortcuts_config.is_some()
assign_default_terminal(config, appid); && let Some(config) = self.shortcuts_config.as_ref()
} {
assign_default_terminal(config, appid);
} }
for mime in mime_types { for mime in mime_types {
@ -450,13 +451,13 @@ fn assign_default_terminal(config: &cosmic_config::Config, appid: &str) {
if let Some(resolved_path) = resolved_path { if let Some(resolved_path) = resolved_path {
let desktop_entry = DesktopEntry::from_path(resolved_path, Some(&get_languages_from_env())); let desktop_entry = DesktopEntry::from_path(resolved_path, Some(&get_languages_from_env()));
if let Ok(desktop_entry) = desktop_entry { if let Ok(desktop_entry) = desktop_entry
if let Some(exec) = desktop_entry.exec() { && let Some(exec) = desktop_entry.exec()
actions.insert(System::Terminal, String::from(exec)); {
actions.insert(System::Terminal, String::from(exec));
if let Err(why) = config.set("system_actions", actions) { if let Err(why) = config.set("system_actions", actions) {
tracing::error!(?why, "Unable to set system_actions shortcuts config"); tracing::error!(?why, "Unable to set system_actions shortcuts config");
}
} }
} }
} }
@ -500,10 +501,10 @@ async fn load_defaults(assocs: &BTreeMap<Arc<str>, Arc<App>>, for_mimes: &[&str]
let mut icons = Vec::new(); let mut icons = Vec::new();
for (id, (appid, app)) in unsorted.iter().enumerate() { for (id, (appid, app)) in unsorted.iter().enumerate() {
if let Some(current_app) = current_app { if let Some(current_app) = current_app
if app.name.as_ref() == current_app.name.as_ref() { && app.name.as_ref() == current_app.name.as_ref()
selected = Some(id); {
} selected = Some(id);
} }
app_ids.push(appid.as_ref().into()); app_ids.push(appid.as_ref().into());
@ -562,21 +563,21 @@ async fn load_terminal_apps(assocs: &BTreeMap<Arc<str>, Arc<App>>) -> AppMeta {
// Scan desktop entries for terminal applications // Scan desktop entries for terminal applications
for path in DesktopEntryIter::new(default_paths()) { for path in DesktopEntryIter::new(default_paths()) {
if let Ok(bytes) = std::fs::read_to_string(&path) { if let Ok(bytes) = std::fs::read_to_string(&path)
if let Ok(entry) = DesktopEntry::from_str(&path, &bytes, None::<&[&str]>) { && let Ok(entry) = DesktopEntry::from_str(&path, &bytes, None::<&[&str]>)
// Check if it's a terminal application {
if entry // Check if it's a terminal application
.categories() if entry
.map(|cats| cats.iter().any(|c| *c == "TerminalEmulator")) .categories()
.unwrap_or(false) .map(|cats| cats.contains(&"TerminalEmulator"))
{ .unwrap_or(false)
let id = entry.id(); {
if let Some(app) = assocs.get(id) { let id = entry.id();
if current_appid.as_ref().map(|c| *c == id).unwrap_or(false) { if let Some(app) = assocs.get(id) {
current_app = Some(app.clone()); if current_appid.as_ref().map(|c| *c == id).unwrap_or(false) {
} current_app = Some(app.clone());
terminals.push((Arc::from(id), app.clone()));
} }
terminals.push((Arc::from(id), app.clone()));
} }
} }
} }
@ -591,10 +592,10 @@ async fn load_terminal_apps(assocs: &BTreeMap<Arc<str>, Arc<App>>) -> AppMeta {
let mut icons = Vec::new(); let mut icons = Vec::new();
for (id, (appid, app)) in terminals.iter().enumerate() { for (id, (appid, app)) in terminals.iter().enumerate() {
if let Some(ref current_app) = current_app { if let Some(ref current_app) = current_app
if app.name.as_ref() == current_app.name.as_ref() { && app.name.as_ref() == current_app.name.as_ref()
selected = Some(id); {
} selected = Some(id);
} }
app_ids.push(appid.to_string()); app_ids.push(appid.to_string());

View file

@ -138,10 +138,10 @@ impl page::Page<crate::pages::Message> for Page {
let (randr_task, randr_handle) = let (randr_task, randr_handle) =
Task::stream(async_fn_stream::fn_stream(|emitter| async move { Task::stream(async_fn_stream::fn_stream(|emitter| async move {
while let Ok(message) = rx.recv().await { while let Ok(message) = rx.recv().await {
if let cosmic_randr::Message::ManagerDone = message { if let cosmic_randr::Message::ManagerDone = message
if !refresh_pending.swap(true, Ordering::SeqCst) { && !refresh_pending.swap(true, Ordering::SeqCst)
_ = emitter.emit(on_enter().await).await; {
} _ = emitter.emit(on_enter().await).await;
} }
} }
})) }))

View file

@ -157,36 +157,35 @@ impl page::Page<crate::pages::Message> for Page {
} }
fn dialog(&self) -> Option<crate::pages::Element<'_>> { fn dialog(&self) -> Option<crate::pages::Element<'_>> {
if let Some(app_to_remove) = &self.app_to_remove { if let Some(app_to_remove) = &self.app_to_remove
if let Some(cached_startup_apps) = &self.cached_startup_apps { && let Some(cached_startup_apps) = &self.cached_startup_apps
if let Some(target_directory_type) = &self.target_directory_type { && let Some(target_directory_type) = &self.target_directory_type
return Some( {
widget::dialog() return Some(
.title(fl!( widget::dialog()
"startup-apps", .title(fl!(
"remove-dialog-title", "startup-apps",
name = app_to_remove.name(&cached_startup_apps.locales) "remove-dialog-title",
)) name = app_to_remove.name(&cached_startup_apps.locales)
.icon(icon::from_name("dialog-warning").size(64)) ))
.body(fl!("startup-apps", "remove-dialog-description")) .icon(icon::from_name("dialog-warning").size(64))
.primary_action( .body(fl!("startup-apps", "remove-dialog-description"))
button::suggested(fl!("remove")).on_press( .primary_action(
Message::RemoveStartupApplication( button::suggested(fl!("remove")).on_press(
target_directory_type.clone(), Message::RemoveStartupApplication(
app_to_remove.clone(), target_directory_type.clone(),
true, app_to_remove.clone(),
) true,
.into(),
),
) )
.secondary_action( .into(),
button::standard(fl!("cancel")) ),
.on_press(Message::CancelRemoveStartupApplication.into()), )
) .secondary_action(
.apply(Element::from), button::standard(fl!("cancel"))
); .on_press(Message::CancelRemoveStartupApplication.into()),
} )
} .apply(Element::from),
);
} }
None None
} }
@ -228,32 +227,31 @@ impl Page {
_ = std::fs::create_dir_all(directory_to_target.as_path()); _ = std::fs::create_dir_all(directory_to_target.as_path());
if let Ok(exists) = std::fs::exists(directory_to_target.join(file_name.clone())) { if let Ok(exists) = std::fs::exists(directory_to_target.join(file_name.clone()))
if !exists { && !exists
// when adding an application, we want to symlink to be more user-friendly {
// this ensures that, as an application gets updated / removed, so does the // when adding an application, we want to symlink to be more user-friendly
// symlink // this ensures that, as an application gets updated / removed, so does the
match std::os::unix::fs::symlink( // symlink
app.clone().path, match std::os::unix::fs::symlink(
directory_to_target.join(file_name), app.clone().path,
) { directory_to_target.join(file_name),
Ok(_) => { ) {
if let Some(ref mut cached_startup_apps) = self.cached_startup_apps Ok(_) => {
{ if let Some(ref mut cached_startup_apps) = self.cached_startup_apps {
let target_apps = cached_startup_apps.apps.get(&directory_type); let target_apps = cached_startup_apps.apps.get(&directory_type);
if let Some(target_apps) = target_apps { if let Some(target_apps) = target_apps {
let mut new_apps = target_apps.clone(); let mut new_apps = target_apps.clone();
new_apps.push(app.clone()); new_apps.push(app.clone());
cached_startup_apps cached_startup_apps
.apps .apps
.insert(directory_type.clone(), new_apps); .insert(directory_type.clone(), new_apps);
}
} }
} }
Err(e) => { }
error!(?e, "Failed to symlink"); Err(e) => {
} error!(?e, "Failed to symlink");
} }
} }
} }
@ -273,33 +271,30 @@ impl Page {
let directory_to_target = let directory_to_target =
directories.first().expect("Always at least one directory"); directories.first().expect("Always at least one directory");
if let Ok(exists) = std::fs::exists(directory_to_target.join(file_name.clone())) if let Ok(exists) = std::fs::exists(directory_to_target.join(file_name.clone()))
&& exists
{ {
if exists { // remove_file works for both regular files & symlinks
// remove_file works for both regular files & symlinks match std::fs::remove_file(directory_to_target.join(file_name)) {
match std::fs::remove_file(directory_to_target.join(file_name)) { Ok(_) => {
Ok(_) => { if let Some(ref mut cached_startup_apps) = self.cached_startup_apps
if let Some(ref mut cached_startup_apps) = {
self.cached_startup_apps let target_apps = cached_startup_apps.apps.get(&directory_type);
{ if let Some(target_apps) = target_apps {
let target_apps = let mut new_apps = Vec::new();
cached_startup_apps.apps.get(&directory_type); for old_app in target_apps {
if let Some(target_apps) = target_apps { if old_app != &app {
let mut new_apps = Vec::new(); new_apps.push(old_app.clone());
for old_app in target_apps {
if old_app != &app {
new_apps.push(old_app.clone());
}
} }
cached_startup_apps
.apps
.insert(directory_type.clone(), new_apps);
} }
cached_startup_apps
.apps
.insert(directory_type.clone(), new_apps);
} }
} }
Err(e) => { }
error!(?e, "Failed to remove file"); Err(e) => {
} error!(?e, "Failed to remove file");
} }
} }
} }
@ -330,39 +325,30 @@ impl Page {
if let Some(startup_apps) = &self.cached_startup_apps { if let Some(startup_apps) = &self.cached_startup_apps {
for app in &startup_apps.all_apps { for app in &startup_apps.all_apps {
if let Some(name) = app.name(&startup_apps.locales) { if let Some(name) = app.name(&startup_apps.locales)
if let Some(exec) = app.exec() { && let Some(exec) = app.exec()
if search_input.is_empty() && (search_input.is_empty()
|| exec.to_lowercase().contains(search_input) || exec.to_lowercase().contains(search_input)
|| name.to_lowercase().contains(search_input) || name.to_lowercase().contains(search_input))
{ {
let mut row = widget::row::with_capacity(3) let mut row = widget::row::with_capacity(3)
.spacing(space_xs) .spacing(space_xs)
.align_y(Alignment::Center); .align_y(Alignment::Center);
row = row.push( row = row.push(
icon::from_name(app.icon().unwrap_or("application-default")) icon::from_name(app.icon().unwrap_or("application-default")).size(32),
.size(32), );
);
if let Some(name) = app.name(&startup_apps.locales) { if let Some(name) = app.name(&startup_apps.locales) {
row = row.push(text(name).width(Length::Fill)); row = row.push(text(name).width(Length::Fill));
} else { } else {
row = row.push(text(&app.appid).width(Length::Fill)); row = row.push(text(&app.appid).width(Length::Fill));
}
row = row.push(
widget::button::text(fl!("add")).on_press(
Message::AddStartupApplication(
directory_type.clone(),
app.clone(),
)
.into(),
),
);
list = list.add(row)
}
} }
row = row.push(widget::button::text(fl!("add")).on_press(
Message::AddStartupApplication(directory_type.clone(), app.clone()).into(),
));
list = list.add(row)
} }
} }
} }
@ -467,16 +453,16 @@ fn get_all_apps(locales: Vec<String>) -> Vec<DesktopEntry> {
} }
// skip if we can't run this in COSMIC // skip if we can't run this in COSMIC
if let Some(only_show_in) = entry.only_show_in() { if let Some(only_show_in) = entry.only_show_in()
if !only_show_in.contains(&"COSMIC") { && !only_show_in.contains(&"COSMIC")
continue; {
} continue;
} }
if let Some(not_show_in) = entry.not_show_in() { if let Some(not_show_in) = entry.not_show_in()
if not_show_in.contains(&"COSMIC") { && not_show_in.contains(&"COSMIC")
continue; {
} continue;
} }
result.push(entry.clone()); result.push(entry.clone());

View file

@ -98,11 +98,12 @@ impl Model {
self.update_status(); self.update_status();
if let Some((path, existing)) = self.get_selected_adapter_mut() { if let Some((path, existing)) = self.get_selected_adapter_mut()
if existing.enabled == Active::Enabled && existing.scanning == Active::Disabled { && existing.enabled == Active::Enabled
existing.scanning = Active::Enabling; && existing.scanning == Active::Disabled
return Some(start_discovery(connection, path)); {
} existing.scanning = Active::Enabling;
return Some(start_discovery(connection, path));
} }
None None

View file

@ -136,10 +136,10 @@ impl Content {
Some(c) => self.font_config.search(input.to_string(), c), Some(c) => self.font_config.search(input.to_string(), c),
}, },
FontMessage::Select(font) => { FontMessage::Select(font) => {
if let Some(context_view) = context_view { if let Some(context_view) = context_view
if let Some(task) = self.font_config.select(font.to_string(), context_view) { && let Some(task) = self.font_config.select(font.to_string(), context_view)
return task; {
} return task;
} }
Task::none() Task::none()
} }

View file

@ -185,25 +185,25 @@ pub async fn fetch() -> Message {
if is_hidden.trim() == "true" { if is_hidden.trim() == "true" {
continue 'icon_dir; continue 'icon_dir;
} }
} else if name.is_none() { } else if name.is_none()
if let Some(value) = buffer.strip_prefix("Name=") { && let Some(value) = buffer.strip_prefix("Name=")
name = Some(value.trim().to_owned()); {
} name = Some(value.trim().to_owned());
} }
if valid_dirs.is_empty() { if valid_dirs.is_empty()
if let Some(value) = buffer.strip_prefix("Inherits=") { && let Some(value) = buffer.strip_prefix("Inherits=")
valid_dirs.extend(value.trim().split(',').map(|fallback| { {
if let Some(path) = theme_paths.get(fallback) { valid_dirs.extend(value.trim().split(',').map(|fallback| {
path.iter() if let Some(path) = theme_paths.get(fallback) {
.last() path.iter()
.and_then(|os| os.to_str().map(ToOwned::to_owned)) .next_back()
.unwrap_or_else(|| fallback.to_owned()) .and_then(|os| os.to_str().map(ToOwned::to_owned))
} else { .unwrap_or_else(|| fallback.to_owned())
fallback.to_owned() } else {
} fallback.to_owned()
})); }
} }));
} }
buffer.clear(); buffer.clear();
@ -213,7 +213,7 @@ pub async fn fetch() -> Message {
// Name of the directory theme was found in (e.g. Pop for Pop) // Name of the directory theme was found in (e.g. Pop for Pop)
valid_dirs.push( valid_dirs.push(
path.iter() path.iter()
.last() .next_back()
.and_then(|os| os.to_str().map(ToOwned::to_owned)) .and_then(|os| os.to_str().map(ToOwned::to_owned))
.unwrap_or_else(|| name.clone()), .unwrap_or_else(|| name.clone()),
); );
@ -288,7 +288,7 @@ fn preview_handles(theme: String, inherits: Vec<String>) -> [icon::Handle; ICON_
fn icon_handle(icon_name: &str, alternate: &str, valid_dirs: &[String]) -> icon::Handle { fn icon_handle(icon_name: &str, alternate: &str, valid_dirs: &[String]) -> icon::Handle {
ICON_TRY_SIZES ICON_TRY_SIZES
.iter() .iter()
.zip(std::iter::repeat(icon_name).take(ICON_TRY_SIZES.len())) .zip(std::iter::repeat_n(icon_name, ICON_TRY_SIZES.len()))
// Try fallback icon name after the default // Try fallback icon name after the default
.chain( .chain(
ICON_TRY_SIZES ICON_TRY_SIZES
@ -316,8 +316,10 @@ fn icon_handle(icon_name: &str, alternate: &str, valid_dirs: &[String]) -> icon:
theme_dir = parent; theme_dir = parent;
} }
if let Some(dir_name) = if let Some(dir_name) = theme_dir
theme_dir.iter().last().and_then(std::ffi::OsStr::to_str) .iter()
.next_back()
.and_then(std::ffi::OsStr::to_str)
{ {
valid_dirs valid_dirs
.iter() .iter()

View file

@ -247,12 +247,12 @@ impl Page {
} }
Message::DrawerColor(u) => { Message::DrawerColor(u) => {
if let Some(context_view) = self.context_view.as_ref() { if let Some(context_view) = self.context_view.as_ref()
if self.drawer.update_color(&mut tasks, u, context_view) { && self.drawer.update_color(&mut tasks, u, context_view)
theme_staged = self {
.theme_manager theme_staged = self
.set_color(self.drawer.current_color(context_view), context_view); .theme_manager
} .set_color(self.drawer.current_color(context_view), context_view);
} }
} }
@ -462,10 +462,10 @@ impl Page {
Message::ImportSuccess(builder) => { Message::ImportSuccess(builder) => {
tracing::trace!("Import successful"); tracing::trace!("Import successful");
let new_is_dark = builder.palette.is_dark(); let new_is_dark = builder.palette.is_dark();
if new_is_dark != self.theme_manager.mode().is_dark { if new_is_dark != self.theme_manager.mode().is_dark
if let Err(err) = self.theme_manager.dark_mode(new_is_dark) { && let Err(err) = self.theme_manager.dark_mode(new_is_dark)
tracing::error!(?err, "Error setting dark mode"); {
} tracing::error!(?err, "Error setting dark mode");
} }
self.theme_manager self.theme_manager
@ -552,33 +552,33 @@ impl Page {
(panel_config.name == "Dock").then_some(panel_config) (panel_config.name == "Dock").then_some(panel_config)
}); });
if let Some(panel_config_helper) = panel_config_helper.as_ref() { if let Some(panel_config_helper) = panel_config_helper.as_ref()
if let Some(panel_config) = panel_config.as_mut() { && let Some(panel_config) = panel_config.as_mut()
let radii = if panel_config.anchor_gap || !panel_config.expand_to_edges { {
let cornder_radii: CornerRadii = roundness.into(); let radii = if panel_config.anchor_gap || !panel_config.expand_to_edges {
cornder_radii.radius_xl[0] as u32 let cornder_radii: CornerRadii = roundness.into();
} else { cornder_radii.radius_xl[0] as u32
0 } else {
}; 0
};
if let Err(why) = panel_config.set_border_radius(panel_config_helper, radii) { if let Err(why) = panel_config.set_border_radius(panel_config_helper, radii) {
tracing::error!(?why, "Error updating panel corner radii"); tracing::error!(?why, "Error updating panel corner radii");
}
} }
}; };
if let Some(dock_config_helper) = dock_config_helper.as_ref() { if let Some(dock_config_helper) = dock_config_helper.as_ref()
if let Some(dock_config) = dock_config.as_mut() { && let Some(dock_config) = dock_config.as_mut()
let radii = if dock_config.anchor_gap || !dock_config.expand_to_edges { {
let cornder_radii: CornerRadii = roundness.into(); let radii = if dock_config.anchor_gap || !dock_config.expand_to_edges {
cornder_radii.radius_xl[0] as u32 let cornder_radii: CornerRadii = roundness.into();
} else { cornder_radii.radius_xl[0] as u32
0 } else {
}; 0
};
if let Err(why) = dock_config.set_border_radius(dock_config_helper, radii) { if let Err(why) = dock_config.set_border_radius(dock_config_helper, radii) {
tracing::error!(?why, "Error updating dock corner radii"); tracing::error!(?why, "Error updating dock corner radii");
}
} }
}; };
} }
@ -596,29 +596,29 @@ impl Page {
(panel_config.name == "Dock").then_some(panel_config) (panel_config.name == "Dock").then_some(panel_config)
}); });
if let Some(panel_config_helper) = panel_config_helper.as_ref() { if let Some(panel_config_helper) = panel_config_helper.as_ref()
if let Some(panel_config) = panel_config.as_mut() { && let Some(panel_config) = panel_config.as_mut()
let spacing = match density { {
Density::Compact => 0, let spacing = match density {
_ => 4, Density::Compact => 0,
}; _ => 4,
let update = panel_config.set_spacing(panel_config_helper, spacing); };
if let Err(err) = update { let update = panel_config.set_spacing(panel_config_helper, spacing);
tracing::error!(?err, "Error updating panel spacing"); if let Err(err) = update {
} tracing::error!(?err, "Error updating panel spacing");
} }
}; };
if let Some(dock_config_helper) = dock_config_helper.as_ref() { if let Some(dock_config_helper) = dock_config_helper.as_ref()
if let Some(dock_config) = dock_config.as_mut() { && let Some(dock_config) = dock_config.as_mut()
let spacing = match density { {
Density::Compact => 0, let spacing = match density {
_ => 4, Density::Compact => 0,
}; _ => 4,
let update = dock_config.set_spacing(dock_config_helper, spacing); };
if let Err(err) = update { let update = dock_config.set_spacing(dock_config_helper, spacing);
tracing::error!(?err, "Error updating dock spacing"); if let Err(err) = update {
} tracing::error!(?err, "Error updating dock spacing");
} }
}; };
} }

View file

@ -244,21 +244,20 @@ impl Page {
.filter(|a| a.matches(&self.search)) .filter(|a| a.matches(&self.search))
{ {
if let Some(config) = self.current_config.as_ref() { if let Some(config) = self.current_config.as_ref() {
if let Some(center) = config.plugins_center.as_ref() { if let Some(center) = config.plugins_center.as_ref()
if center.iter().any(|a| a.as_str() == info.id.as_ref()) { && center.iter().any(|a| a.as_str() == info.id.as_ref())
continue; {
} continue;
} }
if let Some(wings) = config.plugins_wings.as_ref() { if let Some(wings) = config.plugins_wings.as_ref()
if wings && wings
.0 .0
.iter() .iter()
.chain(wings.1.iter()) .chain(wings.1.iter())
.any(|a| a.as_str() == info.id.as_ref()) .any(|a| a.as_str() == info.id.as_ref())
{ {
continue; continue;
}
} }
} }
has_some = true; has_some = true;

View file

@ -468,10 +468,10 @@ impl PageInner {
} }
} }
Message::FullReset => { Message::FullReset => {
if let Some(container) = self.system_container.as_ref() { if let Some(container) = self.system_container.as_ref()
if let Err(err) = container.write_entries() { && let Err(err) = container.write_entries()
tracing::error!(?err, "Error fully resetting the panel config."); {
} tracing::error!(?err, "Error fully resetting the panel config.");
} }
} }
_ => {} _ => {}
@ -571,10 +571,10 @@ impl PageInner {
return Task::none(); return Task::none();
} }
Message::OutputRemoved(output) => { Message::OutputRemoved(output) => {
if let Some((name, _)) = self.outputs_map.remove(&output.id()) { if let Some((name, _)) = self.outputs_map.remove(&output.id())
if let Some(pos) = self.outputs.iter().position(|o| o == &name) { && let Some(pos) = self.outputs.iter().position(|o| o == &name)
self.outputs.remove(pos); {
} self.outputs.remove(pos);
} }
} }
Message::PanelConfig(c) => { Message::PanelConfig(c) => {

View file

@ -109,15 +109,15 @@ impl Config {
#[must_use] #[must_use]
pub fn default_folder() -> PathBuf { pub fn default_folder() -> PathBuf {
if let Some(data_dirs) = env::var_os("XDG_DATA_DIRS") { if let Some(data_dirs) = env::var_os("XDG_DATA_DIRS")
if let Some(data_dirs) = data_dirs.to_str() { && let Some(data_dirs) = data_dirs.to_str()
let data_dirs = data_dirs.split(":"); {
let data_dirs = data_dirs.split(":");
for data_dir in data_dirs { for data_dir in data_dirs {
let potential_path = PathBuf::from(data_dir).join(BACKGROUNDS_DIR); let potential_path = PathBuf::from(data_dir).join(BACKGROUNDS_DIR);
if let Ok(true) = &potential_path.try_exists() { if let Ok(true) = &potential_path.try_exists() {
return potential_path; return potential_path;
}
} }
} }
} }

View file

@ -587,10 +587,10 @@ impl Page {
} }
Category::RecentFolder(id) => { Category::RecentFolder(id) => {
if let Some(path) = self.config.recent_folders().get(id).cloned() { if let Some(path) = self.config.recent_folders().get(id).cloned()
if let Err(why) = self.config.set_current_folder(Some(path.clone())) { && let Err(why) = self.config.set_current_folder(Some(path.clone()))
tracing::error!(?path, ?why, "failed to set current folder"); {
} tracing::error!(?path, ?why, "failed to set current folder");
} }
} }
@ -815,10 +815,10 @@ impl Page {
} }
Message::ImageRemove(image) => { Message::ImageRemove(image) => {
if let Some(path) = self.selection.remove_custom_image(image) { if let Some(path) = self.selection.remove_custom_image(image)
if let Err(why) = self.config.remove_custom_image(&path) { && let Err(why) = self.config.remove_custom_image(&path)
tracing::error!(?why, "could not remove custom image from config"); {
} tracing::error!(?why, "could not remove custom image from config");
} }
} }
@ -858,18 +858,14 @@ impl Page {
self.selection.active = Choice::Slideshow; self.selection.active = Choice::Slideshow;
self.cache_display_image(); self.cache_display_image();
} else { } else {
if let Some(output) = self.config_output() { if let Some(output) = self.config_output()
if let Some(Source::Path(path)) = self.config.current_image(output) { && let Some(Source::Path(path)) = self.config.current_image(output)
if let Some(entity) = self.wallpaper_id_from_path(&path) { && let Some(entity) = self.wallpaper_id_from_path(&path)
if let Some(entry) = && let Some(entry) = self.config_wallpaper_entry(output.to_owned(), path)
self.config_wallpaper_entry(output.to_owned(), path) {
{ self.select_wallpaper(&entry, entity, false);
self.select_wallpaper(&entry, entity, false); self.config_apply();
self.config_apply(); return Task::none();
return Task::none();
}
}
}
} }
self.select_first_wallpaper(); self.select_first_wallpaper();

View file

@ -337,11 +337,9 @@ pub fn focus_navigation() -> Section<crate::pages::Message> {
fn super_key_active_config() -> Option<usize> { fn super_key_active_config() -> Option<usize> {
let super_binding = Binding::new(shortcuts::Modifiers::new().logo(), None); let super_binding = Binding::new(shortcuts::Modifiers::new().logo(), None);
let config = shortcuts::context().ok()?; let config = shortcuts::context().ok()?;
let shortcuts = shortcuts::shortcuts(&config);
let new_id = shortcuts shortcuts::shortcuts(&config)
.iter() .iter()
.find(|(binding, _action)| binding == &&super_binding) .find(|(binding, _action)| binding == &&super_binding)
.and_then(|(_, action)| match action { .and_then(|(_, action)| match action {
@ -349,9 +347,7 @@ fn super_key_active_config() -> Option<usize> {
Action::System(shortcuts::action::System::WorkspaceOverview) => Some(1), Action::System(shortcuts::action::System::WorkspaceOverview) => Some(1),
Action::System(shortcuts::action::System::AppLibrary) => Some(2), Action::System(shortcuts::action::System::AppLibrary) => Some(2),
_ => None, _ => None,
}); })
new_id
} }
fn super_key_set(action: Option<shortcuts::action::System>) { fn super_key_set(action: Option<shortcuts::action::System>) {

View file

@ -226,20 +226,20 @@ impl<Message: Clone> Widget<Message, cosmic::Theme, Renderer> for Arrangement<'_
| core::Event::Touch(touch::Event::FingerLifted { .. }) => { | core::Event::Touch(touch::Event::FingerLifted { .. }) => {
let state = tree.state.downcast_mut::<State>(); let state = tree.state.downcast_mut::<State>();
if let Some((output_key, region)) = state.dragging.take() { if let Some((output_key, region)) = state.dragging.take() {
if let Some(position) = cursor.position() { if let Some(position) = cursor.position()
if position.distance(state.drag_from) < 4.0 { && position.distance(state.drag_from) < 4.0
if let Some(ref on_select) = self.on_select { {
for id in self.tab_model.iter() { if let Some(ref on_select) = self.on_select {
if let Some(&key) = self.tab_model.data::<OutputKey>(id) { for id in self.tab_model.iter() {
if key == output_key { if let Some(&key) = self.tab_model.data::<OutputKey>(id)
shell.publish(on_select(id)); && key == output_key
} {
} shell.publish(on_select(id));
} }
} }
return event::Status::Captured;
} }
return event::Status::Captured;
} }
if let Some(ref on_placement) = self.on_placement { if let Some(ref on_placement) = self.on_placement {
@ -309,10 +309,10 @@ impl<Message: Clone> Widget<Message, cosmic::Theme, Renderer> for Arrangement<'_
display_regions(self.tab_model, self.list, &bounds, state.max_dimensions).enumerate() display_regions(self.tab_model, self.list, &bounds, state.max_dimensions).enumerate()
{ {
// If the output is being dragged, show its dragged position instead. // If the output is being dragged, show its dragged position instead.
if let Some((dragged_key, dragged_region)) = state.dragging { if let Some((dragged_key, dragged_region)) = state.dragging
if dragged_key == output_key { && dragged_key == output_key
region = dragged_region; {
} region = dragged_region;
} }
let (background, border_color) = if Some(&output_key) == active_key { let (background, border_color) = if Some(&output_key) == active_key {

View file

@ -33,7 +33,7 @@ static DPI_SCALE_LABELS: LazyLock<Vec<String>> =
#[derive(Clone, Copy, Debug)] #[derive(Clone, Copy, Debug)]
pub struct ColorDepth(usize); pub struct ColorDepth(usize);
/// Identifies the content to display in the context drawer // /// Identifies the content to display in the context drawer
// pub enum ContextDrawer { // pub enum ContextDrawer {
// NightLight, // NightLight,
// } // }
@ -287,10 +287,10 @@ impl page::Page<crate::pages::Message> for Page {
let (randr_task, randr_handle) = let (randr_task, randr_handle) =
Task::stream(async_fn_stream::fn_stream(|emitter| async move { Task::stream(async_fn_stream::fn_stream(|emitter| async move {
while let Ok(message) = rx.recv().await { while let Ok(message) = rx.recv().await {
if let cosmic_randr::Message::ManagerDone = message { if let cosmic_randr::Message::ManagerDone = message
if !refreshing_page.swap(true, Ordering::SeqCst) { && !refreshing_page.swap(true, Ordering::SeqCst)
_ = emitter.emit(on_enter().await).await; {
} _ = emitter.emit(on_enter().await).await;
} }
} }
})) }))
@ -931,14 +931,13 @@ impl Page {
return Task::none(); return Task::none();
}; };
if let Some(ref resolution) = self.config.resolution { if let Some(ref resolution) = self.config.resolution
if let Some(rates) = self.cache.modes.get(resolution) { && let Some(rates) = self.cache.modes.get(resolution)
if let Some(&rate) = rates.get(option) { && let Some(&rate) = rates.get(option)
self.cache.refresh_rate_selected = Some(option); {
self.config.refresh_rate = Some(rate); self.cache.refresh_rate_selected = Some(option);
return self.exec_randr(output, Randr::RefreshRate(rate)); self.config.refresh_rate = Some(rate);
} return self.exec_randr(output, Randr::RefreshRate(rate));
}
} }
Task::none() Task::none()
@ -1329,7 +1328,7 @@ pub fn display_configuration() -> Section<crate::pages::Message> {
.button_alignment(Alignment::Center) .button_alignment(Alignment::Center)
.on_activate(Message::Display); .on_activate(Message::Display);
let mut display_enable = (page let mut display_enable = if page
// Don't allow disabling display if it's the only active // Don't allow disabling display if it's the only active
.list .list
.outputs .outputs
@ -1337,22 +1336,23 @@ pub fn display_configuration() -> Section<crate::pages::Message> {
.filter(|display| display.enabled) .filter(|display| display.enabled)
.count() .count()
> 1 > 1
|| !active_output.enabled) || !active_output.enabled
.then(|| { {
list_column() list_column()
.add(widget::settings::item( .add(widget::settings::item(
&descriptions[enable_label], &descriptions[enable_label],
toggler(active_output.enabled).on_toggle(Message::DisplayToggle), toggler(active_output.enabled).on_toggle(Message::DisplayToggle),
)) ))
.add(widget::settings::item( .add(widget::settings::item(
&descriptions[mirroring_label], &descriptions[mirroring_label],
widget::dropdown::multi::dropdown( widget::dropdown::multi::dropdown(
&page.mirror_menu, &page.mirror_menu,
Message::Mirroring, Message::Mirroring,
), ),
)) ))
}) } else {
.unwrap_or_else(list_column); list_column()
};
if let Some(items) = display_options { if let Some(items) = display_options {
for item in items { for item in items {

View file

@ -455,22 +455,20 @@ impl Page {
SourceContext::MoveDown(id) => { SourceContext::MoveDown(id) => {
if let Some(pos) = if let Some(pos) =
self.active_layouts.iter().position(|&active| active == id) self.active_layouts.iter().position(|&active| active == id)
&& pos + 1 < self.active_layouts.len()
{ {
if pos + 1 < self.active_layouts.len() { self.active_layouts.swap(pos, pos + 1);
self.active_layouts.swap(pos, pos + 1); self.update_xkb_config();
self.update_xkb_config();
}
} }
} }
SourceContext::MoveUp(id) => { SourceContext::MoveUp(id) => {
if let Some(pos) = if let Some(pos) =
self.active_layouts.iter().position(|&active| active == id) self.active_layouts.iter().position(|&active| active == id)
&& pos > 0
{ {
if pos > 0 { self.active_layouts.swap(pos, pos - 1);
self.active_layouts.swap(pos, pos - 1); self.update_xkb_config();
self.update_xkb_config();
}
} }
} }

View file

@ -197,37 +197,35 @@ impl Model {
} }
pub(super) fn dialog(&self) -> Option<Element<'_, ShortcutMessage>> { pub(super) fn dialog(&self) -> Option<Element<'_, ShortcutMessage>> {
if let Some(&(id, _, _, ref action)) = self.replace_dialog.as_ref() { if let Some(&(id, _, _, ref action)) = self.replace_dialog.as_ref()
if let Some(short_id) = self.shortcut_context { && let Some(short_id) = self.shortcut_context
if let Some(model) = self.shortcut_models.get(short_id) { && let Some(model) = self.shortcut_models.get(short_id)
if let Some(shortcut) = model.bindings.get(id) { && let Some(shortcut) = model.bindings.get(id)
let primary_action = button::suggested(fl!("replace")) {
.on_press(ShortcutMessage::ApplyReplace); let primary_action =
button::suggested(fl!("replace")).on_press(ShortcutMessage::ApplyReplace);
let secondary_action = button::standard(fl!("cancel")) let secondary_action =
.on_press(ShortcutMessage::CancelReplace); button::standard(fl!("cancel")).on_press(ShortcutMessage::CancelReplace);
let dialog = widget::dialog() let dialog = widget::dialog()
.title(fl!("replace-shortcut-dialog")) .title(fl!("replace-shortcut-dialog"))
.icon(icon::from_name("dialog-warning").size(64)) .icon(icon::from_name("dialog-warning").size(64))
.body(fl!( .body(fl!(
"replace-shortcut-dialog", "replace-shortcut-dialog",
"desc", "desc",
shortcut = shortcut.input.clone(), shortcut = shortcut.input.clone(),
name = shortcut name = shortcut
.binding .binding
.description .description
.as_ref() .as_ref()
.unwrap_or(action) .unwrap_or(action)
.to_owned() .to_owned()
)) ))
.primary_action(primary_action) .primary_action(primary_action)
.secondary_action(secondary_action); .secondary_action(secondary_action);
return Some(dialog.into()); return Some(dialog.into());
}
}
}
} }
None None
@ -257,17 +255,15 @@ impl Model {
} }
pub(super) fn on_context_drawer_close(&mut self) { pub(super) fn on_context_drawer_close(&mut self) {
if let Some(short_id) = self.shortcut_context.take() { if let Some(short_id) = self.shortcut_context.take()
if let Some(model) = self.shortcut_models.get_mut(short_id) { && let Some(model) = self.shortcut_models.get_mut(short_id)
if let Some(remove_id) = model && let Some(remove_id) = model
.bindings .bindings
.iter() .iter()
.find(|(_, binding)| !binding.is_saved) .find(|(_, binding)| !binding.is_saved)
.map(|(id, _)| id) .map(|(id, _)| id)
{ {
model.bindings.remove(remove_id); model.bindings.remove(remove_id);
}
}
} }
self.editing = None; self.editing = None;
@ -314,107 +310,103 @@ impl Model {
pub(super) fn update(&mut self, message: ShortcutMessage) -> Task<crate::app::Message> { pub(super) fn update(&mut self, message: ShortcutMessage) -> Task<crate::app::Message> {
match message { match message {
ShortcutMessage::AddAnotherKeybinding => { ShortcutMessage::AddAnotherKeybinding => {
if let Some(short_id) = self.shortcut_context { if let Some(short_id) = self.shortcut_context
if let Some(model) = self.shortcut_models.get_mut(short_id) { && let Some(model) = self.shortcut_models.get_mut(short_id)
// If an empty entry exists, focus it instead of creating a new input. {
for (binding_id, shortcut) in &mut model.bindings { // If an empty entry exists, focus it instead of creating a new input.
if shortcut.binding.is_set() for (binding_id, shortcut) in &mut model.bindings {
|| Binding::from_str(&shortcut.input).is_ok() if shortcut.binding.is_set() || Binding::from_str(&shortcut.input).is_ok() {
{ continue;
continue; }
}
self.editing = Some(binding_id); self.editing = Some(binding_id);
shortcut.reset(); shortcut.reset();
return Task::batch(vec![ return Task::batch(vec![
iced_winit::platform_specific::commands::keyboard_shortcuts_inhibit::inhibit_shortcuts(true).discard(), iced_winit::platform_specific::commands::keyboard_shortcuts_inhibit::inhibit_shortcuts(true).discard(),
widget::text_input::focus(shortcut.id.clone()), widget::text_input::focus(shortcut.id.clone()),
widget::text_input::select_all(shortcut.id.clone()) widget::text_input::select_all(shortcut.id.clone())
]); ]);
} }
// Create a new input and focus it. // Create a new input and focus it.
let id = widget::Id::unique(); let id = widget::Id::unique();
self.editing = Some(model.bindings.insert(ShortcutBinding { self.editing = Some(model.bindings.insert(ShortcutBinding {
id: id.clone(), id: id.clone(),
binding: Binding::default(), binding: Binding::default(),
pending: Binding::default(), pending: Binding::default(),
input: String::new(), input: String::new(),
is_default: false, is_default: false,
is_saved: false, is_saved: false,
})); }));
return Task::batch(vec![ return Task::batch(vec![
iced_winit::platform_specific::commands::keyboard_shortcuts_inhibit::inhibit_shortcuts(true).discard(), iced_winit::platform_specific::commands::keyboard_shortcuts_inhibit::inhibit_shortcuts(true).discard(),
widget::text_input::focus(id.clone()), widget::text_input::focus(id.clone()),
widget::text_input::select_all(id) widget::text_input::select_all(id)
]); ]);
}
} }
} }
ShortcutMessage::ApplyReplace => { ShortcutMessage::ApplyReplace => {
if let Some((id, new_binding, ..)) = self.replace_dialog.take() { if let Some((id, new_binding, ..)) = self.replace_dialog.take()
if let Some(short_id) = self.shortcut_context { && let Some(short_id) = self.shortcut_context
// Remove conflicting bindings that are saved on disk. {
self.config_remove(&new_binding); // Remove conflicting bindings that are saved on disk.
self.config_remove(&new_binding);
// Clear any binding that matches this in the current model // Clear any binding that matches this in the current model
for (_, model) in &mut self.shortcut_models { for (_, model) in &mut self.shortcut_models {
if let Some(id) = model if let Some(id) = model
.bindings .bindings
.iter() .iter()
.find(|(_, shortcut)| shortcut.binding == new_binding) .find(|(_, shortcut)| shortcut.binding == new_binding)
.map(|(id, _)| id) .map(|(id, _)| id)
{ {
model.bindings.remove(id); model.bindings.remove(id);
break; break;
}
} }
// Update the current model and save the binding to disk.
if let Some(model) = self.shortcut_models.get_mut(short_id) {
if let Some(shortcut) = model.bindings.get_mut(id) {
let prev_binding = shortcut.binding.clone();
shortcut.binding = new_binding.clone();
shortcut.input.clear();
if self.editing == Some(id) {
self.editing = None;
}
let action = model.action.clone();
self.config_remove(&prev_binding);
self.config_add(action, new_binding);
}
}
_ = self.on_enter();
} }
// Update the current model and save the binding to disk.
if let Some(model) = self.shortcut_models.get_mut(short_id)
&& let Some(shortcut) = model.bindings.get_mut(id)
{
let prev_binding = shortcut.binding.clone();
shortcut.binding = new_binding.clone();
shortcut.input.clear();
if self.editing == Some(id) {
self.editing = None;
}
let action = model.action.clone();
self.config_remove(&prev_binding);
self.config_add(action, new_binding);
}
_ = self.on_enter();
} }
} }
ShortcutMessage::CancelReplace => { ShortcutMessage::CancelReplace => {
if let Some(((id, _, _, _), short_id)) = if let Some(((id, _, _, _), short_id)) =
self.replace_dialog.take().zip(self.shortcut_context) self.replace_dialog.take().zip(self.shortcut_context)
&& let Some(model) = self.shortcut_models.get_mut(short_id)
&& let Some(binding) = model.bindings.get_mut(id)
{ {
if let Some(model) = self.shortcut_models.get_mut(short_id) { binding.reset();
if let Some(binding) = model.bindings.get_mut(id) { return cosmic::widget::text_input::focus(binding.id.clone());
binding.reset();
return cosmic::widget::text_input::focus(binding.id.clone());
}
}
} }
} }
ShortcutMessage::DeleteBinding(id) => { ShortcutMessage::DeleteBinding(id) => {
if let Some(short_id) = self.shortcut_context { if let Some(short_id) = self.shortcut_context
if let Some(model) = self.shortcut_models.get_mut(short_id) { && let Some(model) = self.shortcut_models.get_mut(short_id)
let shortcut = model.bindings.remove(id); {
if shortcut.is_default { let shortcut = model.bindings.remove(id);
self.config_add(Action::Disable, shortcut.binding.clone()); if shortcut.is_default {
} else { self.config_add(Action::Disable, shortcut.binding.clone());
self.config_remove(&shortcut.binding); } else {
} self.config_remove(&shortcut.binding);
} }
} }
} }
@ -427,34 +419,32 @@ impl Model {
ShortcutMessage::EditBinding(id, enable) => { ShortcutMessage::EditBinding(id, enable) => {
if !enable && self.editing == Some(id) { if !enable && self.editing == Some(id) {
self.editing = None; self.editing = None;
if let Some(short_id) = self.shortcut_context { if let Some(short_id) = self.shortcut_context
if let Some(model) = self.shortcut_models.get_mut(short_id) { && let Some(model) = self.shortcut_models.get_mut(short_id)
if let Some(shortcut) = model.bindings.get_mut(id) { && let Some(shortcut) = model.bindings.get_mut(id)
shortcut.pending = shortcut.binding.clone(); {
shortcut.input = shortcut.binding.to_string(); shortcut.pending = shortcut.binding.clone();
} shortcut.input = shortcut.binding.to_string();
}
} }
return Task::batch(vec![ return Task::batch(vec![
cosmic::widget::text_input::focus(self.add_keybindings_button_id.clone()), cosmic::widget::text_input::focus(self.add_keybindings_button_id.clone()),
iced_winit::platform_specific::commands::keyboard_shortcuts_inhibit::inhibit_shortcuts(false).discard() iced_winit::platform_specific::commands::keyboard_shortcuts_inhibit::inhibit_shortcuts(false).discard()
]); ]);
} }
if let Some(short_id) = self.shortcut_context { if let Some(short_id) = self.shortcut_context
if let Some(model) = self.shortcut_models.get_mut(short_id) { && let Some(model) = self.shortcut_models.get_mut(short_id)
if let Some(shortcut) = model.bindings.get_mut(id) { && let Some(shortcut) = model.bindings.get_mut(id)
if enable { {
self.editing = Some(id); if enable {
shortcut.input = shortcut.binding.to_string(); self.editing = Some(id);
return Task::batch(vec![ shortcut.input = shortcut.binding.to_string();
return Task::batch(vec![
iced_winit::platform_specific::commands::keyboard_shortcuts_inhibit::inhibit_shortcuts(true).discard(), iced_winit::platform_specific::commands::keyboard_shortcuts_inhibit::inhibit_shortcuts(true).discard(),
widget::text_input::select_all(shortcut.id.clone()) widget::text_input::select_all(shortcut.id.clone())
]); ]);
} else if self.editing == Some(id) { } else if self.editing == Some(id) {
self.editing = None; self.editing = None;
return iced_winit::platform_specific::commands::keyboard_shortcuts_inhibit::inhibit_shortcuts(false).discard(); return iced_winit::platform_specific::commands::keyboard_shortcuts_inhibit::inhibit_shortcuts(false).discard();
}
}
} }
} }
} }
@ -491,12 +481,12 @@ impl Model {
crate::app::Message::OpenContextDrawer(self.entity), crate::app::Message::OpenContextDrawer(self.entity),
)]; )];
if let Some(model) = self.shortcut_models.get(0) { if let Some(model) = self.shortcut_models.get(0)
if let Some(shortcut) = model.bindings.get(0) { && let Some(shortcut) = model.bindings.get(0)
self.editing = Some(0); {
tasks.push(widget::text_input::focus(shortcut.id.clone())); self.editing = Some(0);
tasks.push(widget::text_input::select_all(shortcut.id.clone())); tasks.push(widget::text_input::focus(shortcut.id.clone()));
} tasks.push(widget::text_input::select_all(shortcut.id.clone()));
} }
return Task::batch(tasks); return Task::batch(tasks);
@ -509,112 +499,106 @@ impl Model {
panic!("{}", v); panic!("{}", v);
} }
ShortcutMessage::ModifiersChanged(modifiers) => { ShortcutMessage::ModifiersChanged(modifiers) => {
if let Some((short_id, id)) = self.shortcut_context.zip(self.editing) { if let Some((short_id, id)) = self.shortcut_context.zip(self.editing)
if let Some(model) = self.shortcut_models.get_mut(short_id) { && let Some(model) = self.shortcut_models.get_mut(short_id)
if let Some(shortcut) = model.bindings.get_mut(id) { && let Some(shortcut) = model.bindings.get_mut(id)
let mut cfg_modifiers = {
cosmic_settings_config::shortcuts::Modifiers::new(); let mut cfg_modifiers = cosmic_settings_config::shortcuts::Modifiers::new();
if modifiers.alt() { if modifiers.alt() {
cfg_modifiers = cfg_modifiers.alt() cfg_modifiers = cfg_modifiers.alt()
} }
if modifiers.control() { if modifiers.control() {
cfg_modifiers = cfg_modifiers.ctrl() cfg_modifiers = cfg_modifiers.ctrl()
} }
if modifiers.shift() { if modifiers.shift() {
cfg_modifiers = cfg_modifiers.shift() cfg_modifiers = cfg_modifiers.shift()
} }
if modifiers.logo() { if modifiers.logo() {
cfg_modifiers = cfg_modifiers.logo() cfg_modifiers = cfg_modifiers.logo()
} }
let old = let old = std::mem::replace(&mut shortcut.pending.modifiers, cfg_modifiers);
std::mem::replace(&mut shortcut.pending.modifiers, cfg_modifiers);
if shortcut.pending.keycode.is_none() && modifiers.is_empty() { if shortcut.pending.keycode.is_none() && modifiers.is_empty() {
if old.logo { if old.logo {
shortcut.pending.modifiers = old; shortcut.pending.modifiers = old;
shortcut.input = shortcut.pending.to_string(); shortcut.input = shortcut.pending.to_string();
// XX for now avoid applying the keycode // XX for now avoid applying the keycode
shortcut.binding.keycode = None; shortcut.binding.keycode = None;
return Task::batch(vec![ return Task::batch(vec![
iced_winit::platform_specific::commands::keyboard_shortcuts_inhibit::inhibit_shortcuts(false).discard(), iced_winit::platform_specific::commands::keyboard_shortcuts_inhibit::inhibit_shortcuts(false).discard(),
self.submit_binding(id), self.submit_binding(id),
cosmic::widget::text_input::focus(self.add_keybindings_button_id.clone()), cosmic::widget::text_input::focus(self.add_keybindings_button_id.clone()),
]); ]);
} else if old.alt || old.ctrl || old.shift { } else if old.alt || old.ctrl || old.shift {
self.editing = None; self.editing = None;
shortcut.reset(); shortcut.reset();
return Task::batch(vec![ return Task::batch(vec![
cosmic::widget::text_input::focus(self.add_keybindings_button_id.clone()), cosmic::widget::text_input::focus(self.add_keybindings_button_id.clone()),
iced_winit::platform_specific::commands::keyboard_shortcuts_inhibit::inhibit_shortcuts(false).discard() iced_winit::platform_specific::commands::keyboard_shortcuts_inhibit::inhibit_shortcuts(false).discard()
]); ]);
}
}
shortcut.input = shortcut.pending.to_string();
} }
} }
shortcut.input = shortcut.pending.to_string();
} }
} }
ShortcutMessage::KeyReleased(keycode, _, _) => { ShortcutMessage::KeyReleased(keycode, _, _) => {
if let Some((short_id, id)) = self.shortcut_context.zip(self.editing) { if let Some((short_id, id)) = self.shortcut_context.zip(self.editing)
if let Some(model) = self.shortcut_models.get_mut(short_id) { && let Some(model) = self.shortcut_models.get_mut(short_id)
if let Some(shortcut) = model.bindings.get_mut(id) { && let Some(shortcut) = model.bindings.get_mut(id)
// if the currently selected shortcut matches, finish selecting shortcut {
if shortcut.pending.key.is_some() // if the currently selected shortcut matches, finish selecting shortcut
&& shortcut.pending.keycode.is_some_and(|k| k == keycode) if shortcut.pending.key.is_some()
{ && shortcut.pending.keycode.is_some_and(|k| k == keycode)
if shortcut.pending.modifiers {
!= cosmic_settings_config::shortcuts::Modifiers::new() if shortcut.pending.modifiers
|| shortcut.pending.key.is_some_and(|key| { != cosmic_settings_config::shortcuts::Modifiers::new()
key.is_misc_function_key() || shortcut.pending.key.is_some_and(|key| {
|| matches!(key.raw(), 0x10080001..=0x1008FFFF) key.is_misc_function_key()
}) || matches!(key.raw(), 0x10080001..=0x1008FFFF)
{ })
shortcut.input = shortcut.pending.to_string(); {
// XX for now avoid applying the keycode shortcut.input = shortcut.pending.to_string();
shortcut.binding.keycode = None; // XX for now avoid applying the keycode
return Task::batch(vec![ shortcut.binding.keycode = None;
return Task::batch(vec![
iced_winit::platform_specific::commands::keyboard_shortcuts_inhibit::inhibit_shortcuts(false).discard(), iced_winit::platform_specific::commands::keyboard_shortcuts_inhibit::inhibit_shortcuts(false).discard(),
self.submit_binding(id), self.submit_binding(id),
cosmic::widget::text_input::focus(self.add_keybindings_button_id.clone()), cosmic::widget::text_input::focus(self.add_keybindings_button_id.clone()),
]); ]);
} }
return Task::batch(vec![ return Task::batch(vec![
cosmic::widget::text_input::focus(self.add_keybindings_button_id.clone()), cosmic::widget::text_input::focus(self.add_keybindings_button_id.clone()),
iced_winit::platform_specific::commands::keyboard_shortcuts_inhibit::inhibit_shortcuts(false).discard() iced_winit::platform_specific::commands::keyboard_shortcuts_inhibit::inhibit_shortcuts(false).discard()
]); ]);
}
}
} }
} }
} }
ShortcutMessage::KeyPressed(keycode, unmodified_keysym, location, modifiers) => { ShortcutMessage::KeyPressed(keycode, unmodified_keysym, location, modifiers) => {
if unmodified_keysym == Key::Named(Named::Escape) && modifiers.is_empty() { if unmodified_keysym == Key::Named(Named::Escape) && modifiers.is_empty() {
if let Some((short_id, id)) = self.shortcut_context.zip(self.editing) { if let Some((short_id, id)) = self.shortcut_context.zip(self.editing)
if let Some(model) = self.shortcut_models.get_mut(short_id) { && let Some(model) = self.shortcut_models.get_mut(short_id)
if let Some(binding) = model.bindings.get_mut(id) { && let Some(binding) = model.bindings.get_mut(id)
binding.reset(); {
self.editing = None; binding.reset();
return Task::batch(vec![ self.editing = None;
return Task::batch(vec![
cosmic::widget::text_input::focus(self.add_keybindings_button_id.clone()), cosmic::widget::text_input::focus(self.add_keybindings_button_id.clone()),
iced_winit::platform_specific::commands::keyboard_shortcuts_inhibit::inhibit_shortcuts(false).discard() iced_winit::platform_specific::commands::keyboard_shortcuts_inhibit::inhibit_shortcuts(false).discard()
]); ]);
}
}
} }
return Task::none(); return Task::none();
} }
if let Some((short_id, id)) = self.shortcut_context.zip(self.editing) { if let Some((short_id, id)) = self.shortcut_context.zip(self.editing)
if let Some(model) = self.shortcut_models.get_mut(short_id) { && let Some(model) = self.shortcut_models.get_mut(short_id)
if let Some(shortcut) = model.bindings.get_mut(id) { && let Some(shortcut) = model.bindings.get_mut(id)
shortcut.pending.keycode = Some(keycode); {
shortcut.pending.key = shortcut.pending.keycode = Some(keycode);
iced_winit::platform_specific::wayland::keymap::key_to_keysym( shortcut.pending.key =
unmodified_keysym, iced_winit::platform_specific::wayland::keymap::key_to_keysym(
location, unmodified_keysym,
); location,
} );
}
} }
} }
} }
@ -689,68 +673,65 @@ impl Model {
let mut apply_binding = None; let mut apply_binding = None;
// Check for conflicts with the new binding. // Check for conflicts with the new binding.
if let Some(model) = self.shortcut_models.get_mut(short_id) { if let Some(model) = self.shortcut_models.get_mut(short_id)
if let Some(shortcut) = model.bindings.get_mut(id) { && let Some(shortcut) = model.bindings.get_mut(id)
if shortcut.input.is_empty() { {
return Task::none(); if shortcut.input.is_empty() {
return Task::none();
}
match Binding::from_str(&shortcut.input) {
Ok(new_binding) => {
if shortcut.binding == new_binding {
return Task::none();
}
if !new_binding.is_set() {
shortcut.reset();
return Task::none();
}
if let Some(action) = self.config_contains(&new_binding) {
let action_str = if let Action::Spawn(_) = &action {
super::localize_custom_action(&action, &new_binding)
} else {
super::localize_action(&action)
};
self.replace_dialog = Some((id, new_binding, action, action_str));
return Task::none();
}
apply_binding = Some(new_binding);
} }
match Binding::from_str(&shortcut.input) { Err(why) => {
Ok(new_binding) => { tracing::error!(why, "keybinding input invalid");
if shortcut.binding == new_binding { shortcut.reset();
return Task::none();
}
if !new_binding.is_set() {
shortcut.reset();
return Task::none();
}
if let Some(action) = self.config_contains(&new_binding) {
let action_str = if let Action::Spawn(_) = &action {
super::localize_custom_action(&action, &new_binding)
} else {
super::localize_action(&action)
};
self.replace_dialog = Some((id, new_binding, action, action_str));
return Task::none();
}
apply_binding = Some(new_binding);
}
Err(why) => {
tracing::error!(why, "keybinding input invalid");
shortcut.reset();
}
} }
} }
} }
// Apply if no conflict was found. // Apply if no conflict was found.
if let Some(new_binding) = apply_binding { if let Some(new_binding) = apply_binding
if let Some(model) = self.shortcut_models.get_mut(short_id) { && let Some(model) = self.shortcut_models.get_mut(short_id)
if let Some(shortcut) = model.bindings.get_mut(id) { && let Some(shortcut) = model.bindings.get_mut(id)
let prev_binding = mem::replace(&mut shortcut.binding, new_binding.clone()); {
shortcut.is_saved = true; let prev_binding = mem::replace(&mut shortcut.binding, new_binding.clone());
shortcut.reset(); shortcut.is_saved = true;
shortcut.reset();
if self.editing == Some(id) { if self.editing == Some(id) {
self.editing = None; self.editing = None;
}
let action = model.action.clone();
if shortcut.is_default {
self.config_add(Action::Disable, prev_binding);
} else {
self.config_remove(&prev_binding);
}
self.config_add(action, new_binding);
return cosmic::widget::text_input::focus(
self.add_keybindings_button_id.clone(),
);
}
} }
let action = model.action.clone();
if shortcut.is_default {
self.config_add(Action::Disable, prev_binding);
} else {
self.config_remove(&prev_binding);
}
self.config_add(action, new_binding);
return cosmic::widget::text_input::focus(self.add_keybindings_button_id.clone());
} }
} }

View file

@ -431,18 +431,17 @@ impl Page {
hw_address, hw_address,
.. ..
} = dialog } = dialog
&& let Some(nm) = self.nm_state.as_mut()
{ {
if let Some(nm) = self.nm_state.as_mut() { self.connecting.insert(ssid.clone());
self.connecting.insert(ssid.clone()); _ = nm
_ = nm .sender
.sender .unbounded_send(network_manager::Request::Authenticate {
.unbounded_send(network_manager::Request::Authenticate { ssid: ssid.to_string(),
ssid: ssid.to_string(), identity,
identity, hw_address,
hw_address, password,
password, });
});
}
} }
} }
@ -848,19 +847,16 @@ fn connection_settings(conn: zbus::Connection) -> Task<crate::app::Message> {
}) })
// Reduce the settings list into a SSID->UUID map. // Reduce the settings list into a SSID->UUID map.
.fold(BTreeMap::new(), |mut set, settings| async move { .fold(BTreeMap::new(), |mut set, settings| async move {
if let Some(ref wifi) = settings.wifi { if let Some(ref wifi) = settings.wifi
if let Some(ssid) = wifi && let Some(ssid) = wifi
.ssid .ssid
.clone() .clone()
.and_then(|ssid| String::from_utf8(ssid).ok()) .and_then(|ssid| String::from_utf8(ssid).ok())
{ && let Some(ref connection) = settings.connection
if let Some(ref connection) = settings.connection { && let Some(uuid) = connection.uuid.clone()
if let Some(uuid) = connection.uuid.clone() { {
set.insert(ssid.into(), uuid.into()); set.insert(ssid.into(), uuid.into());
return set; return set;
}
}
}
} }
set set

View file

@ -319,15 +319,15 @@ impl Battery {
&& (percent - 100.0_f64).abs() < f64::EPSILON; && (percent - 100.0_f64).abs() < f64::EPSILON;
if !is_charging { if !is_charging {
if let Ok(time) = proxy.time_to_empty().await { if let Ok(time) = proxy.time_to_empty().await
if let Ok(dur) = Duration::from_std(std::time::Duration::from_secs(time as u64)) { && let Ok(dur) = Duration::from_std(std::time::Duration::from_secs(time as u64))
remaining_duration = dur; {
}
}
} else if let Ok(time) = proxy.time_to_full().await {
if let Ok(dur) = Duration::from_std(std::time::Duration::from_secs(time as u64)) {
remaining_duration = dur; remaining_duration = dur;
} }
} else if let Ok(time) = proxy.time_to_full().await
&& let Ok(dur) = Duration::from_std(std::time::Duration::from_secs(time as u64))
{
remaining_duration = dur;
} }
let battery_percent = if percent > 95.0 { let battery_percent = if percent > 95.0 {

View file

@ -43,7 +43,7 @@ static SUSPEND_TIMES: &[Duration] = &[
fn format_time(duration: Duration) -> String { fn format_time(duration: Duration) -> String {
let m = duration.as_secs() / 60; let m = duration.as_secs() / 60;
if m % 60 == 0 { if m.is_multiple_of(60) {
fl!("x-hours", number = (m / 60)) fl!("x-hours", number = (m / 60))
} else { } else {
fl!("x-minutes", number = m) fl!("x-minutes", number = m)

View file

@ -27,10 +27,11 @@ pub fn passwd(range: (u64, u64)) -> Vec<PasswdUser> {
_ => (), _ => (),
} }
if let Ok(user) = line.trim().parse::<PasswdUser>() { if let Ok(user) = line.trim().parse::<PasswdUser>()
if user.uid >= range.0 && user.uid <= range.1 { && user.uid >= range.0
users.push(user); && user.uid <= range.1
} {
users.push(user);
} }
} }
} }

View file

@ -965,12 +965,12 @@ fn get_encrypt_method() -> String {
let reader = BufReader::new(login_defs); let reader = BufReader::new(login_defs);
for line in reader.lines().map_while(Result::ok) { for line in reader.lines().map_while(Result::ok) {
if !line.trim().is_empty() { if !line.trim().is_empty()
if let Some(index) = line.find(|c: char| c.is_whitespace()) { && let Some(index) = line.find(|c: char| c.is_whitespace())
let key = line[0..index].trim(); {
if key == "ENCRYPT_METHOD" { let key = line[0..index].trim();
value = line[(index + 1)..].trim().to_string(); if key == "ENCRYPT_METHOD" {
} value = line[(index + 1)..].trim().to_string();
} }
} }
} }

View file

@ -204,24 +204,22 @@ impl Page {
pub fn update(&mut self, message: Message) -> cosmic::Task<crate::app::Message> { pub fn update(&mut self, message: Message) -> cosmic::Task<crate::app::Message> {
match message { match message {
Message::AddLanguage(id) => { Message::AddLanguage(id) => {
if let Some(language) = self.available_languages.get(id) { if let Some(language) = self.available_languages.get(id)
if let Some((config, locales)) = self.config.as_mut() { && let Some((config, locales)) = self.config.as_mut()
if !locales.contains(&language.lang_code) { && !locales.contains(&language.lang_code)
locales.push(language.lang_code.clone()); {
_ = config.set("system_locales", &locales); locales.push(language.lang_code.clone());
} _ = config.set("system_locales", &locales);
}
} }
} }
Message::RemoveLanguage(id) => { Message::RemoveLanguage(id) => {
if let Some(language) = self.available_languages.remove(id) { if let Some(language) = self.available_languages.remove(id)
if let Some((config, locales)) = self.config.as_mut() { && let Some((config, locales)) = self.config.as_mut()
if let Some(pos) = locales.iter().position(|l| l == &language.lang_code) { && let Some(pos) = locales.iter().position(|l| l == &language.lang_code)
locales.remove(pos); {
_ = config.set("system_locales", &locales); locales.remove(pos);
} _ = config.set("system_locales", &locales);
}
} }
} }
@ -235,10 +233,10 @@ impl Page {
let region = region.lang_code.clone(); let region = region.lang_code.clone();
return cosmic::task::future(async move { return cosmic::task::future(async move {
if let Ok(exit_status) = set_locale(lang, region.clone()).await { if let Ok(exit_status) = set_locale(lang, region.clone()).await
if exit_status.success() { && exit_status.success()
update_time_settings_after_region_change(region); {
} update_time_settings_after_region_change(region);
} }
Message::Refresh(Arc::new(page_reload().await)) Message::Refresh(Arc::new(page_reload().await))
@ -315,24 +313,23 @@ impl Page {
_ = config.set("system_locales", &locales); _ = config.set("system_locales", &locales);
if let Some(language_code) = locales.first() { if let Some(language_code) = locales.first()
if let Some(language) = self && let Some(language) = self
.available_languages .available_languages
.values() .values()
.find(|lang| &lang.lang_code == language_code) .find(|lang| &lang.lang_code == language_code)
{ {
let language = language.clone(); let language = language.clone();
self.language = Some(language.clone()); self.language = Some(language.clone());
let region = self.region.clone(); let region = self.region.clone();
tokio::spawn(async move { tokio::spawn(async move {
_ = set_locale( _ = set_locale(
language.lang_code.clone(), language.lang_code.clone(),
region.unwrap_or(language).lang_code.clone(), region.unwrap_or(language).lang_code.clone(),
) )
.await; .await;
}); });
}
} }
} }
} }

View file

@ -25,21 +25,16 @@ pub enum AccessibilityEvent {
Closed, Closed,
} }
#[derive(Debug, Clone, Copy, PartialEq, Eq, FromPrimitive, ToPrimitive)] #[derive(Debug, Default, Clone, Copy, PartialEq, Eq, FromPrimitive, ToPrimitive)]
pub enum ColorFilter { pub enum ColorFilter {
Greyscale, Greyscale,
Deuteranopia, Deuteranopia,
Protanopia, Protanopia,
Tritanopia, Tritanopia,
#[default]
Unknown, Unknown,
} }
impl Default for ColorFilter {
fn default() -> Self {
ColorFilter::Unknown
}
}
#[derive(Debug, Clone, Copy)] #[derive(Debug, Clone, Copy)]
pub enum AccessibilityRequest { pub enum AccessibilityRequest {
Magnifier(bool), Magnifier(bool),

View file

@ -22,13 +22,9 @@ pub async fn handle_wireless_device(
let mut scan_changed = device.receive_last_scan_changed().await; let mut scan_changed = device.receive_last_scan_changed().await;
if let Some(t) = scan_changed.next().await { if let Some(t) = scan_changed.next().await {
match t.get().await { if let Ok(-1) = t.get().await {
Ok(-1) => { tracing::error!("wireless device scan errored");
tracing::error!("wireless device scan errored"); return Ok(Default::default());
return Ok(Default::default());
}
_ => (),
} }
} }

View file

@ -36,8 +36,8 @@ pub struct KnownDeviceConnection {
pub uuid: Arc<str>, pub uuid: Arc<str>,
} }
pub async fn list<'a>( pub async fn list(
conn: &'a zbus::Connection, conn: &zbus::Connection,
device_type_filter: fn(DeviceType) -> bool, device_type_filter: fn(DeviceType) -> bool,
) -> zbus::Result<Vec<DeviceInfo>> { ) -> zbus::Result<Vec<DeviceInfo>> {
let nm = NetworkManager::new(conn).await?; let nm = NetworkManager::new(conn).await?;

View file

@ -16,19 +16,23 @@ impl HwAddress {
} }
u64::from_str_radix(columnless_vec.join("").as_str(), 16) u64::from_str_radix(columnless_vec.join("").as_str(), 16)
.ok() .ok()
.and_then(|address| Some(HwAddress { address })) .map(|address| HwAddress { address })
} }
pub fn from_string(arg: &String) -> Option<Self> { pub fn from_string(arg: &String) -> Option<Self> {
HwAddress::from_str(arg.as_str()) HwAddress::from_str(arg.as_str())
} }
pub fn to_string(&self) -> String { }
format!("{:#x}", self.address)
impl std::fmt::Display for HwAddress {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let hex = format!("{:#x}", self.address)
.trim_start_matches("0x") .trim_start_matches("0x")
.chars() .chars()
.collect::<Vec<_>>() .collect::<Vec<_>>()
.chunks(2) .chunks(2)
.map(|chunk| chunk.iter().cloned().collect::<String>()) .map(|chunk| chunk.iter().cloned().collect::<String>())
.collect::<Vec<String>>() .collect::<Vec<String>>()
.join(":") .join(":");
write!(f, "{}", hex)
} }
} }

View file

@ -620,7 +620,7 @@ impl NetworkManagerState {
std::str::from_utf8(&output.stdout) std::str::from_utf8(&output.stdout)
.ok() .ok()
.map_or(false, |stdout| stdout.contains("Soft blocked: yes")) .is_some_and(|stdout| stdout.contains("Soft blocked: yes"))
}), }),
network_manager network_manager
.wireless_enabled() .wireless_enabled()
@ -714,7 +714,7 @@ impl NetworkManagerState {
.iter() .iter()
.filter(|a| { .filter(|a| {
known_ssid.contains(&a.ssid) known_ssid.contains(&a.ssid)
&& !active_conns.iter().any(|ac| &ac.name() == a.ssid.as_ref()) && !active_conns.iter().any(|ac| ac.name() == a.ssid.as_ref())
}) })
.cloned() .cloned()
.collect(); .collect();
@ -733,7 +733,7 @@ impl NetworkManagerState {
self.wireless_access_points = Vec::new(); self.wireless_access_points = Vec::new();
} }
async fn connect_wifi<'a>( async fn connect_wifi(
&self, &self,
conn: &zbus::Connection, conn: &zbus::Connection,
ssid: &str, ssid: &str,
@ -844,8 +844,8 @@ impl NetworkManagerState {
let (_, active_conn) = nm let (_, active_conn) = nm
.add_and_activate_connection(conn_settings, device.inner().path(), &ap.path) .add_and_activate_connection(conn_settings, device.inner().path(), &ap.path)
.await?; .await?;
let dummy = ActiveConnectionProxy::new(&conn, active_conn).await?; let dummy = ActiveConnectionProxy::new(conn, active_conn).await?;
let active = ActiveConnectionProxy::builder(&conn) let active = ActiveConnectionProxy::builder(conn)
.destination(dummy.inner().destination().to_owned()) .destination(dummy.inner().destination().to_owned())
.unwrap() .unwrap()
.interface(dummy.inner().interface().to_owned()) .interface(dummy.inner().interface().to_owned())
@ -867,14 +867,13 @@ impl NetworkManagerState {
} else if let Ok(enums::ActiveConnectionState::Deactivated) = state { } else if let Ok(enums::ActiveConnectionState::Deactivated) = state {
return Err(Error::ConnectionActivate); return Err(Error::ConnectionActivate);
} }
match tokio::time::timeout(Duration::from_secs(20), changes.next()).await { if let Ok(Some(s)) =
Ok(Some(s)) => { tokio::time::timeout(Duration::from_secs(20), changes.next()).await
let state = s.get().await.unwrap_or_default().into(); {
if matches!(state, enums::ActiveConnectionState::Activated) { let state = s.get().await.unwrap_or_default().into();
return Ok(()); if matches!(state, enums::ActiveConnectionState::Activated) {
} return Ok(());
} }
_ => {}
}; };
count -= 1; count -= 1;