chore: apply recommendations from clippy
This commit is contained in:
parent
cec55dafd7
commit
8e0f1c4a09
56 changed files with 720 additions and 824 deletions
|
|
@ -42,7 +42,7 @@ impl AppListConfig {
|
|||
}
|
||||
|
||||
pub fn remove_pinned(&mut self, id: &str, config: &Config) {
|
||||
if let Some(pos) = self.favorites.iter().position(|e| e == &id) {
|
||||
if let Some(pos) = self.favorites.iter().position(|e| e == id) {
|
||||
self.favorites.remove(pos);
|
||||
let _ = self.write_entry(config);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -269,22 +269,22 @@ impl DockItem {
|
|||
.first()
|
||||
.map(|t| Message::Toggle(t.0.foreign_toplevel.clone()))
|
||||
} else {
|
||||
Some(Message::TopLevelListPopup((*id).into(), window_id))
|
||||
Some(Message::TopLevelListPopup(*id, window_id))
|
||||
})
|
||||
.width(Length::Shrink)
|
||||
.height(Length::Shrink),
|
||||
)
|
||||
.on_right_release(Message::Popup((*id).into(), window_id))
|
||||
.on_right_release(Message::Popup(*id, window_id))
|
||||
.on_middle_release({
|
||||
launch_on_preferred_gpu(desktop_info, gpus)
|
||||
.unwrap_or_else(|| Message::Popup((*id).into(), window_id))
|
||||
.unwrap_or(Message::Popup(*id, window_id))
|
||||
})
|
||||
.into()
|
||||
} else {
|
||||
icon_button.into()
|
||||
};
|
||||
|
||||
let path = desktop_info.path.to_path_buf();
|
||||
let path = desktop_info.path.clone();
|
||||
let icon_button = if dnd_source_enabled && interaction_enabled {
|
||||
dnd_source(icon_button)
|
||||
.window(window_id)
|
||||
|
|
@ -420,7 +420,7 @@ fn index_in_list(
|
|||
|
||||
if let Some(existing_preview) = existing_preview {
|
||||
if index >= existing_preview {
|
||||
index.checked_sub(1).unwrap_or_default()
|
||||
index.saturating_sub(1)
|
||||
} else {
|
||||
index
|
||||
}
|
||||
|
|
@ -589,9 +589,10 @@ fn find_desktop_entries<'a>(
|
|||
) -> impl Iterator<Item = fde::DesktopEntry> + 'a {
|
||||
app_ids.iter().map(|fav| {
|
||||
let unicase_fav = fde::unicase::Ascii::new(fav.as_str());
|
||||
fde::find_app_by_id(desktop_entries, unicase_fav)
|
||||
.map(ToOwned::to_owned)
|
||||
.unwrap_or_else(|| fde::DesktopEntry::from_appid(fav.clone()).to_owned())
|
||||
fde::find_app_by_id(desktop_entries, unicase_fav).map_or_else(
|
||||
|| fde::DesktopEntry::from_appid(fav.clone()).clone(),
|
||||
ToOwned::to_owned,
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -610,7 +611,7 @@ impl CosmicAppList {
|
|||
.enumerate()
|
||||
.map(|(pinned_ctr, (e, original_id))| DockItem {
|
||||
id: pinned_ctr as u32,
|
||||
toplevels: Default::default(),
|
||||
toplevels: Vec::new(),
|
||||
desktop_info: e.clone(),
|
||||
original_app_id: original_id.clone(),
|
||||
})
|
||||
|
|
@ -681,12 +682,9 @@ impl cosmic::Application for CosmicAppList {
|
|||
.chain(self.pinned_list.iter())
|
||||
.find(|t| t.id == id)
|
||||
{
|
||||
let rectangle = match self.rectangles.get(&toplevel_group.id.into()) {
|
||||
Some(r) => r,
|
||||
None => {
|
||||
tracing::error!("No rectangle found for toplevel group");
|
||||
return Task::none();
|
||||
}
|
||||
let Some(rectangle) = self.rectangles.get(&toplevel_group.id.into()) else {
|
||||
tracing::error!("No rectangle found for toplevel group");
|
||||
return Task::none();
|
||||
};
|
||||
|
||||
let new_id = window::Id::unique();
|
||||
|
|
@ -751,9 +749,8 @@ impl cosmic::Application for CosmicAppList {
|
|||
}
|
||||
}
|
||||
|
||||
let rectangle = match self.rectangles.get(&toplevel_group.id.into()) {
|
||||
Some(r) => r,
|
||||
None => return Task::none(),
|
||||
let Some(rectangle) = self.rectangles.get(&toplevel_group.id.into()) else {
|
||||
return Task::none();
|
||||
};
|
||||
|
||||
let new_id = window::Id::unique();
|
||||
|
|
@ -1040,7 +1037,7 @@ impl cosmic::Application for CosmicAppList {
|
|||
self.active_list.remove(pos)
|
||||
};
|
||||
dock_item.toplevels = t.toplevels;
|
||||
};
|
||||
}
|
||||
dock_item.id = self.item_ctr;
|
||||
|
||||
if dock_item.desktop_info.exec().is_some() {
|
||||
|
|
@ -1095,7 +1092,7 @@ impl cosmic::Application for CosmicAppList {
|
|||
pending::<()>().await;
|
||||
}
|
||||
},
|
||||
|_| Message::IncrementSubscriptionCtr,
|
||||
|()| Message::IncrementSubscriptionCtr,
|
||||
)
|
||||
.map(cosmic::action::app);
|
||||
}
|
||||
|
|
@ -1242,7 +1239,7 @@ impl cosmic::Application for CosmicAppList {
|
|||
app_id.as_deref(),
|
||||
terminal,
|
||||
)
|
||||
.await
|
||||
.await;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -1307,13 +1304,13 @@ impl cosmic::Application for CosmicAppList {
|
|||
{
|
||||
let mut d = self.active_list.remove(p);
|
||||
// but use the id from the config
|
||||
d.original_app_id = original_id.clone();
|
||||
d.original_app_id.clone_from(original_id);
|
||||
d
|
||||
} else {
|
||||
self.item_ctr += 1;
|
||||
DockItem {
|
||||
id: self.item_ctr,
|
||||
toplevels: Default::default(),
|
||||
toplevels: Vec::new(),
|
||||
desktop_info: de.clone(),
|
||||
original_app_id: original_id.clone(),
|
||||
}
|
||||
|
|
@ -1369,9 +1366,10 @@ impl cosmic::Application for CosmicAppList {
|
|||
+ 2 * self.core.applet.suggested_padding(false);
|
||||
let (_favorite_popup_cutoff, active_popup_cutoff) =
|
||||
self.panel_overflow_lengths();
|
||||
let popup_applet_count = self.active_list.len().saturating_sub(
|
||||
(active_popup_cutoff.unwrap_or_default()).saturating_sub(1) as usize,
|
||||
) as f32;
|
||||
let popup_applet_count =
|
||||
self.active_list.len().saturating_sub(
|
||||
(active_popup_cutoff.unwrap_or_default()).saturating_sub(1),
|
||||
) as f32;
|
||||
let popup_applet_size = applet_suggested_size as f32 * popup_applet_count
|
||||
+ 4.0 * (popup_applet_count - 1.);
|
||||
let (max_width, max_height) = match self.core.applet.anchor {
|
||||
|
|
@ -1425,9 +1423,10 @@ impl cosmic::Application for CosmicAppList {
|
|||
+ 2 * self.core.applet.suggested_padding(false);
|
||||
let (favorite_popup_cutoff, _active_popup_cutoff) =
|
||||
self.panel_overflow_lengths();
|
||||
let popup_applet_count = self.pinned_list.len().saturating_sub(
|
||||
favorite_popup_cutoff.unwrap_or_default().saturating_sub(1) as usize,
|
||||
) as f32;
|
||||
let popup_applet_count =
|
||||
self.pinned_list.len().saturating_sub(
|
||||
favorite_popup_cutoff.unwrap_or_default().saturating_sub(1),
|
||||
) as f32;
|
||||
let popup_applet_size = applet_suggested_size as f32 * popup_applet_count
|
||||
+ 4.0 * (popup_applet_count - 1.);
|
||||
let (max_width, max_height) = match self.core.applet.anchor {
|
||||
|
|
@ -1462,7 +1461,7 @@ impl cosmic::Application for CosmicAppList {
|
|||
Task::none()
|
||||
}
|
||||
|
||||
fn view(&self) -> Element<Message> {
|
||||
fn view(&self) -> Element<'_, Message> {
|
||||
let focused_item = self.currently_active_toplevel();
|
||||
let theme = self.core.system_theme();
|
||||
let dot_radius = theme.cosmic().radius_xs();
|
||||
|
|
@ -1589,45 +1588,44 @@ impl cosmic::Application for CosmicAppList {
|
|||
);
|
||||
}
|
||||
|
||||
let mut active: Vec<_> = self.active_list[..active_popup_cutoff
|
||||
.map(|n| {
|
||||
let mut active: Vec<_> =
|
||||
self.active_list[..active_popup_cutoff.map_or(self.active_list.len(), |n| {
|
||||
if n < self.active_list.len() {
|
||||
n.saturating_sub(1)
|
||||
} else {
|
||||
n
|
||||
}
|
||||
})
|
||||
.unwrap_or(self.active_list.len())]
|
||||
.iter()
|
||||
.map(|dock_item| {
|
||||
self.core
|
||||
.applet
|
||||
.applet_tooltip(
|
||||
dock_item.as_icon(
|
||||
&self.core.applet,
|
||||
self.rectangle_tracker.as_ref(),
|
||||
self.popup.is_none(),
|
||||
self.config.enable_drag_source,
|
||||
self.gpus.as_deref(),
|
||||
})]
|
||||
.iter()
|
||||
.map(|dock_item| {
|
||||
self.core
|
||||
.applet
|
||||
.applet_tooltip(
|
||||
dock_item.as_icon(
|
||||
&self.core.applet,
|
||||
self.rectangle_tracker.as_ref(),
|
||||
self.popup.is_none(),
|
||||
self.config.enable_drag_source,
|
||||
self.gpus.as_deref(),
|
||||
dock_item
|
||||
.toplevels
|
||||
.iter()
|
||||
.any(|y| focused_item.contains(&y.0.foreign_toplevel)),
|
||||
dot_radius,
|
||||
self.core.main_window_id().unwrap(),
|
||||
),
|
||||
dock_item
|
||||
.toplevels
|
||||
.iter()
|
||||
.any(|y| focused_item.contains(&y.0.foreign_toplevel)),
|
||||
dot_radius,
|
||||
self.core.main_window_id().unwrap(),
|
||||
),
|
||||
dock_item
|
||||
.desktop_info
|
||||
.full_name(&self.locales)
|
||||
.unwrap_or_default()
|
||||
.to_string(),
|
||||
self.popup.is_some(),
|
||||
Message::Surface,
|
||||
None,
|
||||
)
|
||||
.into()
|
||||
})
|
||||
.collect();
|
||||
.desktop_info
|
||||
.full_name(&self.locales)
|
||||
.unwrap_or_default()
|
||||
.to_string(),
|
||||
self.popup.is_some(),
|
||||
Message::Surface,
|
||||
None,
|
||||
)
|
||||
.into()
|
||||
})
|
||||
.collect();
|
||||
|
||||
if active_popup_cutoff.is_some_and(|n| n < self.active_list.len()) {
|
||||
// button to show more active
|
||||
|
|
@ -1658,15 +1656,13 @@ impl cosmic::Application for CosmicAppList {
|
|||
+ self.core.applet.suggested_padding(false) * 2;
|
||||
window_size
|
||||
.map(|w| w.width)
|
||||
.map(|b| (b / suggested_width as f32) as u32)
|
||||
.unwrap_or(u32::MAX) as usize
|
||||
.map_or(u32::MAX, |b| (b / suggested_width as f32) as u32) as usize
|
||||
} else {
|
||||
let suggested_height = self.core.applet.suggested_size(false).1
|
||||
+ self.core.applet.suggested_padding(false) * 2;
|
||||
window_size
|
||||
.map(|w| w.height)
|
||||
.map(|b| (b / suggested_height as f32) as u32)
|
||||
.unwrap_or(u32::MAX) as usize
|
||||
.map_or(u32::MAX, |b| (b / suggested_height as f32) as u32) as usize
|
||||
}
|
||||
.max(4);
|
||||
if max_num < favorites.len() + active.len() {
|
||||
|
|
@ -1682,7 +1678,7 @@ impl cosmic::Application for CosmicAppList {
|
|||
row(favorites).spacing(app_icon.icon_spacing),
|
||||
|_, _| Message::DndDropFinished,
|
||||
)
|
||||
.drag_id(DND_FAVORITES.clone()),
|
||||
.drag_id(DND_FAVORITES),
|
||||
row(active).spacing(app_icon.icon_spacing).into(),
|
||||
container(vertical_rule(1))
|
||||
.height(Length::Fill)
|
||||
|
|
@ -1697,7 +1693,7 @@ impl cosmic::Application for CosmicAppList {
|
|||
column(favorites).spacing(app_icon.icon_spacing),
|
||||
|_data: Option<DndPathBuf>, _| Message::DndDropFinished,
|
||||
)
|
||||
.drag_id(DND_FAVORITES.clone()),
|
||||
.drag_id(DND_FAVORITES),
|
||||
column(active).spacing(app_icon.icon_spacing).into(),
|
||||
container(divider::horizontal::default())
|
||||
.width(Length::Fill)
|
||||
|
|
@ -1766,7 +1762,7 @@ impl cosmic::Application for CosmicAppList {
|
|||
.into()
|
||||
}
|
||||
|
||||
fn view_window(&self, id: window::Id) -> Element<Message> {
|
||||
fn view_window(&self, id: window::Id) -> Element<'_, Message> {
|
||||
let theme = self.core.system_theme();
|
||||
|
||||
if let Some((_, item, _, _)) = self.dnd_source.as_ref().filter(|s| s.0 == id) {
|
||||
|
|
@ -1907,7 +1903,7 @@ impl cosmic::Application for CosmicAppList {
|
|||
}),
|
||||
);
|
||||
|
||||
if toplevels.len() > 0 {
|
||||
if !toplevels.is_empty() {
|
||||
content = content.push(divider::horizontal::light());
|
||||
content = match toplevels.len() {
|
||||
1 => content.push(
|
||||
|
|
@ -2011,45 +2007,44 @@ impl cosmic::Application for CosmicAppList {
|
|||
let focused_item = self.currently_active_toplevel();
|
||||
let dot_radius = theme.cosmic().radius_xs();
|
||||
// show the overflow popup for active list
|
||||
let active: Vec<_> = self.active_list[active_popup_cutoff
|
||||
.map(|n| {
|
||||
let active: Vec<_> =
|
||||
self.active_list[..active_popup_cutoff.map_or(self.active_list.len(), |n| {
|
||||
if n < self.active_list.len() {
|
||||
n.saturating_sub(1)
|
||||
} else {
|
||||
n - 1
|
||||
}
|
||||
})
|
||||
.unwrap_or(self.active_list.len() - 1)..]
|
||||
.iter()
|
||||
.map(|dock_item| {
|
||||
self.core
|
||||
.applet
|
||||
.applet_tooltip(
|
||||
dock_item.as_icon(
|
||||
&self.core.applet,
|
||||
self.rectangle_tracker.as_ref(),
|
||||
self.popup.is_none(),
|
||||
self.config.enable_drag_source,
|
||||
self.gpus.as_deref(),
|
||||
})]
|
||||
.iter()
|
||||
.map(|dock_item| {
|
||||
self.core
|
||||
.applet
|
||||
.applet_tooltip(
|
||||
dock_item.as_icon(
|
||||
&self.core.applet,
|
||||
self.rectangle_tracker.as_ref(),
|
||||
self.popup.is_none(),
|
||||
self.config.enable_drag_source,
|
||||
self.gpus.as_deref(),
|
||||
dock_item
|
||||
.toplevels
|
||||
.iter()
|
||||
.any(|y| focused_item.contains(&y.0.foreign_toplevel)),
|
||||
dot_radius,
|
||||
self.core.main_window_id().unwrap(),
|
||||
),
|
||||
dock_item
|
||||
.toplevels
|
||||
.iter()
|
||||
.any(|y| focused_item.contains(&y.0.foreign_toplevel)),
|
||||
dot_radius,
|
||||
id,
|
||||
),
|
||||
dock_item
|
||||
.desktop_info
|
||||
.full_name(&self.locales)
|
||||
.unwrap_or_default()
|
||||
.to_string(),
|
||||
self.popup.is_some(),
|
||||
Message::Surface,
|
||||
Some(id),
|
||||
)
|
||||
.into()
|
||||
})
|
||||
.collect();
|
||||
.desktop_info
|
||||
.full_name(&self.locales)
|
||||
.unwrap_or_default()
|
||||
.to_string(),
|
||||
self.popup.is_some(),
|
||||
Message::Surface,
|
||||
None,
|
||||
)
|
||||
.into()
|
||||
})
|
||||
.collect();
|
||||
let content = match &self.core.applet.anchor {
|
||||
PanelAnchor::Left | PanelAnchor::Right => container(
|
||||
Column::with_children(active)
|
||||
|
|
@ -2117,7 +2112,7 @@ impl cosmic::Application for CosmicAppList {
|
|||
}
|
||||
})
|
||||
.collect();
|
||||
favorites.extend(favorites_extra[..favorite_to_remove].into_iter().cloned());
|
||||
favorites.extend(favorites_extra[..favorite_to_remove].iter().copied());
|
||||
let favorites: Vec<_> = favorites
|
||||
.iter()
|
||||
.rev()
|
||||
|
|
@ -2297,7 +2292,7 @@ impl CosmicAppList {
|
|||
favorite_index = (btn_count as usize).min(self.pinned_list.len());
|
||||
}
|
||||
// tracing::error!("{} {} {:?}", btn_count, favorite_index, active_index);
|
||||
return (Some(favorite_index), active_index);
|
||||
(Some(favorite_index), active_index)
|
||||
}
|
||||
|
||||
fn currently_active_toplevel(&self) -> Vec<ExtForeignToplevelHandleV1> {
|
||||
|
|
@ -2331,61 +2326,57 @@ impl CosmicAppList {
|
|||
info: &ToplevelInfo,
|
||||
unicase_appid: Ascii<&str>,
|
||||
) -> DesktopEntry {
|
||||
match fde::find_app_by_id(&self.desktop_entries, unicase_appid) {
|
||||
Some(appid) => appid.clone(),
|
||||
None => {
|
||||
// Update desktop entries in case it was not found.
|
||||
if let Some(appid) = fde::find_app_by_id(&self.desktop_entries, unicase_appid) {
|
||||
appid.clone()
|
||||
} else {
|
||||
// Update desktop entries in case it was not found.
|
||||
|
||||
self.update_desktop_entries();
|
||||
match fde::find_app_by_id(&self.desktop_entries, unicase_appid) {
|
||||
Some(appid) => appid.clone(),
|
||||
None => {
|
||||
tracing::error!(id = info.app_id, "could not find desktop entry for app");
|
||||
self.update_desktop_entries();
|
||||
if let Some(appid) = fde::find_app_by_id(&self.desktop_entries, unicase_appid) {
|
||||
appid.clone()
|
||||
} else {
|
||||
tracing::error!(id = info.app_id, "could not find desktop entry for app");
|
||||
|
||||
let mut fallback_entry = fde::DesktopEntry::from_appid(info.app_id.clone());
|
||||
let mut fallback_entry = fde::DesktopEntry::from_appid(info.app_id.clone());
|
||||
|
||||
// proton opens games as steam_app_X, where X is either
|
||||
// the steam appid or "default". games with a steam appid
|
||||
// can have a desktop entry generated elsewhere; this
|
||||
// specifically handles non-steam games opened
|
||||
// under proton
|
||||
// in addition, try to match WINE entries who have its
|
||||
// appid = the full name of the executable (incl. .exe)
|
||||
let is_proton_game = info.app_id == "steam_app_default";
|
||||
if is_proton_game || info.app_id.ends_with(".exe") {
|
||||
for entry in &self.desktop_entries {
|
||||
let localised_name = entry
|
||||
.name(&self.locales)
|
||||
.map(|x| x.to_string())
|
||||
.unwrap_or_default();
|
||||
// proton opens games as steam_app_X, where X is either
|
||||
// the steam appid or "default". games with a steam appid
|
||||
// can have a desktop entry generated elsewhere; this
|
||||
// specifically handles non-steam games opened
|
||||
// under proton
|
||||
// in addition, try to match WINE entries who have its
|
||||
// appid = the full name of the executable (incl. .exe)
|
||||
let is_proton_game = info.app_id == "steam_app_default";
|
||||
if is_proton_game || info.app_id.ends_with(".exe") {
|
||||
for entry in &self.desktop_entries {
|
||||
let localised_name = entry
|
||||
.name(&self.locales)
|
||||
.map(|x| x.to_string())
|
||||
.unwrap_or_default();
|
||||
|
||||
if localised_name == info.title {
|
||||
// if this is a proton game, we only want
|
||||
// to look for game entries
|
||||
if is_proton_game
|
||||
&& !entry.categories().unwrap_or_default().contains(&"Game")
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
fallback_entry = entry.clone();
|
||||
break;
|
||||
}
|
||||
if localised_name == info.title {
|
||||
// if this is a proton game, we only want
|
||||
// to look for game entries
|
||||
if is_proton_game
|
||||
&& !entry.categories().unwrap_or_default().contains(&"Game")
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
fallback_entry
|
||||
fallback_entry = entry.clone();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fallback_entry
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn launch_on_preferred_gpu(desktop_info: &DesktopEntry, gpus: Option<&[Gpu]>) -> Option<Message> {
|
||||
let Some(exec) = desktop_info.exec() else {
|
||||
return None;
|
||||
};
|
||||
let exec = desktop_info.exec()?;
|
||||
|
||||
let gpu_idx = gpus.map(|gpus| {
|
||||
if desktop_info.prefers_non_default_gpu() {
|
||||
|
|
|
|||
|
|
@ -43,6 +43,6 @@ pub fn localize() {
|
|||
let requested_languages = i18n_embed::DesktopLanguageRequester::requested_languages();
|
||||
|
||||
if let Err(error) = localizer.select(&requested_languages) {
|
||||
eprintln!("Error while loading language for App List {}", error);
|
||||
eprintln!("Error while loading language for App List {error}");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -179,7 +179,7 @@ impl ActivationHandler for AppData {
|
|||
fn new_token(&mut self, token: String, data: &ExecRequestData) {
|
||||
let _ = self.tx.unbounded_send(WaylandUpdate::ActivationToken {
|
||||
token: Some(token),
|
||||
app_id: data.app_id().map(|x| x.to_owned()),
|
||||
app_id: data.app_id().map(String::from),
|
||||
exec: data.exec.clone(),
|
||||
gpu_idx: data.gpu_idx,
|
||||
terminal: data.terminal,
|
||||
|
|
@ -313,7 +313,10 @@ impl Session {
|
|||
self.condvar.notify_all();
|
||||
}
|
||||
|
||||
fn wait_while<F: FnMut(&SessionInner) -> bool>(&self, mut f: F) -> MutexGuard<SessionInner> {
|
||||
fn wait_while<F: FnMut(&SessionInner) -> bool>(
|
||||
&self,
|
||||
mut f: F,
|
||||
) -> MutexGuard<'_, SessionInner> {
|
||||
self.condvar
|
||||
.wait_while(self.inner.lock().unwrap(), |data| f(data))
|
||||
.unwrap()
|
||||
|
|
@ -337,7 +340,7 @@ impl Dispatch<wl_shm_pool::WlShmPool, ()> for AppData {
|
|||
_app_data: &mut Self,
|
||||
_buffer: &wl_shm_pool::WlShmPool,
|
||||
_event: wl_shm_pool::Event,
|
||||
_: &(),
|
||||
(): &(),
|
||||
_: &Connection,
|
||||
_qh: &QueueHandle<Self>,
|
||||
) {
|
||||
|
|
@ -349,7 +352,7 @@ impl Dispatch<wl_buffer::WlBuffer, ()> for AppData {
|
|||
_app_data: &mut Self,
|
||||
_buffer: &wl_buffer::WlBuffer,
|
||||
_event: wl_buffer::Event,
|
||||
_: &(),
|
||||
(): &(),
|
||||
_: &Connection,
|
||||
_qh: &QueueHandle<Self>,
|
||||
) {
|
||||
|
|
@ -387,7 +390,7 @@ impl CaptureData {
|
|||
&self.qh,
|
||||
SessionData {
|
||||
session: session.clone(),
|
||||
session_data: Default::default(),
|
||||
session_data: ScreencopySessionData::default(),
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
|
|
@ -405,22 +408,19 @@ impl CaptureData {
|
|||
}
|
||||
|
||||
// XXX
|
||||
if !formats
|
||||
.shm_formats
|
||||
.contains(&wl_shm::Format::Abgr8888.into())
|
||||
{
|
||||
if !formats.shm_formats.contains(&wl_shm::Format::Abgr8888) {
|
||||
tracing::error!("No suitable buffer format found");
|
||||
tracing::warn!("Available formats: {:#?}", formats);
|
||||
return None;
|
||||
};
|
||||
}
|
||||
|
||||
let buf_len = width * height * 4;
|
||||
if let Some(len) = len {
|
||||
if len != buf_len {
|
||||
return None;
|
||||
}
|
||||
} else if let Err(_err) = rustix::fs::ftruncate(&fd, buf_len as _) {
|
||||
};
|
||||
} else if let Err(_err) = rustix::fs::ftruncate(&fd, buf_len.into()) {
|
||||
}
|
||||
let pool = self
|
||||
.wl_shm
|
||||
.create_pool(fd.as_fd(), buf_len as i32, &self.qh, ());
|
||||
|
|
@ -439,7 +439,7 @@ impl CaptureData {
|
|||
&[],
|
||||
&self.qh,
|
||||
FrameData {
|
||||
frame_data: Default::default(),
|
||||
frame_data: ScreencopyFrameData::default(),
|
||||
session: capture_session.clone(),
|
||||
},
|
||||
);
|
||||
|
|
@ -484,7 +484,7 @@ impl AppData {
|
|||
handle: &ExtForeignToplevelHandleV1,
|
||||
) -> Option<ZcosmicToplevelHandleV1> {
|
||||
self.toplevel_info_state
|
||||
.info(&handle)?
|
||||
.info(handle)?
|
||||
.cosmic_toplevel
|
||||
.clone()
|
||||
}
|
||||
|
|
@ -498,8 +498,7 @@ impl AppData {
|
|||
capturer: self.screencopy_state.capturer().clone(),
|
||||
};
|
||||
std::thread::spawn(move || {
|
||||
use std::ffi::CStr;
|
||||
let name = unsafe { CStr::from_bytes_with_nul_unchecked(b"app-list-screencopy\0") };
|
||||
let name = c"app-list-screencopy";
|
||||
let Ok(fd) = rustix::fs::memfd_create(name, rustix::fs::MemfdFlags::CLOEXEC) else {
|
||||
tracing::error!("Failed to get fd for capture");
|
||||
return;
|
||||
|
|
@ -535,7 +534,7 @@ impl AppData {
|
|||
tx.unbounded_send(WaylandUpdate::Image(handle, WaylandImage::new(img)))
|
||||
{
|
||||
tracing::error!("Failed to send image event to subscription {err:?}");
|
||||
};
|
||||
}
|
||||
} else {
|
||||
tracing::error!("Failed to capture image");
|
||||
}
|
||||
|
|
@ -624,7 +623,7 @@ pub(crate) fn wayland_handler(
|
|||
.expect("Failed to insert wayland source.");
|
||||
|
||||
if handle
|
||||
.insert_source(rx, |event, _, state| match event {
|
||||
.insert_source(rx, |event, (), state| match event {
|
||||
calloop::channel::Event::Msg(req) => match req {
|
||||
WaylandRequest::Screencopy(handle) => {
|
||||
state.send_image(handle.clone());
|
||||
|
|
|
|||
|
|
@ -91,16 +91,13 @@ async fn start_listening(
|
|||
}
|
||||
guard.as_mut().unwrap()
|
||||
};
|
||||
match rx.next().await {
|
||||
Some(u) => {
|
||||
_ = output.send(u).await;
|
||||
State::Waiting
|
||||
}
|
||||
None => {
|
||||
_ = output.send(WaylandUpdate::Finished).await;
|
||||
tracing::error!("Wayland handler thread died");
|
||||
State::Finished
|
||||
}
|
||||
if let Some(u) = rx.next().await {
|
||||
_ = output.send(u).await;
|
||||
State::Waiting
|
||||
} else {
|
||||
_ = output.send(WaylandUpdate::Finished).await;
|
||||
tracing::error!("Wayland handler thread died");
|
||||
State::Finished
|
||||
}
|
||||
}
|
||||
State::Finished => iced::futures::future::pending().await,
|
||||
|
|
|
|||
|
|
@ -235,7 +235,7 @@ impl cosmic::Application for CosmicA11yApplet {
|
|||
});
|
||||
} else {
|
||||
tracing::error!("Wayland tx is None");
|
||||
};
|
||||
}
|
||||
}
|
||||
Message::Token(u) => match u {
|
||||
TokenUpdate::Init(tx) => {
|
||||
|
|
@ -303,7 +303,7 @@ impl cosmic::Application for CosmicA11yApplet {
|
|||
Task::none()
|
||||
}
|
||||
|
||||
fn view(&self) -> Element<Message> {
|
||||
fn view(&self) -> Element<'_, Message> {
|
||||
self.core
|
||||
.applet
|
||||
.icon_button("preferences-desktop-accessibility-symbolic")
|
||||
|
|
@ -311,7 +311,7 @@ impl cosmic::Application for CosmicA11yApplet {
|
|||
.into()
|
||||
}
|
||||
|
||||
fn view_window(&self, _id: window::Id) -> Element<Message> {
|
||||
fn view_window(&self, _id: window::Id) -> Element<'_, Message> {
|
||||
let Spacing {
|
||||
space_xxs, space_s, ..
|
||||
} = theme::active().cosmic().spacing;
|
||||
|
|
|
|||
|
|
@ -82,6 +82,6 @@ pub struct WaylandWatcher {
|
|||
impl WaylandWatcher {
|
||||
pub fn new() -> anyhow::Result<Self> {
|
||||
let (tx, rx) = thread::spawn_wayland_connection(1)?;
|
||||
Ok(Self { tx, rx })
|
||||
Ok(Self { rx, tx })
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,6 +43,6 @@ pub fn localize() {
|
|||
let requested_languages = i18n_embed::DesktopLanguageRequester::requested_languages();
|
||||
|
||||
if let Err(error) = localizer.select(&requested_languages) {
|
||||
eprintln!("Error while loading language for App List {}", error);
|
||||
eprintln!("Error while loading language for App List {error}");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -166,14 +166,13 @@ pub enum Message {
|
|||
}
|
||||
|
||||
impl Audio {
|
||||
fn playback_buttons(&self) -> Option<Element<Message>> {
|
||||
fn playback_buttons(&self) -> Option<Element<'_, Message>> {
|
||||
if self.player_status.is_some() && self.config.show_media_controls_in_top_panel {
|
||||
let mut elements = Vec::with_capacity(3);
|
||||
if self
|
||||
.player_status
|
||||
.as_ref()
|
||||
.map(|s| s.can_go_previous)
|
||||
.unwrap_or_default()
|
||||
.is_some_and(|s| s.can_go_previous)
|
||||
{
|
||||
elements.push(
|
||||
self.core
|
||||
|
|
@ -181,7 +180,7 @@ impl Audio {
|
|||
.icon_button(GO_BACK)
|
||||
.on_press(Message::MprisRequest(MprisRequest::Previous))
|
||||
.into(),
|
||||
)
|
||||
);
|
||||
}
|
||||
if let Some(play) = self.is_play() {
|
||||
elements.push(
|
||||
|
|
@ -196,12 +195,7 @@ impl Audio {
|
|||
.into(),
|
||||
);
|
||||
}
|
||||
if self
|
||||
.player_status
|
||||
.as_ref()
|
||||
.map(|s| s.can_go_next)
|
||||
.unwrap_or_default()
|
||||
{
|
||||
if self.player_status.as_ref().is_some_and(|s| s.can_go_next) {
|
||||
elements.push(
|
||||
self.core
|
||||
.applet
|
||||
|
|
@ -224,7 +218,7 @@ impl Audio {
|
|||
}
|
||||
}
|
||||
|
||||
fn go_previous(&self, icon_size: u16) -> Option<Element<Message>> {
|
||||
fn go_previous(&self, icon_size: u16) -> Option<Element<'_, Message>> {
|
||||
self.player_status.as_ref().and_then(|s| {
|
||||
if s.can_go_previous {
|
||||
Some(
|
||||
|
|
@ -240,7 +234,7 @@ impl Audio {
|
|||
})
|
||||
}
|
||||
|
||||
fn go_next(&self, icon_size: u16) -> Option<Element<Message>> {
|
||||
fn go_next(&self, icon_size: u16) -> Option<Element<'_, Message>> {
|
||||
self.player_status.as_ref().and_then(|s| {
|
||||
if s.can_go_next {
|
||||
Some(
|
||||
|
|
@ -277,17 +271,11 @@ impl Audio {
|
|||
}
|
||||
|
||||
fn current_output_mute(&self) -> bool {
|
||||
self.current_output
|
||||
.as_ref()
|
||||
.map(|o| o.mute)
|
||||
.unwrap_or_default()
|
||||
self.current_output.as_ref().is_some_and(|o| o.mute)
|
||||
}
|
||||
|
||||
fn current_input_mute(&self) -> bool {
|
||||
self.current_input
|
||||
.as_ref()
|
||||
.map(|o| o.mute)
|
||||
.unwrap_or_default()
|
||||
self.current_input.as_ref().is_some_and(|o| o.mute)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -421,7 +409,7 @@ impl cosmic::Application for Audio {
|
|||
connection.send(pulse::Message::SetSourceVolumeByName(
|
||||
name.clone(),
|
||||
device.volume,
|
||||
))
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -434,7 +422,7 @@ impl cosmic::Application for Audio {
|
|||
if let Some(device) = &self.current_output {
|
||||
if let Some(name) = &device.name {
|
||||
connection
|
||||
.send(pulse::Message::SetSinkMuteByName(name.clone(), device.mute))
|
||||
.send(pulse::Message::SetSinkMuteByName(name.clone(), device.mute));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -625,7 +613,7 @@ impl cosmic::Application for Audio {
|
|||
});
|
||||
} else {
|
||||
tracing::error!("Wayland tx is None");
|
||||
};
|
||||
}
|
||||
}
|
||||
Message::Token(u) => match u {
|
||||
TokenUpdate::Init(tx) => {
|
||||
|
|
@ -688,7 +676,7 @@ impl cosmic::Application for Audio {
|
|||
cosmic::app::Action::Surface(a),
|
||||
));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Task::none()
|
||||
}
|
||||
|
|
@ -711,7 +699,7 @@ impl cosmic::Application for Audio {
|
|||
])
|
||||
}
|
||||
|
||||
fn view(&self) -> Element<Message> {
|
||||
fn view(&self) -> Element<'_, Message> {
|
||||
let btn = self
|
||||
.core
|
||||
.applet
|
||||
|
|
@ -765,7 +753,7 @@ impl cosmic::Application for Audio {
|
|||
.into()
|
||||
}
|
||||
|
||||
fn view_window(&self, _id: window::Id) -> Element<Message> {
|
||||
fn view_window(&self, _id: window::Id) -> Element<'_, Message> {
|
||||
let Spacing {
|
||||
space_xxs, space_s, ..
|
||||
} = theme::active().cosmic().spacing;
|
||||
|
|
|
|||
|
|
@ -43,6 +43,6 @@ pub fn localize() {
|
|||
let requested_languages = i18n_embed::DesktopLanguageRequester::requested_languages();
|
||||
|
||||
if let Err(error) = localizer.select(&requested_languages) {
|
||||
eprintln!("Error while loading language for App List {}", error);
|
||||
eprintln!("Error while loading language for App List {error}");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -104,7 +104,7 @@ struct State {
|
|||
impl Default for State {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
drag_initiated: Default::default(),
|
||||
drag_initiated: Option::default(),
|
||||
is_out_of_bounds: true,
|
||||
}
|
||||
}
|
||||
|
|
@ -129,8 +129,8 @@ impl<'a, Message, Theme, Renderer> MouseArea<'a, Message, Theme, Renderer> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, Message, Theme, Renderer> Widget<Message, Theme, Renderer>
|
||||
for MouseArea<'a, Message, Theme, Renderer>
|
||||
impl<Message, Theme, Renderer> Widget<Message, Theme, Renderer>
|
||||
for MouseArea<'_, Message, Theme, Renderer>
|
||||
where
|
||||
Renderer: renderer::Renderer,
|
||||
Message: Clone,
|
||||
|
|
@ -267,7 +267,7 @@ where
|
|||
renderer: &Renderer,
|
||||
dnd_rectangles: &mut cosmic::iced_core::clipboard::DndDestinationRectangles,
|
||||
) {
|
||||
if let Some(state) = state.children.iter().next() {
|
||||
if let Some(state) = state.children.first() {
|
||||
self.content
|
||||
.as_widget()
|
||||
.drag_destinations(state, layout, renderer, dnd_rectangles);
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ pub struct PlayerStatus {
|
|||
impl PlayerStatus {
|
||||
async fn new(player: Player) -> Option<Self> {
|
||||
let metadata = player.metadata().await.ok()?;
|
||||
let pathname = metadata.url().unwrap_or("".into());
|
||||
let pathname = metadata.url().unwrap_or_default();
|
||||
let pathbuf = PathBuf::from(pathname);
|
||||
|
||||
let title = metadata
|
||||
|
|
@ -108,7 +108,7 @@ impl MprisPlayer {
|
|||
})
|
||||
}
|
||||
|
||||
fn name(&self) -> &BusName {
|
||||
fn name(&self) -> &BusName<'_> {
|
||||
self.player.inner().destination()
|
||||
}
|
||||
}
|
||||
|
|
@ -171,7 +171,7 @@ impl State {
|
|||
filter_firefox_players(&mut players);
|
||||
|
||||
// pre-sort by path so that the same player is always selected
|
||||
players.sort_by(|a, b| a.name().cmp(&b.name()));
|
||||
players.sort_by(|a, b| a.name().cmp(b.name()));
|
||||
|
||||
let mut state = Self {
|
||||
conn,
|
||||
|
|
@ -196,7 +196,7 @@ impl State {
|
|||
};
|
||||
self.players.push(player);
|
||||
filter_firefox_players(&mut self.players);
|
||||
self.players.sort_by(|a, b| a.name().cmp(&b.name()));
|
||||
self.players.sort_by(|a, b| a.name().cmp(b.name()));
|
||||
self.update_any_player_state_stream().await;
|
||||
}
|
||||
|
||||
|
|
@ -254,7 +254,7 @@ async fn run(output: &mut futures::channel::mpsc::Sender<MprisUpdate>) {
|
|||
_ = output.send(MprisUpdate::Player(player_status)).await;
|
||||
} else {
|
||||
tracing::error!("Failed to get player status.");
|
||||
};
|
||||
}
|
||||
} else {
|
||||
let _ = output.send(MprisUpdate::Setup).await;
|
||||
}
|
||||
|
|
@ -287,7 +287,7 @@ async fn run(output: &mut futures::channel::mpsc::Sender<MprisUpdate>) {
|
|||
}
|
||||
}
|
||||
|
||||
async fn find_active<'a>(players: &'a Vec<MprisPlayer>) -> Option<&'a MprisPlayer> {
|
||||
async fn find_active<'a>(players: &'a [MprisPlayer]) -> Option<&'a MprisPlayer> {
|
||||
let mut best = (0, None::<&'a MprisPlayer>);
|
||||
let eval = |p: Player| async move {
|
||||
let v = {
|
||||
|
|
@ -303,7 +303,7 @@ async fn find_active<'a>(players: &'a Vec<MprisPlayer>) -> Option<&'a MprisPlaye
|
|||
v + p.metadata().await.is_ok() as i32
|
||||
};
|
||||
|
||||
for p in players.iter() {
|
||||
for p in players {
|
||||
let v = eval(p.player.clone()).await;
|
||||
if v > best.0 {
|
||||
best = (v, Some(p));
|
||||
|
|
|
|||
|
|
@ -168,7 +168,7 @@ impl Connection {
|
|||
panic!();
|
||||
}
|
||||
mpsc::error::TrySendError::Full(_) => {
|
||||
tracing::warn!("Failed to send message to PulseAudio server: channel is full")
|
||||
tracing::warn!("Failed to send message to PulseAudio server: channel is full");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -249,9 +249,8 @@ impl PulseHandle {
|
|||
for msg in msgs.drain(..) {
|
||||
match msg {
|
||||
Message::GetDefaultSink => {
|
||||
let server = match server.as_mut() {
|
||||
Some(s) => s,
|
||||
None => continue,
|
||||
let Some(server) = server.as_mut() else {
|
||||
continue;
|
||||
};
|
||||
match server.get_default_sink() {
|
||||
Ok(sink) => {
|
||||
|
|
@ -266,9 +265,8 @@ impl PulseHandle {
|
|||
}
|
||||
}
|
||||
Message::GetDefaultSource => {
|
||||
let server = match server.as_mut() {
|
||||
Some(s) => s,
|
||||
None => continue,
|
||||
let Some(server) = server.as_mut() else {
|
||||
continue;
|
||||
};
|
||||
match server.get_default_source() {
|
||||
Ok(source) => {
|
||||
|
|
@ -286,9 +284,8 @@ impl PulseHandle {
|
|||
}
|
||||
}
|
||||
Message::GetSinks => {
|
||||
let server = match server.as_mut() {
|
||||
Some(s) => s,
|
||||
None => continue,
|
||||
let Some(server) = server.as_mut() else {
|
||||
continue;
|
||||
};
|
||||
match server.get_sinks() {
|
||||
Ok(sinks) => {
|
||||
|
|
@ -302,9 +299,8 @@ impl PulseHandle {
|
|||
}
|
||||
}
|
||||
Message::GetSources => {
|
||||
let server = match server.as_mut() {
|
||||
Some(s) => s,
|
||||
None => continue,
|
||||
let Some(server) = server.as_mut() else {
|
||||
continue;
|
||||
};
|
||||
match server.get_sources() {
|
||||
Ok(sinks) => {
|
||||
|
|
@ -318,23 +314,20 @@ impl PulseHandle {
|
|||
}
|
||||
}
|
||||
Message::SetSinkVolumeByName(name, channel_volumes) => {
|
||||
let server = match server.as_mut() {
|
||||
Some(s) => s,
|
||||
None => continue,
|
||||
let Some(server) = server.as_mut() else {
|
||||
continue;
|
||||
};
|
||||
server.set_sink_volume_by_name(&name, &channel_volumes)
|
||||
server.set_sink_volume_by_name(&name, &channel_volumes);
|
||||
}
|
||||
Message::SetSourceVolumeByName(name, channel_volumes) => {
|
||||
let server = match server.as_mut() {
|
||||
Some(s) => s,
|
||||
None => continue,
|
||||
let Some(server) = server.as_mut() else {
|
||||
continue;
|
||||
};
|
||||
server.set_source_volume_by_name(&name, &channel_volumes)
|
||||
server.set_source_volume_by_name(&name, &channel_volumes);
|
||||
}
|
||||
Message::SetSinkMuteByName(name, mute) => {
|
||||
let server = match server.as_mut() {
|
||||
Some(s) => s,
|
||||
None => continue,
|
||||
let Some(server) = server.as_mut() else {
|
||||
continue;
|
||||
};
|
||||
|
||||
let op =
|
||||
|
|
@ -342,9 +335,8 @@ impl PulseHandle {
|
|||
server.wait_for_result(op).ok();
|
||||
}
|
||||
Message::SetSourceMuteByName(name, mute) => {
|
||||
let server = match server.as_mut() {
|
||||
Some(s) => s,
|
||||
None => continue,
|
||||
let Some(server) = server.as_mut() else {
|
||||
continue;
|
||||
};
|
||||
|
||||
let op = server
|
||||
|
|
@ -367,7 +359,7 @@ impl PulseHandle {
|
|||
Self::send_connected(&from_pulse_send).await;
|
||||
}
|
||||
} else {
|
||||
match PulseServer::connect().and_then(|server| server.init()) {
|
||||
match PulseServer::connect().and_then(PulseServer::init) {
|
||||
Ok(new_server) => {
|
||||
tracing::info!("Connected to server");
|
||||
Self::send_connected(&from_pulse_send).await;
|
||||
|
|
@ -384,13 +376,11 @@ impl PulseHandle {
|
|||
}
|
||||
}
|
||||
Message::SetDefaultSink(device) => {
|
||||
let server = match server.as_mut() {
|
||||
Some(s) => s,
|
||||
None => continue,
|
||||
let Some(server) = server.as_mut() else {
|
||||
continue;
|
||||
};
|
||||
let default_sink = match server.get_default_sink() {
|
||||
Ok(sink) => sink,
|
||||
Err(_) => continue,
|
||||
let Ok(default_sink) = server.get_default_sink() else {
|
||||
continue;
|
||||
};
|
||||
let to_move = server.get_sink_inputs(default_sink.index);
|
||||
if let Some(name) = device.name.as_ref() {
|
||||
|
|
@ -405,13 +395,11 @@ impl PulseHandle {
|
|||
}
|
||||
}
|
||||
Message::SetDefaultSource(device) => {
|
||||
let server = match server.as_mut() {
|
||||
Some(s) => s,
|
||||
None => continue,
|
||||
let Some(server) = server.as_mut() else {
|
||||
continue;
|
||||
};
|
||||
let default_source = match server.get_default_source() {
|
||||
Ok(source) => source,
|
||||
Err(_) => continue,
|
||||
let Ok(default_source) = server.get_default_source() else {
|
||||
continue;
|
||||
};
|
||||
let to_move = server.get_source_outputs(default_source.index);
|
||||
if let Some(name) = device.name.as_ref() {
|
||||
|
|
@ -421,12 +409,12 @@ impl PulseHandle {
|
|||
.await
|
||||
{
|
||||
tracing::error!("ERROR! {:?}", err);
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
tracing::warn!("message doesn't match")
|
||||
tracing::warn!("message doesn't match");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -440,12 +428,12 @@ impl PulseHandle {
|
|||
}
|
||||
|
||||
async fn send_disconnected(sender: &tokio::sync::mpsc::Sender<Message>) {
|
||||
sender.send(Message::Disconnected).await.unwrap()
|
||||
sender.send(Message::Disconnected).await.unwrap();
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
async fn send_connected(sender: &tokio::sync::mpsc::Sender<Message>) {
|
||||
sender.send(Message::Connected).await.unwrap()
|
||||
sender.send(Message::Connected).await.unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -532,7 +520,7 @@ impl PulseServer {
|
|||
}
|
||||
|
||||
// Get a list of output devices
|
||||
pub fn get_sinks(&self) -> Result<Vec<DeviceInfo>, PulseServerError> {
|
||||
pub fn get_sinks(&self) -> Result<Vec<DeviceInfo>, PulseServerError<'_>> {
|
||||
let list: Rc<RefCell<Option<Vec<DeviceInfo>>>> = Rc::new(RefCell::new(Some(Vec::new())));
|
||||
let list_ref = list.clone();
|
||||
|
||||
|
|
@ -543,7 +531,7 @@ impl PulseServer {
|
|||
}
|
||||
},
|
||||
);
|
||||
self.wait_for_result(operation).and_then(|_| {
|
||||
self.wait_for_result(operation).and_then(|()| {
|
||||
list.borrow_mut().take().ok_or(PulseServerError::Misc(
|
||||
"get_sinks(): failed to wait for operation",
|
||||
))
|
||||
|
|
@ -551,7 +539,7 @@ impl PulseServer {
|
|||
}
|
||||
|
||||
// Get a list of input devices
|
||||
pub fn get_sources(&self) -> Result<Vec<DeviceInfo>, PulseServerError> {
|
||||
pub fn get_sources(&self) -> Result<Vec<DeviceInfo>, PulseServerError<'_>> {
|
||||
let list: Rc<RefCell<Option<Vec<DeviceInfo>>>> = Rc::new(RefCell::new(Some(Vec::new())));
|
||||
let list_ref = list.clone();
|
||||
|
||||
|
|
@ -562,14 +550,14 @@ impl PulseServer {
|
|||
}
|
||||
},
|
||||
);
|
||||
self.wait_for_result(operation).and_then(|_| {
|
||||
self.wait_for_result(operation).and_then(|()| {
|
||||
list.borrow_mut().take().ok_or(PulseServerError::Misc(
|
||||
"get_sources(): Failed to wait for operation",
|
||||
))
|
||||
})
|
||||
}
|
||||
|
||||
pub fn get_server_info(&mut self) -> Result<ServerInfo, PulseServerError> {
|
||||
pub fn get_server_info(&mut self) -> Result<ServerInfo, PulseServerError<'_>> {
|
||||
let info = Rc::new(RefCell::new(Some(None)));
|
||||
let info_ref = info.clone();
|
||||
|
||||
|
|
@ -643,7 +631,7 @@ impl PulseServer {
|
|||
true
|
||||
}
|
||||
|
||||
fn get_default_sink(&mut self) -> Result<DeviceInfo, PulseServerError> {
|
||||
fn get_default_sink(&mut self) -> Result<DeviceInfo, PulseServerError<'_>> {
|
||||
let server_info = self.get_server_info();
|
||||
match server_info {
|
||||
Ok(info) => {
|
||||
|
|
@ -668,7 +656,7 @@ impl PulseServer {
|
|||
}
|
||||
}
|
||||
|
||||
fn get_default_source(&mut self) -> Result<DeviceInfo, PulseServerError> {
|
||||
fn get_default_source(&mut self) -> Result<DeviceInfo, PulseServerError<'_>> {
|
||||
let server_info = self.get_server_info();
|
||||
match server_info {
|
||||
Ok(info) => {
|
||||
|
|
@ -750,7 +738,7 @@ impl PulseServer {
|
|||
fn wait_for_result<G: ?Sized>(
|
||||
&self,
|
||||
operation: pulse::operation::Operation<G>,
|
||||
) -> Result<(), PulseServerError> {
|
||||
) -> Result<(), PulseServerError<'_>> {
|
||||
// TODO: make this loop async. It is already in an async context, so
|
||||
// we could make this thread sleep while waiting for the pulse server's
|
||||
// response.
|
||||
|
|
|
|||
|
|
@ -261,7 +261,7 @@ impl cosmic::Application for CosmicBatteryApplet {
|
|||
}
|
||||
return cosmic::iced::Task::perform(
|
||||
tokio::time::sleep(Duration::from_millis(200)),
|
||||
|_| cosmic::Action::App(Message::SetKbdBrightnessDebounced),
|
||||
|()| cosmic::Action::App(Message::SetKbdBrightnessDebounced),
|
||||
);
|
||||
}
|
||||
Message::SetScreenBrightnessDebounced => {
|
||||
|
|
@ -276,7 +276,7 @@ impl cosmic::Application for CosmicBatteryApplet {
|
|||
}
|
||||
return cosmic::iced::Task::perform(
|
||||
tokio::time::sleep(Duration::from_millis(200)),
|
||||
|_| cosmic::Action::App(Message::SetScreenBrightnessDebounced),
|
||||
|()| cosmic::Action::App(Message::SetScreenBrightnessDebounced),
|
||||
);
|
||||
}
|
||||
Message::ReleaseKbdBrightness => {
|
||||
|
|
@ -410,7 +410,7 @@ impl cosmic::Application for CosmicBatteryApplet {
|
|||
});
|
||||
} else {
|
||||
tracing::error!("Wayland tx is None");
|
||||
};
|
||||
}
|
||||
}
|
||||
Message::Token(u) => match u {
|
||||
TokenUpdate::Init(tx) => {
|
||||
|
|
@ -433,17 +433,13 @@ impl cosmic::Application for CosmicBatteryApplet {
|
|||
self.update_trigger = Some(tx);
|
||||
}
|
||||
Message::GpuOn(path, name, app_list) => {
|
||||
let toggled = self
|
||||
.gpus
|
||||
.get(&path)
|
||||
.map(|data| data.toggled)
|
||||
.unwrap_or_default();
|
||||
let toggled = self.gpus.get(&path).is_some_and(|data| data.toggled);
|
||||
self.gpus.insert(
|
||||
path,
|
||||
GPUData {
|
||||
name,
|
||||
app_list,
|
||||
toggled,
|
||||
app_list,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
|
@ -483,7 +479,7 @@ impl cosmic::Application for CosmicBatteryApplet {
|
|||
Task::none()
|
||||
}
|
||||
|
||||
fn view(&self) -> Element<Message> {
|
||||
fn view(&self) -> Element<'_, Message> {
|
||||
let btn = self
|
||||
.core
|
||||
.applet
|
||||
|
|
@ -491,7 +487,9 @@ impl cosmic::Application for CosmicBatteryApplet {
|
|||
.on_press_down(Message::TogglePopup)
|
||||
.into();
|
||||
|
||||
let content = if !self.gpus.is_empty() {
|
||||
let content = if self.gpus.is_empty() {
|
||||
btn
|
||||
} else {
|
||||
let dot = container(vertical_space().height(Length::Fixed(0.0)))
|
||||
.padding(2.0)
|
||||
.class(cosmic::style::Container::Custom(Box::new(|theme| {
|
||||
|
|
@ -517,14 +515,12 @@ impl cosmic::Application for CosmicBatteryApplet {
|
|||
.align_y(Alignment::Center)
|
||||
.into(),
|
||||
}
|
||||
} else {
|
||||
btn
|
||||
};
|
||||
|
||||
self.core.applet.autosize_window(content).into()
|
||||
}
|
||||
|
||||
fn view_window(&self, _id: window::Id) -> Element<Message> {
|
||||
fn view_window(&self, _id: window::Id) -> Element<'_, Message> {
|
||||
let Spacing {
|
||||
space_xxs, space_s, ..
|
||||
} = theme::active().cosmic().spacing;
|
||||
|
|
@ -740,7 +736,7 @@ impl cosmic::Application for CosmicBatteryApplet {
|
|||
width: 0.0,
|
||||
color: Color::TRANSPARENT,
|
||||
},
|
||||
shadow: Default::default(),
|
||||
shadow: Shadow::default(),
|
||||
icon_color: Some(Color::TRANSPARENT),
|
||||
}
|
||||
},))),
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ pub async fn get_power_profile(daemon: Backend<'_>) -> Result<Power> {
|
|||
"Battery" => Ok(Power::Battery),
|
||||
"Balanced" => Ok(Power::Balanced),
|
||||
"Performance" => Ok(Power::Performance),
|
||||
_ => panic!("Unknown power profile: {}", power),
|
||||
_ => panic!("Unknown power profile: {power}"),
|
||||
}
|
||||
}
|
||||
Backend::PowerProfilesDaemon(ppd) => {
|
||||
|
|
@ -226,7 +226,7 @@ pub async fn get_charging_limit() -> anyhow::Result<bool> {
|
|||
Backend::PowerProfilesDaemon(_) => {
|
||||
tracing::info!("Power Profiles Daemon is not supported.");
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
anyhow::bail!("Unsupported")
|
||||
|
|
@ -245,7 +245,7 @@ pub async fn set_charging_limit() -> Result<()> {
|
|||
"Setting charging limit via Power Profiles Daemon is not supported."
|
||||
);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
|
|
|
|||
|
|
@ -79,7 +79,7 @@ async fn is_desktop() -> bool {
|
|||
}
|
||||
|
||||
async fn powered_on(path: impl AsRef<Path>) -> bool {
|
||||
let Some(component) = path.as_ref().components().last() else {
|
||||
let Some(component) = path.as_ref().components().next_back() else {
|
||||
return true;
|
||||
};
|
||||
let name_str = component.as_os_str();
|
||||
|
|
@ -87,7 +87,7 @@ async fn powered_on(path: impl AsRef<Path>) -> bool {
|
|||
return true;
|
||||
};
|
||||
let Ok(state) =
|
||||
tokio::fs::read_to_string(format!("/sys/class/drm/{}/device/power_state", name)).await
|
||||
tokio::fs::read_to_string(format!("/sys/class/drm/{name}/device/power_state")).await
|
||||
else {
|
||||
return true;
|
||||
};
|
||||
|
|
@ -201,120 +201,117 @@ impl Gpu {
|
|||
}
|
||||
|
||||
async fn app_list(&self, running_apps: &[RunningApp]) -> Option<Vec<Entry>> {
|
||||
match self.driver.as_ref().and_then(|s| s.to_str()) {
|
||||
Some("nvidia") => {
|
||||
// figure out bus path for calling nvidia-smi
|
||||
let mut sys_path = PathBuf::from("/sys/class/drm");
|
||||
sys_path.push(self.path.components().last()?.as_os_str());
|
||||
let buslink = std::fs::read_link(sys_path)
|
||||
.ok()?
|
||||
.components()
|
||||
.rev()
|
||||
.nth(2)?
|
||||
.as_os_str()
|
||||
.to_string_lossy()
|
||||
.into_owned();
|
||||
if let Some("nvidia") = self.driver.as_ref().and_then(|s| s.to_str()) {
|
||||
// figure out bus path for calling nvidia-smi
|
||||
let mut sys_path = PathBuf::from("/sys/class/drm");
|
||||
sys_path.push(self.path.components().next_back()?.as_os_str());
|
||||
let buslink = std::fs::read_link(sys_path)
|
||||
.ok()?
|
||||
.components()
|
||||
.rev()
|
||||
.nth(2)?
|
||||
.as_os_str()
|
||||
.to_string_lossy()
|
||||
.into_owned();
|
||||
|
||||
let smi_output = match tokio::process::Command::new("nvidia-smi")
|
||||
.args(["pmon", "--id", &buslink, "--count", "1"])
|
||||
.output()
|
||||
.await
|
||||
{
|
||||
Ok(output) if output.status.success() => {
|
||||
String::from_utf8_lossy(&output.stdout).into_owned()
|
||||
}
|
||||
Ok(output) => {
|
||||
debug!(
|
||||
"smi returned error code {}: {}",
|
||||
output.status,
|
||||
String::from_utf8_lossy(&output.stdout)
|
||||
);
|
||||
return None;
|
||||
}
|
||||
Err(err) => {
|
||||
debug!("smi returned error code: {}", err);
|
||||
return None;
|
||||
}
|
||||
};
|
||||
let smi_output = match tokio::process::Command::new("nvidia-smi")
|
||||
.args(["pmon", "--id", &buslink, "--count", "1"])
|
||||
.output()
|
||||
.await
|
||||
{
|
||||
Ok(output) if output.status.success() => {
|
||||
String::from_utf8_lossy(&output.stdout).into_owned()
|
||||
}
|
||||
Ok(output) => {
|
||||
debug!(
|
||||
"smi returned error code {}: {}",
|
||||
output.status,
|
||||
String::from_utf8_lossy(&output.stdout)
|
||||
);
|
||||
return None;
|
||||
}
|
||||
Err(err) => {
|
||||
debug!("smi returned error code: {}", err);
|
||||
return None;
|
||||
}
|
||||
};
|
||||
|
||||
Some(
|
||||
smi_output
|
||||
.lines()
|
||||
.filter(|line| {
|
||||
// smi shows an empty line filled with - when no app is running
|
||||
let components = line.split_whitespace().collect::<Vec<_>>();
|
||||
components[1].trim().ne("-") && !line.starts_with('#')
|
||||
})
|
||||
.map(|line| {
|
||||
let components = line.split_whitespace().collect::<Vec<_>>();
|
||||
let pid = components[1].trim();
|
||||
let process_name = components.last().unwrap().trim();
|
||||
Some(
|
||||
smi_output
|
||||
.lines()
|
||||
.filter(|line| {
|
||||
// smi shows an empty line filled with - when no app is running
|
||||
let components = line.split_whitespace().collect::<Vec<_>>();
|
||||
components[1].trim().ne("-") && !line.starts_with('#')
|
||||
})
|
||||
.map(|line| {
|
||||
let components = line.split_whitespace().collect::<Vec<_>>();
|
||||
let pid = components[1].trim();
|
||||
let process_name = components.last().unwrap().trim();
|
||||
|
||||
if let Some(application) = running_apps
|
||||
.iter()
|
||||
.find(|running_app| running_app.executable_name == process_name)
|
||||
{
|
||||
Entry {
|
||||
name: application.name.clone(),
|
||||
icon: application.icon.clone(),
|
||||
secondary: String::new(),
|
||||
}
|
||||
} else {
|
||||
Entry {
|
||||
name: process_name.to_string(),
|
||||
icon: None,
|
||||
secondary: pid.to_string(),
|
||||
}
|
||||
if let Some(application) = running_apps
|
||||
.iter()
|
||||
.find(|running_app| running_app.executable_name == process_name)
|
||||
{
|
||||
Entry {
|
||||
name: application.name.clone(),
|
||||
icon: application.icon.clone(),
|
||||
secondary: String::new(),
|
||||
}
|
||||
})
|
||||
.collect(),
|
||||
)
|
||||
}
|
||||
_ => {
|
||||
let lsof_output = match tokio::process::Command::new("lsof")
|
||||
.args([OsStr::new("-t"), self.path.as_os_str()])
|
||||
.output()
|
||||
.await
|
||||
{
|
||||
Ok(output) => String::from_utf8_lossy(&output.stdout).into_owned(),
|
||||
Err(err) => {
|
||||
debug!("lsof returned error code: {}", err);
|
||||
return None;
|
||||
}
|
||||
};
|
||||
|
||||
Some(
|
||||
lsof_output
|
||||
.lines()
|
||||
.filter_map(|pid| {
|
||||
let executable = std::fs::read_link(format!("/proc/{}/exe", pid))
|
||||
.ok()?
|
||||
.components()
|
||||
.last()?
|
||||
.as_os_str()
|
||||
.to_string_lossy()
|
||||
.into_owned();
|
||||
|
||||
if let Some(application) = running_apps
|
||||
.iter()
|
||||
.find(|running_app| running_app.executable_name == executable)
|
||||
{
|
||||
Some(Entry {
|
||||
name: application.name.clone(),
|
||||
icon: application.icon.clone(),
|
||||
secondary: String::new(),
|
||||
})
|
||||
} else {
|
||||
Some(Entry {
|
||||
name: executable,
|
||||
icon: None,
|
||||
secondary: pid.to_string(),
|
||||
})
|
||||
} else {
|
||||
Entry {
|
||||
name: process_name.to_string(),
|
||||
icon: None,
|
||||
secondary: pid.to_string(),
|
||||
}
|
||||
})
|
||||
.collect(),
|
||||
)
|
||||
}
|
||||
}
|
||||
})
|
||||
.collect(),
|
||||
)
|
||||
} else {
|
||||
let lsof_output = match tokio::process::Command::new("lsof")
|
||||
.args([OsStr::new("-t"), self.path.as_os_str()])
|
||||
.output()
|
||||
.await
|
||||
{
|
||||
Ok(output) => String::from_utf8_lossy(&output.stdout).into_owned(),
|
||||
Err(err) => {
|
||||
debug!("lsof returned error code: {err}");
|
||||
return None;
|
||||
}
|
||||
};
|
||||
|
||||
Some(
|
||||
lsof_output
|
||||
.lines()
|
||||
.filter_map(|pid| {
|
||||
let executable = std::fs::read_link(format!("/proc/{pid}/exe"))
|
||||
.ok()?
|
||||
.components()
|
||||
.next_back()?
|
||||
.as_os_str()
|
||||
.to_string_lossy()
|
||||
.into_owned();
|
||||
|
||||
if let Some(application) = running_apps
|
||||
.iter()
|
||||
.find(|running_app| running_app.executable_name == executable)
|
||||
{
|
||||
Some(Entry {
|
||||
name: application.name.clone(),
|
||||
icon: application.icon.clone(),
|
||||
secondary: String::new(),
|
||||
})
|
||||
} else {
|
||||
Some(Entry {
|
||||
name: executable,
|
||||
icon: None,
|
||||
secondary: pid.to_string(),
|
||||
})
|
||||
}
|
||||
})
|
||||
.collect(),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -325,14 +322,14 @@ fn all_gpus<S: AsRef<str>>(seat: S) -> io::Result<Vec<Gpu>> {
|
|||
enumerator.match_sysname("card[0-9]*")?;
|
||||
let mut gpus = enumerator
|
||||
.scan_devices()?
|
||||
.filter(|device| {
|
||||
device
|
||||
.filter_map(|device| {
|
||||
if device
|
||||
.property_value("ID_SEAT")
|
||||
.map(|x| x.to_os_string())
|
||||
.unwrap_or_else(|| OsString::from("seat0"))
|
||||
== *seat.as_ref()
|
||||
})
|
||||
.flat_map(|device| {
|
||||
.unwrap_or_else(|| OsStr::new("seat0"))
|
||||
!= seat.as_ref()
|
||||
{
|
||||
return None;
|
||||
}
|
||||
let path = device.devnode().map(PathBuf::from)?;
|
||||
let node = DrmNode::from_path(&path).ok()?;
|
||||
if !node.has_render() {
|
||||
|
|
@ -340,11 +337,8 @@ fn all_gpus<S: AsRef<str>>(seat: S) -> io::Result<Vec<Gpu>> {
|
|||
}
|
||||
|
||||
let boot_vga = if let Ok(Some(pci)) = device.parent_with_subsystem(Path::new("pci")) {
|
||||
if let Some(value) = pci.attribute_value("boot_vga") {
|
||||
value == "1"
|
||||
} else {
|
||||
false
|
||||
}
|
||||
pci.attribute_value("boot_vga")
|
||||
.is_some_and(|value| value == "1")
|
||||
} else {
|
||||
false
|
||||
};
|
||||
|
|
@ -352,10 +346,10 @@ fn all_gpus<S: AsRef<str>>(seat: S) -> io::Result<Vec<Gpu>> {
|
|||
let name = if let Some(parent) = device.parent() {
|
||||
let vendor = parent
|
||||
.property_value("SWITCHEROO_CONTROL_VENDOR_NAME")
|
||||
.or_else(|| parent.property_value("ID_VENDOR_FROM_DATABASE"));
|
||||
.or(parent.property_value("ID_VENDOR_FROM_DATABASE"));
|
||||
let name = parent
|
||||
.property_value("SWITCHEROO_CONTROL_PRODUCT_NAME")
|
||||
.or_else(|| parent.property_value("ID_MODEL_FROM_DATABASE"));
|
||||
.or(parent.property_value("ID_MODEL_FROM_DATABASE"));
|
||||
|
||||
if vendor.is_none() && name.is_none() {
|
||||
String::from("Unknown GPU")
|
||||
|
|
@ -374,7 +368,7 @@ fn all_gpus<S: AsRef<str>>(seat: S) -> io::Result<Vec<Gpu>> {
|
|||
let driver = loop {
|
||||
if let Some(dev) = device {
|
||||
if dev.driver().is_some() {
|
||||
break dev.driver().map(std::ffi::OsStr::to_os_string);
|
||||
break dev.driver().map(OsStr::to_os_string);
|
||||
} else {
|
||||
device = dev.parent();
|
||||
}
|
||||
|
|
@ -412,8 +406,8 @@ fn all_gpus<S: AsRef<str>>(seat: S) -> io::Result<Vec<Gpu>> {
|
|||
})
|
||||
})
|
||||
})
|
||||
.or_else(|| gpus.iter().position(|gpu| gpu.boot_vga))
|
||||
.or_else(|| (gpus.len() == 1).then_some(0))
|
||||
.or(gpus.iter().position(|gpu| gpu.boot_vga))
|
||||
.or((gpus.len() == 1).then_some(0))
|
||||
{
|
||||
gpus[primary_idx].primary = true;
|
||||
}
|
||||
|
|
@ -487,10 +481,10 @@ async fn start_listening(
|
|||
let name = if let Some(parent) = device.parent() {
|
||||
let vendor = parent
|
||||
.property_value("SWITCHEROO_CONTROL_VENDOR_NAME")
|
||||
.or_else(|| parent.property_value("ID_VENDOR_FROM_DATABASE"));
|
||||
.or(parent.property_value("ID_VENDOR_FROM_DATABASE"));
|
||||
let name = parent
|
||||
.property_value("SWITCHEROO_CONTROL_PRODUCT_NAME")
|
||||
.or_else(|| parent.property_value("ID_MODEL_FROM_DATABASE"));
|
||||
.or(parent.property_value("ID_MODEL_FROM_DATABASE"));
|
||||
|
||||
if vendor.is_none() && name.is_none() {
|
||||
String::from("Unknown GPU")
|
||||
|
|
@ -509,7 +503,7 @@ async fn start_listening(
|
|||
let driver = loop {
|
||||
if let Some(dev) = device {
|
||||
if dev.driver().is_some() {
|
||||
break dev.driver().map(std::ffi::OsStr::to_os_string);
|
||||
break dev.driver().map(OsStr::to_os_string);
|
||||
} else {
|
||||
device = dev.parent();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,6 +43,6 @@ pub fn localize() {
|
|||
let requested_languages = i18n_embed::DesktopLanguageRequester::requested_languages();
|
||||
|
||||
if let Err(error) = localizer.select(&requested_languages) {
|
||||
eprintln!("Error while loading language for App List {}", error);
|
||||
eprintln!("Error while loading language for App List {error}");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -116,7 +116,7 @@ impl cosmic::Application for CosmicBluetoothApplet {
|
|||
destroy_popup(p),
|
||||
cosmic::task::future(
|
||||
set_tick(Duration::from_secs(10))
|
||||
.map(|_| cosmic::Action::App(Message::Ignore)),
|
||||
.map(|()| cosmic::Action::App(Message::Ignore)),
|
||||
),
|
||||
]);
|
||||
} else {
|
||||
|
|
@ -133,7 +133,7 @@ impl cosmic::Application for CosmicBluetoothApplet {
|
|||
None,
|
||||
);
|
||||
|
||||
let tx = self.bluer_sender.as_ref().cloned();
|
||||
let tx = self.bluer_sender.clone();
|
||||
return Task::batch(vec![
|
||||
iced::Task::perform(
|
||||
async {
|
||||
|
|
@ -141,11 +141,11 @@ impl cosmic::Application for CosmicBluetoothApplet {
|
|||
let _ = tx.send(BluerRequest::StateUpdate).await;
|
||||
}
|
||||
},
|
||||
|_| cosmic::action::app(Message::Ignore),
|
||||
|()| cosmic::action::app(Message::Ignore),
|
||||
),
|
||||
get_popup(popup_settings),
|
||||
cosmic::task::future(set_tick(Duration::from_secs(3)))
|
||||
.map(|_: ()| cosmic::Action::App(Message::Ignore)),
|
||||
.map(|()| cosmic::Action::App(Message::Ignore)),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
@ -160,7 +160,7 @@ impl cosmic::Application for CosmicBluetoothApplet {
|
|||
err_msg,
|
||||
} => {
|
||||
if let Some(err_msg) = err_msg {
|
||||
eprintln!("bluetooth request error: {}", err_msg);
|
||||
eprintln!("bluetooth request error: {err_msg}");
|
||||
}
|
||||
if self.bluer_state.bluetooth_enabled != state.bluetooth_enabled {
|
||||
self.timeline
|
||||
|
|
@ -178,7 +178,7 @@ impl cosmic::Application for CosmicBluetoothApplet {
|
|||
BluerRequest::StateUpdate
|
||||
if self.popup.is_some() && self.bluer_sender.is_some() =>
|
||||
{
|
||||
let tx = self.bluer_sender.as_ref().cloned().unwrap();
|
||||
let tx = self.bluer_sender.clone().unwrap();
|
||||
tokio::spawn(async move {
|
||||
// sleep for a bit before requesting state update again
|
||||
tokio::time::sleep(Duration::from_millis(3000)).await;
|
||||
|
|
@ -186,7 +186,7 @@ impl cosmic::Application for CosmicBluetoothApplet {
|
|||
});
|
||||
}
|
||||
_ => {}
|
||||
};
|
||||
}
|
||||
}
|
||||
BluerEvent::Init { sender, state } => {
|
||||
self.bluer_sender.replace(sender);
|
||||
|
|
@ -270,7 +270,7 @@ impl cosmic::Application for CosmicBluetoothApplet {
|
|||
}
|
||||
_ => {} // TODO
|
||||
}
|
||||
if let Some(tx) = self.bluer_sender.as_mut().cloned() {
|
||||
if let Some(tx) = self.bluer_sender.clone() {
|
||||
tokio::spawn(async move {
|
||||
let _ = tx.send(r).await;
|
||||
});
|
||||
|
|
@ -295,7 +295,8 @@ impl cosmic::Application for CosmicBluetoothApplet {
|
|||
self.popup = None;
|
||||
}
|
||||
return cosmic::task::future(
|
||||
set_tick(Duration::from_secs(10)).map(|_| cosmic::Action::App(Message::Ignore)),
|
||||
set_tick(Duration::from_secs(10))
|
||||
.map(|()| cosmic::Action::App(Message::Ignore)),
|
||||
);
|
||||
}
|
||||
Message::OpenSettings => {
|
||||
|
|
@ -305,7 +306,7 @@ impl cosmic::Application for CosmicBluetoothApplet {
|
|||
app_id: Self::APP_ID.to_string(),
|
||||
exec,
|
||||
});
|
||||
};
|
||||
}
|
||||
}
|
||||
Message::Token(u) => match u {
|
||||
TokenUpdate::Init(tx) => {
|
||||
|
|
@ -347,7 +348,7 @@ impl cosmic::Application for CosmicBluetoothApplet {
|
|||
Task::none()
|
||||
}
|
||||
|
||||
fn view(&self) -> Element<Message> {
|
||||
fn view(&self) -> Element<'_, Message> {
|
||||
self.core
|
||||
.applet
|
||||
.icon_button(&self.icon_name)
|
||||
|
|
@ -355,7 +356,7 @@ impl cosmic::Application for CosmicBluetoothApplet {
|
|||
.into()
|
||||
}
|
||||
|
||||
fn view_window(&self, _id: window::Id) -> Element<Message> {
|
||||
fn view_window(&self, _id: window::Id) -> Element<'_, Message> {
|
||||
let Spacing {
|
||||
space_xxs, space_s, ..
|
||||
} = theme::active().cosmic().spacing;
|
||||
|
|
@ -363,10 +364,9 @@ impl cosmic::Application for CosmicBluetoothApplet {
|
|||
let mut known_bluetooth = vec![];
|
||||
// PERF: This should be pre-filtered in an update.
|
||||
for dev in self.bluer_state.devices.iter().filter(|d| {
|
||||
!self
|
||||
.request_confirmation
|
||||
self.request_confirmation
|
||||
.as_ref()
|
||||
.map_or(false, |(dev, _, _)| d.address == dev.address)
|
||||
.is_none_or(|(dev, _, _)| d.address != dev.address)
|
||||
}) {
|
||||
let mut row = row![
|
||||
icon::from_name(dev.icon).size(16).symbolic(true),
|
||||
|
|
@ -380,13 +380,13 @@ impl cosmic::Application for CosmicBluetoothApplet {
|
|||
|
||||
if let Some(battery) = dev.battery_percent {
|
||||
let icon = match battery {
|
||||
b if b >= 20 && b < 40 => "battery-low",
|
||||
b if (20..40).contains(&b) => "battery-low",
|
||||
b if b < 20 => "battery-caution",
|
||||
_ => "battery",
|
||||
};
|
||||
let status = row!(
|
||||
icon::from_name(icon).symbolic(true).size(14),
|
||||
text::body(format!("{}%", battery))
|
||||
text::body(format!("{battery}%"))
|
||||
)
|
||||
.align_y(Alignment::Center)
|
||||
.spacing(2)
|
||||
|
|
@ -416,7 +416,7 @@ impl cosmic::Application for CosmicBluetoothApplet {
|
|||
);
|
||||
}
|
||||
BluerDeviceStatus::Disconnected | BluerDeviceStatus::Pairing => continue,
|
||||
};
|
||||
}
|
||||
|
||||
known_bluetooth.push(
|
||||
menu_button(row)
|
||||
|
|
@ -529,10 +529,10 @@ impl cosmic::Application for CosmicBluetoothApplet {
|
|||
matches!(
|
||||
d.status,
|
||||
BluerDeviceStatus::Disconnected | BluerDeviceStatus::Pairing
|
||||
) && !self
|
||||
) && self
|
||||
.request_confirmation
|
||||
.as_ref()
|
||||
.map_or(false, |(dev, _, _)| d.address == dev.address)
|
||||
.is_none_or(|(dev, _, _)| d.address != dev.address)
|
||||
&& (d.has_name() || d.is_known_device_type())
|
||||
}) {
|
||||
let row = row![
|
||||
|
|
|
|||
|
|
@ -95,7 +95,7 @@ pub fn bluetooth_subscription<I: 'static + Hash + Copy + Send + Sync + Debug>(
|
|||
}
|
||||
|
||||
retry_count = retry_count.saturating_add(1);
|
||||
_ = tokio::time::sleep(Duration::from_millis(
|
||||
() = tokio::time::sleep(Duration::from_millis(
|
||||
2_u64.saturating_pow(retry_count).min(68719476734),
|
||||
))
|
||||
.await;
|
||||
|
|
@ -156,7 +156,7 @@ pub fn bluetooth_subscription<I: 'static + Hash + Copy + Send + Sync + Debug>(
|
|||
event_handler(event).await;
|
||||
// Consume any additional available events.
|
||||
let mut count = 0;
|
||||
while let Some(event) = session_rx.try_recv().ok() {
|
||||
while let Ok(event) = session_rx.try_recv() {
|
||||
event_handler(event).await;
|
||||
count += 1;
|
||||
if count == 100 {
|
||||
|
|
@ -165,7 +165,7 @@ pub fn bluetooth_subscription<I: 'static + Hash + Copy + Send + Sync + Debug>(
|
|||
}
|
||||
} else {
|
||||
break;
|
||||
};
|
||||
}
|
||||
|
||||
session_state.rx = Some(session_rx);
|
||||
interval.tick().await;
|
||||
|
|
@ -271,10 +271,9 @@ impl BluerDevice {
|
|||
#[inline(never)]
|
||||
pub async fn from_device(device: &bluer::Device) -> Self {
|
||||
let (mut name, is_paired, is_trusted, is_connected, battery_percent, icon) = futures::join!(
|
||||
device.name().map(|res| res
|
||||
.ok()
|
||||
.flatten()
|
||||
.unwrap_or_else(|| device.address().to_string())),
|
||||
device
|
||||
.name()
|
||||
.map(|res| res.ok().flatten().unwrap_or(device.address().to_string())),
|
||||
device.is_paired().map(Result::unwrap_or_default),
|
||||
device.is_trusted().map(Result::unwrap_or_default),
|
||||
device.is_connected().map(Result::unwrap_or_default),
|
||||
|
|
@ -286,7 +285,7 @@ impl BluerDevice {
|
|||
|
||||
if name.is_empty() {
|
||||
name = device.address().to_string();
|
||||
};
|
||||
}
|
||||
|
||||
let status = if is_connected {
|
||||
BluerDeviceStatus::Connected
|
||||
|
|
@ -385,9 +384,8 @@ impl BluerSessionState {
|
|||
let agent_clone = adapter_clone_1.clone();
|
||||
let tx_clone = tx_clone_1.clone();
|
||||
Box::pin(async move {
|
||||
let device = match agent_clone.device(req.device) {
|
||||
Ok(d) => d,
|
||||
Err(_) => return Err(bluer::agent::ReqError::Rejected),
|
||||
let Ok(device) = agent_clone.device(req.device) else {
|
||||
return Err(bluer::agent::ReqError::Rejected);
|
||||
};
|
||||
let _ = tx_clone
|
||||
.send(BluerSessionEvent::AgentEvent(
|
||||
|
|
@ -397,16 +395,15 @@ impl BluerSessionState {
|
|||
))
|
||||
.await;
|
||||
let pin_code = fastrand::u32(0..999999);
|
||||
Ok(format!("{:06}", pin_code))
|
||||
Ok(format!("{pin_code:06}"))
|
||||
})
|
||||
})),
|
||||
display_pin_code: Some(Box::new(move |req| {
|
||||
let agent_clone = adapter_clone_2.clone();
|
||||
let tx_clone = tx_clone_2.clone();
|
||||
Box::pin(async move {
|
||||
let device = match agent_clone.device(req.device) {
|
||||
Ok(d) => d,
|
||||
Err(_) => return Err(bluer::agent::ReqError::Rejected),
|
||||
let Ok(device) = agent_clone.device(req.device) else {
|
||||
return Err(bluer::agent::ReqError::Rejected);
|
||||
};
|
||||
let _ = tx_clone
|
||||
.send(BluerSessionEvent::AgentEvent(
|
||||
|
|
@ -424,9 +421,8 @@ impl BluerSessionState {
|
|||
let agent_clone = adapter_clone_3.clone();
|
||||
let tx_clone = tx_clone_3.clone();
|
||||
Box::pin(async move {
|
||||
let device = match agent_clone.device(req.device) {
|
||||
Ok(d) => d,
|
||||
Err(_) => return Err(bluer::agent::ReqError::Rejected),
|
||||
let Ok(device) = agent_clone.device(req.device) else {
|
||||
return Err(bluer::agent::ReqError::Rejected);
|
||||
};
|
||||
let _ = tx_clone
|
||||
.send(BluerSessionEvent::AgentEvent(
|
||||
|
|
@ -443,9 +439,8 @@ impl BluerSessionState {
|
|||
let agent_clone = adapter_clone_4.clone();
|
||||
let tx_clone = tx_clone_4.clone();
|
||||
Box::pin(async move {
|
||||
let device = match agent_clone.device(req.device) {
|
||||
Ok(d) => d,
|
||||
Err(_) => return Err(bluer::agent::ReqError::Rejected),
|
||||
let Ok(device) = agent_clone.device(req.device) else {
|
||||
return Err(bluer::agent::ReqError::Rejected);
|
||||
};
|
||||
let _ = tx_clone
|
||||
.send(BluerSessionEvent::AgentEvent(
|
||||
|
|
@ -462,9 +457,8 @@ impl BluerSessionState {
|
|||
let agent_clone = adapter_clone_5.clone();
|
||||
let tx_clone = tx_clone_5.clone();
|
||||
Box::pin(async move {
|
||||
let device = match agent_clone.device(req.device) {
|
||||
Ok(d) => d,
|
||||
Err(_) => return Err(bluer::agent::ReqError::Rejected),
|
||||
let Ok(device) = agent_clone.device(req.device) else {
|
||||
return Err(bluer::agent::ReqError::Rejected);
|
||||
};
|
||||
let (tx, mut rx) = channel(1);
|
||||
let _ = tx_clone
|
||||
|
|
@ -487,9 +481,8 @@ impl BluerSessionState {
|
|||
let agent_clone = adapter_clone_6.clone();
|
||||
let tx_clone = tx_clone_6.clone();
|
||||
Box::pin(async move {
|
||||
let device = match agent_clone.device(req.device) {
|
||||
Ok(d) => d,
|
||||
Err(_) => return Err(bluer::agent::ReqError::Rejected),
|
||||
let Ok(device) = agent_clone.device(req.device) else {
|
||||
return Err(bluer::agent::ReqError::Rejected);
|
||||
};
|
||||
let (tx, mut rx) = channel(1);
|
||||
let _ = tx_clone
|
||||
|
|
@ -511,9 +504,8 @@ impl BluerSessionState {
|
|||
let agent_clone = adapter_clone_7.clone();
|
||||
let tx_clone = tx_clone_7.clone();
|
||||
Box::pin(async move {
|
||||
let device = match agent_clone.device(req.device) {
|
||||
Ok(d) => d,
|
||||
Err(_) => return Err(bluer::agent::ReqError::Rejected),
|
||||
let Ok(device) = agent_clone.device(req.device) else {
|
||||
return Err(bluer::agent::ReqError::Rejected);
|
||||
};
|
||||
let (tx, mut rx) = channel(1);
|
||||
// TODO better describe the service to the user
|
||||
|
|
@ -614,16 +606,14 @@ impl BluerSessionState {
|
|||
let mut new_devices = Vec::new();
|
||||
let mut interval = tokio::time::interval(Duration::from_secs(10));
|
||||
interval.set_missed_tick_behavior(tokio::time::MissedTickBehavior::Skip);
|
||||
let mut change_stream =
|
||||
match adapter_clone.discover_devices_with_changes().await {
|
||||
Ok(stream) => stream,
|
||||
Err(_) => {
|
||||
tick(&mut interval).await;
|
||||
return;
|
||||
}
|
||||
};
|
||||
let Ok(mut change_stream) =
|
||||
adapter_clone.discover_devices_with_changes().await
|
||||
else {
|
||||
tick(&mut interval).await;
|
||||
return;
|
||||
};
|
||||
|
||||
while let Some(_) = change_stream.next().await {
|
||||
while change_stream.next().await.is_some() {
|
||||
new_devices = build_device_list(new_devices, &adapter_clone).await;
|
||||
for d in new_devices
|
||||
.iter()
|
||||
|
|
@ -679,7 +669,7 @@ impl BluerSessionState {
|
|||
match &req_clone {
|
||||
BluerRequest::SetBluetoothEnabled(enabled) => {
|
||||
if let Err(e) = adapter_clone.set_powered(*enabled).await {
|
||||
tracing::error!("Failed to power off bluetooth adapter. {e:?}")
|
||||
tracing::error!("Failed to power off bluetooth adapter. {e:?}");
|
||||
}
|
||||
|
||||
// rfkill will be persisted after reboot
|
||||
|
|
@ -695,8 +685,8 @@ impl BluerSessionState {
|
|||
.ok()
|
||||
.and_then(|o| {
|
||||
let lines = String::from_utf8(o.stdout).ok()?;
|
||||
lines.split("\n").into_iter().find_map(|row| {
|
||||
let (id, cname) = row.trim().split_once(" ")?;
|
||||
lines.split('\n').into_iter().find_map(|row| {
|
||||
let (id, cname) = row.trim().split_once(' ')?;
|
||||
(name == cname).then_some(id.to_string())
|
||||
})
|
||||
})
|
||||
|
|
@ -768,7 +758,7 @@ impl BluerSessionState {
|
|||
}
|
||||
}
|
||||
BluerRequest::StateUpdate => {}
|
||||
};
|
||||
}
|
||||
|
||||
let _ = tx_clone
|
||||
.send(BluerSessionEvent::RequestResponse {
|
||||
|
|
@ -820,7 +810,7 @@ async fn build_device_list(mut devices: Vec<BluerDevice>, adapter: &Adapter) ->
|
|||
.collect::<FuturesUnordered<_>>();
|
||||
|
||||
while let Some(device) = device_stream.next().await {
|
||||
devices.push(device)
|
||||
devices.push(device);
|
||||
}
|
||||
|
||||
devices.sort();
|
||||
|
|
|
|||
|
|
@ -44,6 +44,6 @@ pub fn localize() {
|
|||
let requested_languages = i18n_embed::DesktopLanguageRequester::requested_languages();
|
||||
|
||||
if let Err(error) = localizer.select(&requested_languages) {
|
||||
eprintln!("Error while loading language for App List {}", error);
|
||||
eprintln!("Error while loading language for App List {error}");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -199,7 +199,7 @@ impl cosmic::Application for Window {
|
|||
Task::none()
|
||||
}
|
||||
|
||||
fn view(&self) -> Element<Self::Message> {
|
||||
fn view(&self) -> Element<'_, Self::Message> {
|
||||
let input_source_text = self.core.applet.text(
|
||||
self.active_layouts
|
||||
.first()
|
||||
|
|
@ -233,7 +233,7 @@ impl cosmic::Application for Window {
|
|||
.into()
|
||||
}
|
||||
|
||||
fn view_window(&self, _id: Id) -> Element<Self::Message> {
|
||||
fn view_window(&self, _id: Id) -> Element<'_, Self::Message> {
|
||||
let Spacing {
|
||||
space_xxs, space_s, ..
|
||||
} = theme::active().cosmic().spacing;
|
||||
|
|
@ -294,7 +294,7 @@ impl Window {
|
|||
.chain(std::iter::repeat(""));
|
||||
|
||||
'outer: for (layout, variant) in layouts.zip(variants) {
|
||||
println!("{} : {}", layout, variant);
|
||||
println!("{layout} : {variant}");
|
||||
for xkb_layout in &self.layouts {
|
||||
if layout != xkb_layout.name() {
|
||||
continue;
|
||||
|
|
|
|||
|
|
@ -88,25 +88,23 @@ impl Minimize {
|
|||
fn find_new_desktop_entry(&mut self, appid: &str) -> fde::DesktopEntry {
|
||||
let unicase_appid = fde::unicase::Ascii::new(appid);
|
||||
|
||||
let de = match fde::find_app_by_id(&self.desktop_entries, unicase_appid) {
|
||||
Some(de) => de,
|
||||
None => {
|
||||
// Update desktop entries in case it was not found.
|
||||
self.update_desktop_entries();
|
||||
match fde::find_app_by_id(&self.desktop_entries, unicase_appid) {
|
||||
Some(appid) => appid,
|
||||
None => {
|
||||
tracing::warn!(appid, "could not find desktop entry for app");
|
||||
let mut entry = fde::DesktopEntry {
|
||||
appid: appid.to_owned(),
|
||||
groups: Default::default(),
|
||||
path: Default::default(),
|
||||
ubuntu_gettext_domain: None,
|
||||
};
|
||||
entry.add_desktop_entry("Name".to_string(), appid.to_owned());
|
||||
return entry;
|
||||
}
|
||||
}
|
||||
let de = if let Some(de) = fde::find_app_by_id(&self.desktop_entries, unicase_appid) {
|
||||
de
|
||||
} else {
|
||||
// Update desktop entries in case it was not found.
|
||||
self.update_desktop_entries();
|
||||
if let Some(appid) = fde::find_app_by_id(&self.desktop_entries, unicase_appid) {
|
||||
appid
|
||||
} else {
|
||||
tracing::warn!(appid, "could not find desktop entry for app");
|
||||
let mut entry = fde::DesktopEntry {
|
||||
appid: appid.to_owned(),
|
||||
groups: Default::default(),
|
||||
path: Default::default(),
|
||||
ubuntu_gettext_domain: None,
|
||||
};
|
||||
entry.add_desktop_entry("Name".to_string(), appid.to_owned());
|
||||
return entry;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -186,7 +184,7 @@ impl cosmic::Application for Minimize {
|
|||
.desktop_entry
|
||||
.icon()
|
||||
.unwrap_or(&apps[pos].desktop_entry.appid),
|
||||
)
|
||||
);
|
||||
}
|
||||
apps[pos].toplevel_info = toplevel_info;
|
||||
} else {
|
||||
|
|
@ -278,7 +276,7 @@ impl cosmic::Application for Minimize {
|
|||
cosmic::app::Action::Surface(a),
|
||||
));
|
||||
}
|
||||
};
|
||||
}
|
||||
Task::none()
|
||||
}
|
||||
|
||||
|
|
@ -286,17 +284,14 @@ impl cosmic::Application for Minimize {
|
|||
wayland_subscription::wayland_subscription().map(Message::Wayland)
|
||||
}
|
||||
|
||||
fn view(&self) -> Element<Self::Message> {
|
||||
let max_icon_count = self
|
||||
.max_icon_count()
|
||||
.map(|n| {
|
||||
if n < self.apps.len() {
|
||||
n - 1
|
||||
} else {
|
||||
self.apps.len()
|
||||
}
|
||||
})
|
||||
.unwrap_or(self.apps.len());
|
||||
fn view(&self) -> Element<'_, Self::Message> {
|
||||
let max_icon_count = self.max_icon_count().map_or(self.apps.len(), |n| {
|
||||
if n < self.apps.len() {
|
||||
n - 1
|
||||
} else {
|
||||
self.apps.len()
|
||||
}
|
||||
});
|
||||
let (width, _) = self.core.applet.suggested_size(false);
|
||||
let padding = self.core.applet.suggested_padding(false);
|
||||
let theme = self.core.system_theme().cosmic();
|
||||
|
|
@ -339,7 +334,7 @@ impl cosmic::Application for Minimize {
|
|||
|
||||
// TODO optional dividers on ends if detects app list neighbor
|
||||
// not sure the best way to tell if there is an adjacent app-list
|
||||
let icon_buttons = icon_buttons.chain(overflow_btn.into_iter());
|
||||
let icon_buttons = icon_buttons.chain(overflow_btn);
|
||||
let content: Element<_> = if matches!(
|
||||
self.core.applet.anchor,
|
||||
PanelAnchor::Top | PanelAnchor::Bottom
|
||||
|
|
@ -384,17 +379,14 @@ impl cosmic::Application for Minimize {
|
|||
.into()
|
||||
}
|
||||
|
||||
fn view_window(&self, _id: window::Id) -> Element<Self::Message> {
|
||||
let max_icon_count = self
|
||||
.max_icon_count()
|
||||
.map(|n| {
|
||||
if n < self.apps.len() {
|
||||
n - 1
|
||||
} else {
|
||||
self.apps.len()
|
||||
}
|
||||
})
|
||||
.unwrap_or(self.apps.len());
|
||||
fn view_window(&self, _id: window::Id) -> Element<'_, Self::Message> {
|
||||
let max_icon_count = self.max_icon_count().map_or(self.apps.len(), |n| {
|
||||
if n < self.apps.len() {
|
||||
n - 1
|
||||
} else {
|
||||
self.apps.len()
|
||||
}
|
||||
});
|
||||
let (width, _) = self.core.applet.suggested_size(false);
|
||||
let padding = self.core.applet.suggested_padding(false);
|
||||
let theme = self.core.system_theme().cosmic();
|
||||
|
|
|
|||
|
|
@ -43,6 +43,6 @@ pub fn localize() {
|
|||
let requested_languages = i18n_embed::DesktopLanguageRequester::requested_languages();
|
||||
|
||||
if let Err(error) = localizer.select(&requested_languages) {
|
||||
eprintln!("Error while loading language for Minimize {}", error);
|
||||
eprintln!("Error while loading language for Minimize {error}");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -88,7 +88,10 @@ impl Session {
|
|||
self.condvar.notify_all();
|
||||
}
|
||||
|
||||
fn wait_while<F: FnMut(&SessionInner) -> bool>(&self, mut f: F) -> MutexGuard<SessionInner> {
|
||||
fn wait_while<F: FnMut(&SessionInner) -> bool>(
|
||||
&self,
|
||||
mut f: F,
|
||||
) -> MutexGuard<'_, SessionInner> {
|
||||
self.condvar
|
||||
.wait_while(self.inner.lock().unwrap(), |data| f(data))
|
||||
.unwrap()
|
||||
|
|
@ -150,7 +153,7 @@ impl CaptureData {
|
|||
&self.qh,
|
||||
SessionData {
|
||||
session: session.clone(),
|
||||
session_data: Default::default(),
|
||||
session_data: ScreencopySessionData::default(),
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
|
|
@ -168,22 +171,19 @@ impl CaptureData {
|
|||
}
|
||||
|
||||
// XXX
|
||||
if !formats
|
||||
.shm_formats
|
||||
.contains(&wl_shm::Format::Abgr8888.into())
|
||||
{
|
||||
if !formats.shm_formats.contains(&wl_shm::Format::Abgr8888) {
|
||||
tracing::error!("No suitable buffer format found");
|
||||
tracing::warn!("Available formats: {:#?}", formats);
|
||||
return None;
|
||||
};
|
||||
}
|
||||
|
||||
let buf_len = width * height * 4;
|
||||
if let Some(len) = len {
|
||||
if len != buf_len {
|
||||
return None;
|
||||
}
|
||||
} else if let Err(_err) = rustix::fs::ftruncate(&fd, buf_len as _) {
|
||||
};
|
||||
} else if let Err(_err) = rustix::fs::ftruncate(&fd, buf_len.into()) {
|
||||
}
|
||||
let pool = self
|
||||
.wl_shm
|
||||
.create_pool(fd.as_fd(), buf_len as i32, &self.qh, ());
|
||||
|
|
@ -202,7 +202,7 @@ impl CaptureData {
|
|||
&[],
|
||||
&self.qh,
|
||||
FrameData {
|
||||
frame_data: Default::default(),
|
||||
frame_data: ScreencopyFrameData::default(),
|
||||
session: capture_session.clone(),
|
||||
},
|
||||
);
|
||||
|
|
@ -237,7 +237,7 @@ impl<T: AsFd> ShmImage<T> {
|
|||
pub fn image(&self) -> anyhow::Result<image::RgbaImage> {
|
||||
let mmap = unsafe { memmap2::Mmap::map(&self.fd.as_fd())? };
|
||||
image::RgbaImage::from_raw(self.width, self.height, mmap.to_vec())
|
||||
.ok_or_else(|| anyhow::anyhow!("ShmImage had incorrect size"))
|
||||
.ok_or(anyhow::anyhow!("ShmImage had incorrect size"))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -297,7 +297,7 @@ impl AppData {
|
|||
handle: &ExtForeignToplevelHandleV1,
|
||||
) -> Option<ZcosmicToplevelHandleV1> {
|
||||
self.toplevel_info_state
|
||||
.info(&handle)?
|
||||
.info(handle)?
|
||||
.cosmic_toplevel
|
||||
.clone()
|
||||
}
|
||||
|
|
@ -311,9 +311,7 @@ impl AppData {
|
|||
capturer: self.screencopy_state.capturer().clone(),
|
||||
};
|
||||
std::thread::spawn(move || {
|
||||
use std::ffi::CStr;
|
||||
let name =
|
||||
unsafe { CStr::from_bytes_with_nul_unchecked(b"minimize-applet-screencopy\0") };
|
||||
let name = c"minimize-applet-screencopy";
|
||||
let Ok(fd) = rustix::fs::memfd_create(name, rustix::fs::MemfdFlags::CLOEXEC) else {
|
||||
tracing::error!("Failed to get fd for capture");
|
||||
return;
|
||||
|
|
@ -347,7 +345,7 @@ impl AppData {
|
|||
tx.send(WaylandUpdate::Image(handle, WaylandImage::new(img))),
|
||||
) {
|
||||
tracing::error!("Failed to send image event to subscription {err:?}");
|
||||
};
|
||||
}
|
||||
} else {
|
||||
tracing::error!("Failed to capture image");
|
||||
}
|
||||
|
|
@ -448,7 +446,7 @@ pub(crate) fn wayland_handler(
|
|||
.expect("Failed to insert wayland source.");
|
||||
|
||||
if handle
|
||||
.insert_source(rx, |event, _, state| match event {
|
||||
.insert_source(rx, |event, (), state| match event {
|
||||
calloop::channel::Event::Msg(req) => match req {
|
||||
WaylandRequest::Toplevel(req) => match req {
|
||||
ToplevelRequest::Activate(handle) => {
|
||||
|
|
@ -552,7 +550,7 @@ impl Dispatch<wl_shm_pool::WlShmPool, ()> for AppData {
|
|||
_app_data: &mut Self,
|
||||
_buffer: &wl_shm_pool::WlShmPool,
|
||||
_event: wl_shm_pool::Event,
|
||||
_: &(),
|
||||
(): &(),
|
||||
_: &Connection,
|
||||
_qh: &QueueHandle<Self>,
|
||||
) {
|
||||
|
|
@ -564,7 +562,7 @@ impl Dispatch<wl_buffer::WlBuffer, ()> for AppData {
|
|||
_app_data: &mut Self,
|
||||
_buffer: &wl_buffer::WlBuffer,
|
||||
_event: wl_buffer::Event,
|
||||
_: &(),
|
||||
(): &(),
|
||||
_: &Connection,
|
||||
_qh: &QueueHandle<Self>,
|
||||
) {
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ pub struct WindowImage<'a, Msg> {
|
|||
icon: Element<'a, Msg>,
|
||||
}
|
||||
|
||||
impl<'a, Msg> WindowImage<'a, Msg>
|
||||
impl<Msg> WindowImage<'_, Msg>
|
||||
where
|
||||
Msg: 'static + Clone,
|
||||
{
|
||||
|
|
@ -81,13 +81,13 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, Msg> Widget<Msg, cosmic::Theme, cosmic::Renderer> for WindowImage<'a, Msg> {
|
||||
impl<Msg> Widget<Msg, cosmic::Theme, cosmic::Renderer> for WindowImage<'_, Msg> {
|
||||
fn children(&self) -> Vec<cosmic::iced_core::widget::Tree> {
|
||||
vec![Tree::new(&self.image_button), Tree::new(&self.icon)]
|
||||
}
|
||||
|
||||
fn diff(&mut self, tree: &mut cosmic::iced_core::widget::Tree) {
|
||||
tree.diff_children(&mut [&mut self.image_button, &mut self.icon])
|
||||
tree.diff_children(&mut [&mut self.image_button, &mut self.icon]);
|
||||
}
|
||||
|
||||
fn overlay<'b>(
|
||||
|
|
|
|||
|
|
@ -127,9 +127,8 @@ impl CosmicNetworkApplet {
|
|||
self.update_togglers(&new_state);
|
||||
// check for failed conns that can be reset
|
||||
for new_s in &mut new_state.active_conns {
|
||||
let state = match new_s {
|
||||
ActiveConnectionInfo::WiFi { state, .. } => state,
|
||||
_ => continue,
|
||||
let ActiveConnectionInfo::WiFi { state, .. } = new_s else {
|
||||
continue;
|
||||
};
|
||||
|
||||
if matches!(state, ActiveConnectionState::Activated) {
|
||||
|
|
@ -180,7 +179,7 @@ impl CosmicNetworkApplet {
|
|||
_ => icon_name,
|
||||
},
|
||||
)
|
||||
.to_string()
|
||||
.to_string();
|
||||
}
|
||||
|
||||
fn update_togglers(&mut self, state: &NetworkManagerState) {
|
||||
|
|
@ -194,7 +193,7 @@ impl CosmicNetworkApplet {
|
|||
chain::Toggler::off(WIFI.clone(), 1.)
|
||||
};
|
||||
timeline.set_chain(chain);
|
||||
};
|
||||
}
|
||||
|
||||
if state.airplane_mode != self.nm_state.airplane_mode {
|
||||
changed = true;
|
||||
|
|
@ -204,7 +203,7 @@ impl CosmicNetworkApplet {
|
|||
chain::Toggler::off(AIRPLANE_MODE.clone(), 1.)
|
||||
};
|
||||
timeline.set_chain(chain);
|
||||
};
|
||||
}
|
||||
if changed {
|
||||
timeline.start();
|
||||
}
|
||||
|
|
@ -344,21 +343,15 @@ impl cosmic::Application for CosmicNetworkApplet {
|
|||
let conn_match = self
|
||||
.new_connection
|
||||
.as_ref()
|
||||
.map(|c| c.ssid() == ssid && c.hw_address() == *hw_address)
|
||||
.unwrap_or_default();
|
||||
.is_some_and(|c| c.ssid() == ssid && c.hw_address() == *hw_address);
|
||||
|
||||
if conn_match && success {
|
||||
if let Some(s) = state
|
||||
if let Some(ActiveConnectionInfo::WiFi { state, .. }) = state
|
||||
.active_conns
|
||||
.iter_mut()
|
||||
.find(|ap| &ap.name() == ssid && ap.hw_address() == *hw_address)
|
||||
{
|
||||
match s {
|
||||
ActiveConnectionInfo::WiFi { state, .. } => {
|
||||
*state = ActiveConnectionState::Activated;
|
||||
}
|
||||
_ => {}
|
||||
};
|
||||
*state = ActiveConnectionState::Activated;
|
||||
}
|
||||
self.failed_known_ssids.remove(ssid);
|
||||
self.new_connection = None;
|
||||
|
|
@ -401,7 +394,7 @@ impl cosmic::Application for CosmicNetworkApplet {
|
|||
} else if self
|
||||
.new_connection
|
||||
.as_ref()
|
||||
.map(|c| c.ssid()).is_some_and(|ssid| {
|
||||
.map(NewConnectionState::ssid).is_some_and(|ssid| {
|
||||
state.active_conns.iter().any(|c|
|
||||
matches!(c, ActiveConnectionInfo::WiFi { name, state: ActiveConnectionState::Activated, .. } if ssid == name)
|
||||
)
|
||||
|
|
@ -423,9 +416,7 @@ impl cosmic::Application for CosmicNetworkApplet {
|
|||
}
|
||||
},
|
||||
Message::SelectWirelessAccessPoint(access_point) => {
|
||||
let tx = if let Some(tx) = self.nm_sender.as_ref() {
|
||||
tx
|
||||
} else {
|
||||
let Some(tx) = self.nm_sender.as_ref() else {
|
||||
return Task::none();
|
||||
};
|
||||
|
||||
|
|
@ -467,9 +458,7 @@ impl cosmic::Application for CosmicNetworkApplet {
|
|||
}
|
||||
Message::SubmitPassword => {
|
||||
// save password
|
||||
let tx = if let Some(tx) = self.nm_sender.as_ref() {
|
||||
tx
|
||||
} else {
|
||||
let Some(tx) = self.nm_sender.as_ref() else {
|
||||
return Task::none();
|
||||
};
|
||||
|
||||
|
|
@ -485,12 +474,12 @@ impl cosmic::Application for CosmicNetworkApplet {
|
|||
let _ = tx.unbounded_send(NetworkManagerRequest::Authenticate {
|
||||
ssid: access_point.ssid.clone(),
|
||||
identity: is_enterprise.then(|| identity.clone()),
|
||||
password: password,
|
||||
password,
|
||||
hw_address: access_point.hw_address,
|
||||
});
|
||||
self.new_connection
|
||||
.replace(NewConnectionState::Waiting(access_point));
|
||||
};
|
||||
}
|
||||
}
|
||||
Message::ActivateKnownWifi(ssid, hw_address) => {
|
||||
let mut network_type = NetworkType::Open;
|
||||
|
|
@ -616,7 +605,7 @@ impl cosmic::Application for CosmicNetworkApplet {
|
|||
Task::none()
|
||||
}
|
||||
|
||||
fn view(&self) -> Element<Message> {
|
||||
fn view(&self) -> Element<'_, Message> {
|
||||
self.core
|
||||
.applet
|
||||
.icon_button(&self.icon_name)
|
||||
|
|
@ -624,7 +613,7 @@ impl cosmic::Application for CosmicNetworkApplet {
|
|||
.into()
|
||||
}
|
||||
|
||||
fn view_window(&self, _id: window::Id) -> Element<Message> {
|
||||
fn view_window(&self, _id: window::Id) -> Element<'_, Message> {
|
||||
let Spacing {
|
||||
space_xxs, space_s, ..
|
||||
} = theme::active().cosmic().spacing;
|
||||
|
|
@ -744,7 +733,7 @@ impl cosmic::Application for CosmicNetworkApplet {
|
|||
.into(),
|
||||
),
|
||||
_ => {}
|
||||
};
|
||||
}
|
||||
if self.failed_known_ssids.contains(name) {
|
||||
btn_content.push(
|
||||
cosmic::widget::button::icon(
|
||||
|
|
@ -753,7 +742,7 @@ impl cosmic::Application for CosmicNetworkApplet {
|
|||
.icon_size(16)
|
||||
.on_press(Message::ResetFailedKnownSsid(name.clone(), *hw_address))
|
||||
.into(),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
known_wifi.push(Element::from(
|
||||
|
|
@ -768,7 +757,7 @@ impl cosmic::Application for CosmicNetworkApplet {
|
|||
.align_x(Alignment::Center),
|
||||
));
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
let mut content = if let Some(hw_device_to_show) = self.hw_device_to_show {
|
||||
|
|
@ -899,7 +888,7 @@ impl cosmic::Application for CosmicNetworkApplet {
|
|||
.align_y(Alignment::Center)
|
||||
.spacing(8),
|
||||
)
|
||||
.on_press(Message::OpenHwDevice(Some(hw_device.clone()))),
|
||||
.on_press(Message::OpenHwDevice(Some(hw_device))),
|
||||
));
|
||||
}
|
||||
|
||||
|
|
@ -955,7 +944,7 @@ impl cosmic::Application for CosmicNetworkApplet {
|
|||
known.hw_address,
|
||||
))
|
||||
.into(),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
let mut btn = menu_button(
|
||||
|
|
|
|||
|
|
@ -42,6 +42,6 @@ pub fn localize() {
|
|||
let requested_languages = i18n_embed::DesktopLanguageRequester::requested_languages();
|
||||
|
||||
if let Err(error) = localizer.select(&requested_languages) {
|
||||
eprintln!("Error while loading language for App List {}", error);
|
||||
eprintln!("Error while loading language for App List {error}");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ async fn start_listening(
|
|||
let mut active_conns_changed = network_manager.receive_active_connections_changed().await;
|
||||
active_conns_changed.next().await;
|
||||
|
||||
while let (Some(_change), _) = tokio::join!(
|
||||
while let (Some(_change), ()) = tokio::join!(
|
||||
active_conns_changed.next(),
|
||||
tokio::time::sleep(tokio::time::Duration::from_secs(1))
|
||||
) {
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ pub async fn handle_wireless_device(
|
|||
if let Some(t) = scan_changed.next().await {
|
||||
if let Ok(-1) = t.get().await {
|
||||
eprintln!("scan errored");
|
||||
return Ok(Default::default());
|
||||
return Ok(Vec::new());
|
||||
}
|
||||
}
|
||||
let access_points = device.get_access_points().await?;
|
||||
|
|
@ -33,8 +33,7 @@ pub async fn handle_wireless_device(
|
|||
.await
|
||||
.and_then(|dev| dev.cached_state())
|
||||
.unwrap_or_default()
|
||||
.map(|s| s.into())
|
||||
.unwrap_or_else(|| DeviceState::Unknown);
|
||||
.map_or(DeviceState::Unknown, |s| s.into());
|
||||
// Sort by strength and remove duplicates
|
||||
let mut aps = HashMap::<String, AccessPoint>::new();
|
||||
for ap in access_points {
|
||||
|
|
@ -45,7 +44,7 @@ pub async fn handle_wireless_device(
|
|||
if access_point.strength > strength {
|
||||
continue;
|
||||
}
|
||||
};
|
||||
}
|
||||
let proxy: &AccessPointProxy = ≈
|
||||
let Ok(flags) = ap.rsn_flags().await else {
|
||||
continue;
|
||||
|
|
@ -100,6 +99,7 @@ pub struct AccessPoint {
|
|||
// TODO do we want to support eap methods other than peap in the applet?
|
||||
// Then we'd need a dropdown for the eap method,
|
||||
// and tls requires a cert instead of a password
|
||||
#[allow(clippy::upper_case_acronyms)]
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub enum NetworkType {
|
||||
Open,
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ pub async fn active_connections(
|
|||
Some(SpecificDevice::Wired(wired_device)) => {
|
||||
info.push(ActiveConnectionInfo::Wired {
|
||||
name: connection.id().await?,
|
||||
hw_address: HwAddress::from_string(&wired_device.hw_address().await?)
|
||||
hw_address: HwAddress::from_str(&wired_device.hw_address().await?)
|
||||
.unwrap_or_default(),
|
||||
speed: wired_device.speed().await?,
|
||||
ip_addresses: addresses.clone(),
|
||||
|
|
@ -53,10 +53,8 @@ pub async fn active_connections(
|
|||
info.push(ActiveConnectionInfo::WiFi {
|
||||
name: String::from_utf8_lossy(&access_point.ssid().await?).into_owned(),
|
||||
ip_addresses: addresses.clone(),
|
||||
hw_address: HwAddress::from_string(
|
||||
&wireless_device.hw_address().await?,
|
||||
)
|
||||
.unwrap_or_default(),
|
||||
hw_address: HwAddress::from_str(&wireless_device.hw_address().await?)
|
||||
.unwrap_or_default(),
|
||||
state,
|
||||
strength: access_point.strength().await.unwrap_or_default(),
|
||||
});
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ async fn start_listening(
|
|||
let mut devices_changed = network_manager.receive_devices_changed().await;
|
||||
|
||||
let secs = if has_popup { 4 } else { 60 };
|
||||
while let (Some(_change), _) = tokio::join!(
|
||||
while let (Some(_change), ()) = tokio::join!(
|
||||
devices_changed.next(),
|
||||
tokio::time::sleep(tokio::time::Duration::from_secs(secs))
|
||||
) {
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
use std::fmt::Write;
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Default, Debug, PartialOrd, Ord)]
|
||||
pub struct HwAddress {
|
||||
address: u64,
|
||||
|
|
@ -5,7 +7,7 @@ pub struct HwAddress {
|
|||
|
||||
impl HwAddress {
|
||||
pub fn from_str(arg: &str) -> Option<Self> {
|
||||
let columnless_vec = arg.split(":").collect::<Vec<&str>>();
|
||||
let columnless_vec = arg.split(':').collect::<Box<[_]>>();
|
||||
if columnless_vec.len() * 3 - 1 != arg.len() {
|
||||
return None;
|
||||
}
|
||||
|
|
@ -16,24 +18,19 @@ impl HwAddress {
|
|||
}
|
||||
u64::from_str_radix(columnless_vec.join("").as_str(), 16)
|
||||
.ok()
|
||||
.and_then(|address| Some(HwAddress { address }))
|
||||
}
|
||||
pub fn from_string(arg: &String) -> Option<Self> {
|
||||
HwAddress::from_str(arg.as_str())
|
||||
}
|
||||
pub fn to_string(&self) -> String {
|
||||
// return if self.address > 100000000000000 {
|
||||
// "Intel Corp".to_string()
|
||||
// } else {
|
||||
// "TP-Link".to_string()
|
||||
// };
|
||||
format!("{:#x}", self.address)
|
||||
.trim_start_matches("0x")
|
||||
.chars()
|
||||
.collect::<Vec<_>>()
|
||||
.chunks(2)
|
||||
.map(|chunk| chunk.iter().cloned().collect::<String>())
|
||||
.collect::<Vec<String>>()
|
||||
.join(":")
|
||||
.map(|address| HwAddress { address })
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Display for HwAddress {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
for (index, c) in format!("{:x}", self.address).char_indices() {
|
||||
if index != 0 && index % 2 == 0 {
|
||||
f.write_char(':')?;
|
||||
}
|
||||
f.write_char(c)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -74,9 +74,8 @@ async fn start_listening(
|
|||
) -> State {
|
||||
match state {
|
||||
State::Ready => {
|
||||
let conn = match Connection::system().await {
|
||||
Ok(c) => c,
|
||||
Err(_) => return State::Finished,
|
||||
let Ok(conn) = Connection::system().await else {
|
||||
return State::Finished;
|
||||
};
|
||||
|
||||
let (tx, rx) = unbounded();
|
||||
|
|
@ -96,9 +95,8 @@ async fn start_listening(
|
|||
}
|
||||
}
|
||||
State::Waiting(conn, mut rx) => {
|
||||
let network_manager = match NetworkManager::new(&conn).await {
|
||||
Ok(n) => n,
|
||||
Err(_) => return State::Finished,
|
||||
let Ok(network_manager) = NetworkManager::new(&conn).await else {
|
||||
return State::Finished;
|
||||
};
|
||||
|
||||
match rx.next().await {
|
||||
|
|
@ -114,7 +112,7 @@ async fn start_listening(
|
|||
}
|
||||
let mut is_there_device = false;
|
||||
for device in c.devices().await.unwrap_or_default() {
|
||||
if HwAddress::from_string(device.hw_address().await.as_ref().unwrap())
|
||||
if HwAddress::from_str(device.hw_address().await.as_ref().unwrap())
|
||||
== Some(hw_address)
|
||||
{
|
||||
is_there_device = true;
|
||||
|
|
@ -288,7 +286,7 @@ async fn start_listening(
|
|||
_ => {
|
||||
return State::Finished;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
State::Waiting(conn, rx)
|
||||
}
|
||||
|
|
@ -494,7 +492,7 @@ impl NetworkManagerState {
|
|||
ap.network_type,
|
||||
ap.working,
|
||||
ap.state
|
||||
)
|
||||
);
|
||||
}
|
||||
self_.active_conns = active_conns;
|
||||
self_.known_access_points = known_access_points;
|
||||
|
|
@ -510,7 +508,7 @@ impl NetworkManagerState {
|
|||
self.wireless_access_points = Vec::new();
|
||||
}
|
||||
|
||||
async fn connect_wifi<'a>(
|
||||
async fn connect_wifi(
|
||||
&self,
|
||||
conn: &Connection,
|
||||
ssid: &str,
|
||||
|
|
@ -587,7 +585,7 @@ impl NetworkManagerState {
|
|||
.hw_address()
|
||||
.await
|
||||
.ok()
|
||||
.and_then(|device_address| HwAddress::from_string(&device_address))
|
||||
.and_then(|device_address| HwAddress::from_str(&device_address))
|
||||
.unwrap_or_default();
|
||||
if device_hw_address != hw_address {
|
||||
continue;
|
||||
|
|
@ -631,8 +629,8 @@ impl NetworkManagerState {
|
|||
let (_, active_conn) = nm
|
||||
.add_and_activate_connection(conn_settings, device.inner().path(), &ap.path)
|
||||
.await?;
|
||||
let dummy = ActiveConnectionProxy::new(&conn, active_conn).await?;
|
||||
let active = ActiveConnectionProxy::builder(&conn)
|
||||
let dummy = ActiveConnectionProxy::new(conn, active_conn).await?;
|
||||
let active = ActiveConnectionProxy::builder(conn)
|
||||
.destination(dummy.inner().destination().to_owned())
|
||||
.unwrap()
|
||||
.interface(dummy.inner().interface().to_owned())
|
||||
|
|
@ -645,7 +643,7 @@ impl NetworkManagerState {
|
|||
ActiveConnection::from(active)
|
||||
};
|
||||
let mut changes = active_conn.receive_state_changed().await;
|
||||
_ = tokio::time::sleep(tokio::time::Duration::from_millis(500)).await;
|
||||
() = tokio::time::sleep(tokio::time::Duration::from_millis(500)).await;
|
||||
let mut count = 5;
|
||||
loop {
|
||||
let state = active_conn.state().await;
|
||||
|
|
@ -654,15 +652,14 @@ impl NetworkManagerState {
|
|||
} else if let Ok(enums::ActiveConnectionState::Deactivated) = state {
|
||||
anyhow::bail!("Failed to activate connection");
|
||||
}
|
||||
match tokio::time::timeout(Duration::from_secs(20), changes.next()).await {
|
||||
Ok(Some(s)) => {
|
||||
let state = s.get().await.unwrap_or_default().into();
|
||||
if matches!(state, enums::ActiveConnectionState::Activated) {
|
||||
return Ok(());
|
||||
}
|
||||
if let 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) {
|
||||
return Ok(());
|
||||
}
|
||||
_ => {}
|
||||
};
|
||||
}
|
||||
|
||||
count -= 1;
|
||||
if count <= 0 {
|
||||
|
|
|
|||
|
|
@ -125,12 +125,12 @@ impl cosmic::Application for Notifications {
|
|||
core,
|
||||
config_helper: helper,
|
||||
config,
|
||||
icon_name: Default::default(),
|
||||
icon_name: String::default(),
|
||||
popup: None,
|
||||
timeline: Default::default(),
|
||||
dbus_sender: Default::default(),
|
||||
timeline: Timeline::default(),
|
||||
dbus_sender: Option::default(),
|
||||
cards: Vec::new(),
|
||||
token_tx: Default::default(),
|
||||
token_tx: Option::default(),
|
||||
proxy: block_on(crate::subscriptions::notifications::get_proxy())
|
||||
.expect("Failed to get proxy"),
|
||||
notifications_tx: None,
|
||||
|
|
@ -290,7 +290,7 @@ impl cosmic::Application for Notifications {
|
|||
}
|
||||
}
|
||||
Message::ClearAll(None) => {
|
||||
for n in self.cards.drain(..).map(|n| n.1).flatten() {
|
||||
for n in self.cards.drain(..).flat_map(|n| n.1) {
|
||||
if let Some(tx) = &self.dbus_sender {
|
||||
let tx = tx.clone();
|
||||
tokio::spawn(async move {
|
||||
|
|
@ -365,7 +365,7 @@ impl cosmic::Application for Notifications {
|
|||
{
|
||||
Some(ActionId::Default.to_string())
|
||||
} else {
|
||||
notification.actions.get(0).map(|a| a.0.to_string())
|
||||
notification.actions.first().map(|a| a.0.to_string())
|
||||
};
|
||||
|
||||
let Some(action) = maybe_action else {
|
||||
|
|
@ -392,12 +392,12 @@ impl cosmic::Application for Notifications {
|
|||
cosmic::app::Action::Surface(a),
|
||||
));
|
||||
}
|
||||
};
|
||||
}
|
||||
self.update_icon();
|
||||
Task::none()
|
||||
}
|
||||
|
||||
fn view(&self) -> Element<Message> {
|
||||
fn view(&self) -> Element<'_, Message> {
|
||||
self.core
|
||||
.applet
|
||||
.icon_button(&self.icon_name)
|
||||
|
|
@ -405,7 +405,7 @@ impl cosmic::Application for Notifications {
|
|||
.into()
|
||||
}
|
||||
|
||||
fn view_window(&self, _id: window::Id) -> Element<Message> {
|
||||
fn view_window(&self, _id: window::Id) -> Element<'_, Message> {
|
||||
let Spacing {
|
||||
space_xxs, space_s, ..
|
||||
} = theme::active().cosmic().spacing;
|
||||
|
|
@ -423,7 +423,7 @@ impl cosmic::Application for Notifications {
|
|||
]);
|
||||
|
||||
let notifications = if self.cards.is_empty() {
|
||||
let no_notifications = String::from(fl!("no-notifications"));
|
||||
let no_notifications = fl!("no-notifications");
|
||||
row![
|
||||
container(
|
||||
column![
|
||||
|
|
|
|||
|
|
@ -43,6 +43,6 @@ pub fn localize() {
|
|||
let requested_languages = i18n_embed::DesktopLanguageRequester::requested_languages();
|
||||
|
||||
if let Err(error) = localizer.select(&requested_languages) {
|
||||
eprintln!("Error while loading language for App List {}", error);
|
||||
eprintln!("Error while loading language for App List {error}");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ pub fn notifications(proxy: NotificationsAppletProxy<'static>) -> Subscription<O
|
|||
std::process::exit(0);
|
||||
} else {
|
||||
tokio::time::sleep(std::time::Duration::from_secs(1)).await;
|
||||
};
|
||||
}
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
|
@ -101,10 +101,10 @@ pub fn notifications(proxy: NotificationsAppletProxy<'static>) -> Subscription<O
|
|||
}
|
||||
v = next_input => {
|
||||
if let Some(Input::Activated(id, action)) = v {
|
||||
if let Err(err) = proxy.invoke_action(id, action.clone()).await {
|
||||
if proxy.invoke_action(id, action.clone()).await.is_err() {
|
||||
tracing::error!("Failed to invoke action {id} {action}");
|
||||
} else {
|
||||
tracing::error!("Invoked {action} for {id}")
|
||||
tracing::error!("Invoked {action} for {id}");
|
||||
}
|
||||
} else {
|
||||
tracing::error!("Channel closed, ending notifications subscription");
|
||||
|
|
|
|||
|
|
@ -99,7 +99,7 @@ impl cosmic::Application for Power {
|
|||
core,
|
||||
icon_name: "system-shutdown-symbolic".to_string(),
|
||||
subsurface_id: window::Id::unique(),
|
||||
popup: Default::default(),
|
||||
popup: Option::default(),
|
||||
},
|
||||
Task::none(),
|
||||
)
|
||||
|
|
@ -158,12 +158,12 @@ impl cosmic::Application for Power {
|
|||
}
|
||||
}
|
||||
a => return a.perform(),
|
||||
};
|
||||
}
|
||||
Task::none()
|
||||
}
|
||||
Message::Zbus(result) => {
|
||||
if let Err(e) = result {
|
||||
eprintln!("cosmic-applet-power ERROR: '{}'", e);
|
||||
eprintln!("cosmic-applet-power ERROR: '{e}'");
|
||||
}
|
||||
Task::none()
|
||||
}
|
||||
|
|
@ -181,7 +181,7 @@ impl cosmic::Application for Power {
|
|||
}
|
||||
}
|
||||
|
||||
fn view(&self) -> Element<Message> {
|
||||
fn view(&self) -> Element<'_, Message> {
|
||||
self.core
|
||||
.applet
|
||||
.icon_button(&self.icon_name)
|
||||
|
|
@ -189,7 +189,7 @@ impl cosmic::Application for Power {
|
|||
.into()
|
||||
}
|
||||
|
||||
fn view_window(&self, id: window::Id) -> Element<Message> {
|
||||
fn view_window(&self, id: window::Id) -> Element<'_, Message> {
|
||||
let Spacing {
|
||||
space_xxs,
|
||||
space_s,
|
||||
|
|
@ -264,7 +264,7 @@ impl cosmic::Application for Power {
|
|||
}
|
||||
}
|
||||
|
||||
fn power_buttons(name: &str, on_press: Message) -> button::Button<Message> {
|
||||
fn power_buttons(name: &str, on_press: Message) -> button::Button<'_, Message> {
|
||||
button::custom(
|
||||
widget::container(text_icon(name, 40))
|
||||
.width(Length::Fill)
|
||||
|
|
@ -340,16 +340,13 @@ async fn lock() -> zbus::Result<()> {
|
|||
async fn log_out() -> zbus::Result<()> {
|
||||
let session_type = std::env::var("XDG_CURRENT_DESKTOP").ok();
|
||||
let connection = Connection::session().await?;
|
||||
match session_type.as_ref().map(|s| s.trim()) {
|
||||
Some("pop:GNOME") => {
|
||||
let manager_proxy = SessionManagerProxy::new(&connection).await?;
|
||||
manager_proxy.logout(0).await?;
|
||||
}
|
||||
if let Some("pop:GNOME") = session_type.as_ref().map(|s| s.trim()) {
|
||||
let manager_proxy = SessionManagerProxy::new(&connection).await?;
|
||||
manager_proxy.logout(0).await?;
|
||||
} else {
|
||||
// By default assume COSMIC
|
||||
_ => {
|
||||
let cosmic_session = CosmicSessionProxy::new(&connection).await?;
|
||||
cosmic_session.exit().await?;
|
||||
}
|
||||
let cosmic_session = CosmicSessionProxy::new(&connection).await?;
|
||||
cosmic_session.exit().await?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,6 +43,6 @@ pub fn localize() {
|
|||
let requested_languages = i18n_embed::DesktopLanguageRequester::requested_languages();
|
||||
|
||||
if let Err(error) = localizer.select(&requested_languages) {
|
||||
eprintln!("Error while loading language for App List {}", error);
|
||||
eprintln!("Error while loading language for App List {error}");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -65,15 +65,13 @@ impl App {
|
|||
}
|
||||
|
||||
fn overflow_index(&self) -> Option<usize> {
|
||||
let Some(max_major_axis_len) = self.core.applet.suggested_bounds.as_ref().map(|c| {
|
||||
let max_major_axis_len = self.core.applet.suggested_bounds.as_ref().map(|c| {
|
||||
// if we have a configure for width and height, we're in a overflow popup
|
||||
match self.core.applet.anchor {
|
||||
PanelAnchor::Top | PanelAnchor::Bottom => c.width as u32,
|
||||
PanelAnchor::Left | PanelAnchor::Right => c.height as u32,
|
||||
}
|
||||
}) else {
|
||||
return None;
|
||||
};
|
||||
})?;
|
||||
|
||||
let button_total_size =
|
||||
self.core.applet.suggested_size(true).0 + self.core.applet.suggested_padding(true) * 2;
|
||||
|
|
@ -111,7 +109,7 @@ impl App {
|
|||
});
|
||||
let theme = self.core.system_theme();
|
||||
let cosmic = theme.cosmic();
|
||||
let corners = cosmic.corner_radii.clone();
|
||||
let corners = cosmic.corner_radii;
|
||||
let pad = corners.radius_m[0];
|
||||
|
||||
self.core
|
||||
|
|
@ -211,12 +209,12 @@ impl cosmic::Application for App {
|
|||
self.resize_window()
|
||||
}
|
||||
status_notifier_watcher::Event::Error(err) => {
|
||||
eprintln!("Status notifier error: {}", err);
|
||||
eprintln!("Status notifier error: {err}");
|
||||
Task::none()
|
||||
}
|
||||
},
|
||||
Msg::TogglePopup(id) => {
|
||||
self.open_menu = if self.open_menu != Some(id) {
|
||||
self.open_menu = if self.open_menu.is_none() {
|
||||
Some(id)
|
||||
} else {
|
||||
None
|
||||
|
|
@ -232,15 +230,14 @@ impl cosmic::Application for App {
|
|||
let i = self.menus.keys().position(|&i| i == id).unwrap();
|
||||
let (i, parent) = self
|
||||
.overflow_index()
|
||||
.clone()
|
||||
.and_then(|overflow_i| {
|
||||
if overflow_i <= i {
|
||||
Some(i - overflow_i).zip(self.overflow_popup.clone())
|
||||
Some(i - overflow_i).zip(self.overflow_popup)
|
||||
} else {
|
||||
Some((i, self.core.main_window_id().unwrap()))
|
||||
}
|
||||
})
|
||||
.unwrap_or_else(|| (0, self.core.main_window_id().unwrap()));
|
||||
.unwrap_or((0, self.core.main_window_id().unwrap()));
|
||||
|
||||
let mut popup_settings = self
|
||||
.core
|
||||
|
|
@ -315,15 +312,14 @@ impl cosmic::Application for App {
|
|||
|
||||
let (i, parent) = self
|
||||
.overflow_index()
|
||||
.clone()
|
||||
.and_then(|overflow_i| {
|
||||
if overflow_i <= i {
|
||||
Some(i - overflow_i).zip(self.overflow_popup.clone())
|
||||
Some(i - overflow_i).zip(self.overflow_popup)
|
||||
} else {
|
||||
Some((i, self.core.main_window_id().unwrap()))
|
||||
}
|
||||
})
|
||||
.unwrap_or_else(|| (0, self.core.main_window_id().unwrap()));
|
||||
.unwrap_or((0, self.core.main_window_id().unwrap()));
|
||||
|
||||
let mut popup_settings = self
|
||||
.core
|
||||
|
|
@ -384,8 +380,7 @@ impl cosmic::Application for App {
|
|||
}
|
||||
|
||||
self.overflow_popup = Some(popup_id);
|
||||
let mut cmds = Vec::new();
|
||||
cmds.push(get_popup(popup_settings));
|
||||
let cmds = vec![get_popup(popup_settings)];
|
||||
return Task::batch(cmds);
|
||||
} else {
|
||||
return Task::none();
|
||||
|
|
@ -442,7 +437,7 @@ impl cosmic::Application for App {
|
|||
|
||||
subscriptions.push(status_notifier_watcher::subscription().map(Msg::StatusNotifier));
|
||||
|
||||
for (id, menu) in self.menus.iter() {
|
||||
for (id, menu) in &self.menus {
|
||||
subscriptions.push(menu.subscription().with(*id).map(Msg::StatusMenu));
|
||||
}
|
||||
subscriptions.push(activation_token_subscription(0).map(Msg::Token));
|
||||
|
|
@ -513,7 +508,7 @@ impl cosmic::Application for App {
|
|||
|
||||
let theme = self.core.system_theme();
|
||||
let cosmic = theme.cosmic();
|
||||
let corners = cosmic.corner_radii.clone();
|
||||
let corners = cosmic.corner_radii;
|
||||
let pad = corners.radius_m[0];
|
||||
match self.open_menu {
|
||||
Some(id) => match self.menus.get(&id) {
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ impl State {
|
|||
Ok(layout) => {
|
||||
self.layout = Some(layout);
|
||||
}
|
||||
Err(err) => eprintln!("Error getting layout from icon: {}", err),
|
||||
Err(err) => eprintln!("Error getting layout from icon: {err}"),
|
||||
}
|
||||
iced::Task::none()
|
||||
}
|
||||
|
|
@ -109,7 +109,7 @@ impl State {
|
|||
let _ = menu_proxy.event(id, "clicked", &0.into(), 0).await;
|
||||
});
|
||||
if is_submenu {
|
||||
self.expanded = if self.expanded != Some(id) {
|
||||
self.expanded = if self.expanded.is_none() {
|
||||
Some(id)
|
||||
} else {
|
||||
None
|
||||
|
|
@ -134,7 +134,7 @@ impl State {
|
|||
self.icon_pixmap.as_ref()
|
||||
}
|
||||
|
||||
pub fn popup_view(&self) -> cosmic::Element<Msg> {
|
||||
pub fn popup_view(&self) -> cosmic::Element<'_, Msg> {
|
||||
if let Some(layout) = self.layout.as_ref() {
|
||||
layout_view(layout, self.expanded)
|
||||
} else {
|
||||
|
|
@ -165,7 +165,7 @@ impl State {
|
|||
}
|
||||
}
|
||||
|
||||
fn layout_view(layout: &Layout, expanded: Option<i32>) -> cosmic::Element<Msg> {
|
||||
fn layout_view(layout: &Layout, expanded: Option<i32>) -> cosmic::Element<'_, Msg> {
|
||||
iced::widget::column(layout.children().iter().filter_map(|i| {
|
||||
if !i.visible() {
|
||||
None
|
||||
|
|
|
|||
|
|
@ -76,7 +76,7 @@ impl StatusNotifierItem {
|
|||
}
|
||||
|
||||
pub fn icon_subscription(&self) -> iced::Subscription<IconUpdate> {
|
||||
fn icon_events<'a>(
|
||||
fn icon_events(
|
||||
item_proxy: StatusNotifierItemProxy<'static>,
|
||||
) -> impl futures::Stream<Item = IconUpdate> + 'static {
|
||||
async move {
|
||||
|
|
@ -99,7 +99,7 @@ impl StatusNotifierItem {
|
|||
format!("status-notifier-item-icon-{}", &self.name),
|
||||
async move {
|
||||
let new_icon_stream = item_proxy.receive_new_icon().await.unwrap();
|
||||
futures::stream::once(async { () })
|
||||
futures::stream::once(async {})
|
||||
.chain(new_icon_stream.map(|_| ()))
|
||||
.flat_map(move |()| icon_events(item_proxy.clone()))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ pub async fn watch(connection: &zbus::Connection) -> zbus::Result<EventStream> {
|
|||
|
||||
let name = connection.unique_name().unwrap().as_str();
|
||||
if let Err(err) = watcher.register_status_notifier_host(name).await {
|
||||
eprintln!("Failed to register status notifier host: {}", err);
|
||||
eprintln!("Failed to register status notifier host: {err}");
|
||||
}
|
||||
|
||||
let connection_clone = connection.clone();
|
||||
|
|
|
|||
|
|
@ -36,10 +36,10 @@ pub fn subscription() -> iced::Subscription<Event> {
|
|||
}
|
||||
Err(err) => Some((Event::Error(err.to_string()), State::Failed)),
|
||||
},
|
||||
State::Connected(mut stream) => match stream.next().await {
|
||||
Some(event) => Some((event, State::Connected(stream))),
|
||||
None => None,
|
||||
},
|
||||
State::Connected(mut stream) => stream
|
||||
.next()
|
||||
.await
|
||||
.map(|event| (event, State::Connected(stream))),
|
||||
State::Failed => None,
|
||||
}
|
||||
}),
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ impl StatusNotifierWatcher {
|
|||
) {
|
||||
let sender = hdr.sender().unwrap();
|
||||
let service = if service.starts_with('/') {
|
||||
format!("{}{}", sender, service)
|
||||
format!("{sender}{service}")
|
||||
} else {
|
||||
service.to_string()
|
||||
};
|
||||
|
|
@ -95,7 +95,7 @@ pub async fn create_service(connection: &zbus::Connection) -> zbus::Result<()> {
|
|||
|
||||
let flags = RequestNameFlags::AllowReplacement.into();
|
||||
if dbus_proxy.request_name(NAME.as_ref(), flags).await? == RequestNameReply::InQueue {
|
||||
eprintln!("Bus name '{}' already owned", NAME);
|
||||
eprintln!("Bus name '{NAME}' already owned");
|
||||
}
|
||||
|
||||
let connection = connection.clone();
|
||||
|
|
@ -103,18 +103,15 @@ pub async fn create_service(connection: &zbus::Connection) -> zbus::Result<()> {
|
|||
let mut have_bus_name = false;
|
||||
let unique_name = connection.unique_name().map(|x| x.as_ref());
|
||||
while let Some(evt) = name_owner_changed_stream.next().await {
|
||||
let args = match evt.args() {
|
||||
Ok(args) => args,
|
||||
Err(_) => {
|
||||
continue;
|
||||
}
|
||||
let Ok(args) = evt.args() else {
|
||||
continue;
|
||||
};
|
||||
if args.name.as_ref() == NAME {
|
||||
if args.new_owner.as_ref() == unique_name.as_ref() {
|
||||
eprintln!("Acquired bus name: {}", NAME);
|
||||
eprintln!("Acquired bus name: {NAME}");
|
||||
have_bus_name = true;
|
||||
} else if have_bus_name {
|
||||
eprintln!("Lost bus name: {}", NAME);
|
||||
eprintln!("Lost bus name: {NAME}");
|
||||
have_bus_name = false;
|
||||
}
|
||||
} else if let BusName::Unique(name) = &args.name {
|
||||
|
|
|
|||
|
|
@ -43,6 +43,6 @@ pub fn localize() {
|
|||
let requested_languages = i18n_embed::DesktopLanguageRequester::requested_languages();
|
||||
|
||||
if let Err(error) = localizer.select(&requested_languages) {
|
||||
eprintln!("Error while loading language for App List {}", error);
|
||||
eprintln!("Error while loading language for App List {error}");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -88,7 +88,7 @@ pub fn spawn_workspaces(tx: mpsc::Sender<TilingState>) -> SyncSender<AppRequest>
|
|||
};
|
||||
let loop_handle = event_loop.handle();
|
||||
loop_handle
|
||||
.insert_source(workspaces_rx, |e, _, state| match e {
|
||||
.insert_source(workspaces_rx, |e, (), state| match e {
|
||||
Event::Msg(AppRequest::TilingState(autotile)) => {
|
||||
if let Some(w) = state.workspace_state.workspace_groups().find_map(|g| {
|
||||
if let Some(o) = state.expected_output.as_ref() {
|
||||
|
|
@ -183,9 +183,10 @@ impl State {
|
|||
.filter_map(|handle| self.workspace_state.workspace_info(handle))
|
||||
.find_map(|w| {
|
||||
if w.state.contains(ext_workspace_handle_v1::State::Active) {
|
||||
w.tiling.and_then(|e| match e {
|
||||
WEnum::Value(v) => Some(v),
|
||||
_ => {
|
||||
w.tiling.and_then(|e| {
|
||||
if let WEnum::Value(v) = e {
|
||||
Some(v)
|
||||
} else {
|
||||
error!("No tiling state for the workspace");
|
||||
None
|
||||
}
|
||||
|
|
@ -273,7 +274,7 @@ impl ToplevelInfoHandler for State {
|
|||
) {
|
||||
let Some(w) = self
|
||||
.toplevel_info_state
|
||||
.info(&toplevel)
|
||||
.info(toplevel)
|
||||
.map(|t| t.workspace.clone())
|
||||
else {
|
||||
return;
|
||||
|
|
@ -289,7 +290,7 @@ impl ToplevelInfoHandler for State {
|
|||
) {
|
||||
let Some(w) = self
|
||||
.toplevel_info_state
|
||||
.info(&toplevel)
|
||||
.info(toplevel)
|
||||
.map(|t| t.workspace.clone())
|
||||
else {
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -80,6 +80,6 @@ impl WorkspacesWatcher {
|
|||
pub fn new() -> anyhow::Result<Self> {
|
||||
let (tx, rx) = mpsc::channel(20);
|
||||
let tx = wayland::spawn_workspaces(tx);
|
||||
Ok(Self { tx, rx })
|
||||
Ok(Self { rx, tx })
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -110,7 +110,7 @@ impl cosmic::Application for Window {
|
|||
let window = Self {
|
||||
core,
|
||||
popup: None,
|
||||
timeline: Default::default(),
|
||||
timeline: Timeline::default(),
|
||||
autotiled: config.autotile,
|
||||
config,
|
||||
config_helper,
|
||||
|
|
@ -202,7 +202,7 @@ impl cosmic::Application for Window {
|
|||
};
|
||||
|
||||
if let Err(err) = tx.send(AppRequest::TilingState(state)) {
|
||||
error!("Failed to send the tiling state update. {err:?}")
|
||||
error!("Failed to send the tiling state update. {err:?}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -223,16 +223,14 @@ impl cosmic::Application for Window {
|
|||
.activate_position(if c.autotile { 0 } else { 1 });
|
||||
}
|
||||
|
||||
if c.active_hint != self.config.active_hint {
|
||||
if self.popup.is_some() {
|
||||
self.timeline
|
||||
.set_chain(if c.active_hint {
|
||||
cosmic_time::chain::Toggler::on(self.active_hint.clone(), 1.0)
|
||||
} else {
|
||||
cosmic_time::chain::Toggler::off(self.active_hint.clone(), 1.0)
|
||||
})
|
||||
.start();
|
||||
}
|
||||
if c.active_hint != self.config.active_hint && self.popup.is_some() {
|
||||
self.timeline
|
||||
.set_chain(if c.active_hint {
|
||||
cosmic_time::chain::Toggler::on(self.active_hint.clone(), 1.0)
|
||||
} else {
|
||||
cosmic_time::chain::Toggler::off(self.active_hint.clone(), 1.0)
|
||||
})
|
||||
.start();
|
||||
}
|
||||
|
||||
self.config = *c;
|
||||
|
|
@ -252,7 +250,7 @@ impl cosmic::Application for Window {
|
|||
};
|
||||
|
||||
if let Err(err) = tx.send(AppRequest::DefaultBehavior(state)) {
|
||||
error!("Failed to send the tiling state update. {err:?}")
|
||||
error!("Failed to send the tiling state update. {err:?}");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -276,7 +274,7 @@ impl cosmic::Application for Window {
|
|||
Task::none()
|
||||
}
|
||||
|
||||
fn view(&self) -> Element<Self::Message> {
|
||||
fn view(&self) -> Element<'_, Self::Message> {
|
||||
self.core
|
||||
.applet
|
||||
.icon_button(if self.autotiled { ON } else { OFF })
|
||||
|
|
@ -284,7 +282,7 @@ impl cosmic::Application for Window {
|
|||
.into()
|
||||
}
|
||||
|
||||
fn view_window(&self, _id: Id) -> Element<Self::Message> {
|
||||
fn view_window(&self, _id: Id) -> Element<'_, Self::Message> {
|
||||
let Spacing {
|
||||
space_xxxs,
|
||||
space_xxs,
|
||||
|
|
|
|||
|
|
@ -43,6 +43,6 @@ pub fn localize() {
|
|||
let requested_languages = i18n_embed::DesktopLanguageRequester::requested_languages();
|
||||
|
||||
if let Err(error) = localizer.select(&requested_languages) {
|
||||
eprintln!("Error while loading language for App List {}", error);
|
||||
eprintln!("Error while loading language for App List {error}");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -159,7 +159,7 @@ impl Window {
|
|||
calendar
|
||||
}
|
||||
|
||||
fn vertical_layout(&self) -> Element<Message> {
|
||||
fn vertical_layout(&self) -> Element<'_, Message> {
|
||||
let mut elements = Vec::new();
|
||||
let date = self.now.naive_local();
|
||||
let datetime = self.create_datetime(&date);
|
||||
|
|
@ -216,7 +216,7 @@ impl Window {
|
|||
)
|
||||
}
|
||||
|
||||
fn horizontal_layout(&self) -> Element<Message> {
|
||||
fn horizontal_layout(&self) -> Element<'_, Message> {
|
||||
let datetime = self.create_datetime(&self.now);
|
||||
let mut prefs = DateTimeFormatterPreferences::from(self.locale.clone());
|
||||
prefs.hour_cycle = Some(if self.config.military_time {
|
||||
|
|
@ -500,10 +500,10 @@ impl cosmic::Application for Window {
|
|||
}
|
||||
}
|
||||
Message::Tick => {
|
||||
self.now = self
|
||||
.timezone
|
||||
.map(|tz| chrono::Local::now().with_timezone(&tz).fixed_offset())
|
||||
.unwrap_or_else(|| chrono::Local::now().into());
|
||||
self.now = self.timezone.map_or_else(
|
||||
|| chrono::Local::now().into(),
|
||||
|tz| chrono::Local::now().with_timezone(&tz).fixed_offset(),
|
||||
);
|
||||
Task::none()
|
||||
}
|
||||
Message::Rectangle(u) => {
|
||||
|
|
@ -523,8 +523,8 @@ impl cosmic::Application for Window {
|
|||
}
|
||||
Task::none()
|
||||
}
|
||||
Message::SelectDay(_day) => {
|
||||
if let Some(date) = self.date_selected.with_day(_day) {
|
||||
Message::SelectDay(day) => {
|
||||
if let Some(date) = self.date_selected.with_day(day) {
|
||||
self.date_selected = date;
|
||||
} else {
|
||||
tracing::error!("invalid naivedate");
|
||||
|
|
@ -562,7 +562,7 @@ impl cosmic::Application for Window {
|
|||
});
|
||||
} else {
|
||||
tracing::error!("Wayland tx is None");
|
||||
};
|
||||
}
|
||||
Task::none()
|
||||
}
|
||||
Message::Token(u) => {
|
||||
|
|
@ -616,7 +616,7 @@ impl cosmic::Application for Window {
|
|||
}
|
||||
}
|
||||
|
||||
fn view(&self) -> Element<Message> {
|
||||
fn view(&self) -> Element<'_, Message> {
|
||||
let horizontal = matches!(
|
||||
self.core.applet.anchor,
|
||||
PanelAnchor::Top | PanelAnchor::Bottom
|
||||
|
|
@ -646,7 +646,7 @@ impl cosmic::Application for Window {
|
|||
.into()
|
||||
}
|
||||
|
||||
fn view_window(&self, _id: window::Id) -> Element<Message> {
|
||||
fn view_window(&self, _id: window::Id) -> Element<'_, Message> {
|
||||
let Spacing {
|
||||
space_xxs, space_s, ..
|
||||
} = theme::active().cosmic().spacing;
|
||||
|
|
|
|||
|
|
@ -110,7 +110,7 @@ impl cosmic::Application for IcedWorkspacesApplet {
|
|||
},
|
||||
core,
|
||||
workspaces: Vec::new(),
|
||||
workspace_tx: Default::default(),
|
||||
workspace_tx: Option::default(),
|
||||
scroll: 0.0,
|
||||
next_scroll: None,
|
||||
last_scroll: Instant::now(),
|
||||
|
|
@ -211,7 +211,7 @@ impl cosmic::Application for IcedWorkspacesApplet {
|
|||
Task::none()
|
||||
}
|
||||
|
||||
fn view(&self) -> Element<Message> {
|
||||
fn view(&self) -> Element<'_, Message> {
|
||||
if self.workspaces.is_empty() {
|
||||
return row![].padding(8).into();
|
||||
}
|
||||
|
|
@ -224,7 +224,7 @@ impl cosmic::Application for IcedWorkspacesApplet {
|
|||
let suggested_window_size = self.core.applet.suggested_window_size();
|
||||
let popup_index = self.popup_index().unwrap_or(self.workspaces.len());
|
||||
|
||||
let buttons = self.workspaces[..popup_index].iter().filter_map(|w| {
|
||||
let buttons = self.workspaces[..popup_index].iter().map(|w| {
|
||||
let content = self.core.applet.text(&w.name).font(cosmic::font::bold());
|
||||
|
||||
let (width, height) = if self.core.applet.is_horizontal() {
|
||||
|
|
@ -258,79 +258,73 @@ impl cosmic::Application for IcedWorkspacesApplet {
|
|||
)
|
||||
.padding(0);
|
||||
|
||||
Some(
|
||||
btn.class(
|
||||
if w.state.contains(ext_workspace_handle_v1::State::Active) {
|
||||
cosmic::theme::iced::Button::Primary
|
||||
} else if w.state.contains(ext_workspace_handle_v1::State::Urgent) {
|
||||
let appearance = |theme: &Theme| {
|
||||
let cosmic = theme.cosmic();
|
||||
button::Style {
|
||||
btn.class(
|
||||
if w.state.contains(ext_workspace_handle_v1::State::Active) {
|
||||
cosmic::theme::iced::Button::Primary
|
||||
} else if w.state.contains(ext_workspace_handle_v1::State::Urgent) {
|
||||
let appearance = |theme: &Theme| {
|
||||
let cosmic = theme.cosmic();
|
||||
button::Style {
|
||||
background: Some(Background::Color(cosmic.palette.neutral_3.into())),
|
||||
border: Border {
|
||||
radius: cosmic.radius_xl().into(),
|
||||
..Default::default()
|
||||
},
|
||||
border_radius: theme.cosmic().radius_xl().into(),
|
||||
text_color: theme.cosmic().destructive_button.base.into(),
|
||||
..button::Style::default()
|
||||
}
|
||||
};
|
||||
cosmic::theme::iced::Button::Custom(Box::new(
|
||||
move |theme, status| match status {
|
||||
button::Status::Active => appearance(theme),
|
||||
button::Status::Hovered => button::Style {
|
||||
background: Some(Background::Color(
|
||||
cosmic.palette.neutral_3.into(),
|
||||
theme.current_container().component.hover.into(),
|
||||
)),
|
||||
border: Border {
|
||||
radius: cosmic.radius_xl().into(),
|
||||
radius: theme.cosmic().radius_xl().into(),
|
||||
..Default::default()
|
||||
},
|
||||
border_radius: theme.cosmic().radius_xl().into(),
|
||||
text_color: theme.cosmic().destructive_button.base.into(),
|
||||
..button::Style::default()
|
||||
}
|
||||
};
|
||||
cosmic::theme::iced::Button::Custom(Box::new(move |theme, status| {
|
||||
match status {
|
||||
button::Status::Active => appearance(theme),
|
||||
button::Status::Hovered => button::Style {
|
||||
background: Some(Background::Color(
|
||||
theme.current_container().component.hover.into(),
|
||||
)),
|
||||
border: Border {
|
||||
radius: theme.cosmic().radius_xl().into(),
|
||||
..Default::default()
|
||||
},
|
||||
..appearance(theme)
|
||||
},
|
||||
button::Status::Pressed => appearance(theme),
|
||||
button::Status::Disabled => appearance(theme),
|
||||
}
|
||||
}))
|
||||
} else {
|
||||
let appearance = |theme: &Theme| {
|
||||
let cosmic = theme.cosmic();
|
||||
button::Style {
|
||||
background: None,
|
||||
..appearance(theme)
|
||||
},
|
||||
button::Status::Pressed => appearance(theme),
|
||||
button::Status::Disabled => appearance(theme),
|
||||
},
|
||||
))
|
||||
} else {
|
||||
let appearance = |theme: &Theme| {
|
||||
let cosmic = theme.cosmic();
|
||||
button::Style {
|
||||
background: None,
|
||||
border: Border {
|
||||
radius: cosmic.radius_xl().into(),
|
||||
..Default::default()
|
||||
},
|
||||
border_radius: cosmic.radius_xl().into(),
|
||||
text_color: theme.current_container().component.on.into(),
|
||||
..button::Style::default()
|
||||
}
|
||||
};
|
||||
cosmic::theme::iced::Button::Custom(Box::new(
|
||||
move |theme, status| match status {
|
||||
button::Status::Active => appearance(theme),
|
||||
button::Status::Hovered => button::Style {
|
||||
background: Some(Background::Color(
|
||||
theme.current_container().component.hover.into(),
|
||||
)),
|
||||
border: Border {
|
||||
radius: cosmic.radius_xl().into(),
|
||||
radius: theme.cosmic().radius_xl().into(),
|
||||
..Default::default()
|
||||
},
|
||||
border_radius: cosmic.radius_xl().into(),
|
||||
text_color: theme.current_container().component.on.into(),
|
||||
..button::Style::default()
|
||||
}
|
||||
};
|
||||
cosmic::theme::iced::Button::Custom(Box::new(move |theme, status| {
|
||||
match status {
|
||||
button::Status::Active => appearance(theme),
|
||||
button::Status::Hovered => button::Style {
|
||||
background: Some(Background::Color(
|
||||
theme.current_container().component.hover.into(),
|
||||
)),
|
||||
border: Border {
|
||||
radius: theme.cosmic().radius_xl().into(),
|
||||
..Default::default()
|
||||
},
|
||||
..appearance(theme)
|
||||
},
|
||||
button::Status::Pressed | button::Status::Disabled => {
|
||||
appearance(theme)
|
||||
}
|
||||
}
|
||||
}))
|
||||
},
|
||||
)
|
||||
.into(),
|
||||
..appearance(theme)
|
||||
},
|
||||
button::Status::Pressed | button::Status::Disabled => appearance(theme),
|
||||
},
|
||||
))
|
||||
},
|
||||
)
|
||||
.into()
|
||||
});
|
||||
// TODO if there is a popup_index, create a button with a popup for the remaining workspaces
|
||||
// Should it appear on hover or on click?
|
||||
|
|
|
|||
|
|
@ -43,6 +43,6 @@ pub fn localize() {
|
|||
let requested_languages = i18n_embed::DesktopLanguageRequester::requested_languages();
|
||||
|
||||
if let Err(error) = localizer.select(&requested_languages) {
|
||||
eprintln!("Error while loading language for App List {}", error);
|
||||
eprintln!("Error while loading language for App List {error}");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -78,7 +78,7 @@ pub fn spawn_workspaces(tx: mpsc::Sender<Vec<Workspace>>) -> SyncSender<Workspac
|
|||
};
|
||||
let loop_handle = event_loop.handle();
|
||||
loop_handle
|
||||
.insert_source(workspaces_rx, |e, _, state| match e {
|
||||
.insert_source(workspaces_rx, |e, (), state| match e {
|
||||
Event::Msg(WorkspaceEvent::Activate(handle)) => {
|
||||
handle.activate();
|
||||
state
|
||||
|
|
|
|||
|
|
@ -79,6 +79,6 @@ impl WorkspacesWatcher {
|
|||
pub fn new() -> anyhow::Result<Self> {
|
||||
let (tx, rx) = mpsc::channel(20);
|
||||
let tx = wayland::spawn_workspaces(tx);
|
||||
Ok(Self { tx, rx })
|
||||
Ok(Self { rx, tx })
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ fn main() -> cosmic::iced::Result {
|
|||
return Ok(());
|
||||
};
|
||||
|
||||
let start = applet.rfind('/').map(|v| v + 1).unwrap_or(0);
|
||||
let start = applet.rfind('/').map_or(0, |v| v + 1);
|
||||
let cmd = &applet.as_str()[start..];
|
||||
|
||||
tracing::info!("Starting `{cmd}` with version {VERSION}");
|
||||
|
|
|
|||
|
|
@ -103,7 +103,7 @@ impl cosmic::Application for Button {
|
|||
Task::none()
|
||||
}
|
||||
|
||||
fn view(&self) -> cosmic::Element<Msg> {
|
||||
fn view(&self) -> cosmic::Element<'_, Msg> {
|
||||
// currently, panel being anchored to the left or right is a hard
|
||||
// override for icon, later if text is updated to wrap, we may
|
||||
// use Override::Text to override this behavior
|
||||
|
|
@ -181,15 +181,15 @@ pub fn run() -> iced::Result {
|
|||
if let Ok(bytes) = fs::read_to_string(&path) {
|
||||
if let Ok(entry) = DesktopEntry::from_str(&path, &bytes, Some(&locales)) {
|
||||
desktop = Some(Desktop {
|
||||
name: entry
|
||||
.name(&locales)
|
||||
.map(|x| x.to_string())
|
||||
.unwrap_or_else(|| panic!("Desktop file '{filename}' doesn't have `Name`")),
|
||||
name: entry.name(&locales).map_or_else(
|
||||
|| panic!("Desktop file '{filename}' doesn't have `Name`"),
|
||||
|x| x.to_string(),
|
||||
),
|
||||
icon: entry.icon().map(|x| x.to_string()),
|
||||
exec: entry
|
||||
.exec()
|
||||
.map(|x| x.to_string())
|
||||
.unwrap_or_else(|| panic!("Desktop file '{filename}' doesn't have `Exec`")),
|
||||
exec: entry.exec().map_or_else(
|
||||
|| panic!("Desktop file '{filename}' doesn't have `Exec`"),
|
||||
|x| x.to_string(),
|
||||
),
|
||||
});
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue