hyprswitch improvements
* update cache after window is shown instead before * lookup icons based on process name too
This commit is contained in:
parent
419d099904
commit
ad5a888186
1 changed files with 32 additions and 30 deletions
|
@ -50,35 +50,38 @@ impl WindowProvider {
|
||||||
.map(|x| x.name().to_string_lossy().into_owned());
|
.map(|x| x.name().to_string_lossy().into_owned());
|
||||||
|
|
||||||
process_name.map(|process_name| {
|
process_name.map(|process_name| {
|
||||||
let icon = cache.get(&process_name).cloned().or_else(|| {
|
let icon =
|
||||||
freedesktop_icons::lookup(&process_name)
|
cache.get(&process_name).cloned().or_else(|| {
|
||||||
.with_size(cfg.image_size())
|
freedesktop_icons::lookup(&process_name)
|
||||||
.with_scale(1)
|
.with_size(cfg.image_size())
|
||||||
.find()
|
.with_scale(1)
|
||||||
.map(|icon| icon.to_string_lossy().to_string())
|
.find()
|
||||||
.or_else(|| {
|
.map(|icon| icon.to_string_lossy().to_string())
|
||||||
desktop_files
|
.or_else(|| {
|
||||||
.iter()
|
desktop_files
|
||||||
.find_map(|d| match &d.entry.entry_type {
|
.iter()
|
||||||
EntryType::Application(app) => {
|
.find_map(|d| match &d.entry.entry_type {
|
||||||
if app.startup_wm_class.as_ref().is_some_and(
|
EntryType::Application(app) => {
|
||||||
|wm_class| {
|
if app.startup_wm_class.as_ref().is_some_and(
|
||||||
*wm_class.to_lowercase()
|
|wm_class| {
|
||||||
== c.initial_class.to_lowercase()
|
*wm_class.to_lowercase()
|
||||||
},
|
== c.initial_class.to_lowercase()
|
||||||
) {
|
},
|
||||||
d.entry
|
) || app.exec.as_ref().is_some_and(|app| {
|
||||||
.icon
|
app.starts_with(&process_name)
|
||||||
.as_ref()
|
}) {
|
||||||
.map(|icon| icon.content.clone())
|
d.entry
|
||||||
} else {
|
.icon
|
||||||
None
|
.as_ref()
|
||||||
|
.map(|icon| icon.content.clone())
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
_ => None,
|
||||||
_ => None,
|
})
|
||||||
})
|
})
|
||||||
})
|
});
|
||||||
});
|
|
||||||
|
|
||||||
MenuItem::new(
|
MenuItem::new(
|
||||||
format!(
|
format!(
|
||||||
|
@ -99,7 +102,6 @@ impl WindowProvider {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
windows: menu_items,
|
windows: menu_items,
|
||||||
})
|
})
|
||||||
|
@ -139,6 +141,7 @@ fn main() -> Result<(), String> {
|
||||||
|
|
||||||
let provider = WindowProvider::new(&config, &cache)?;
|
let provider = WindowProvider::new(&config, &cache)?;
|
||||||
let windows = provider.windows.clone();
|
let windows = provider.windows.clone();
|
||||||
|
let result = gui::show(config, provider, false, None, None).map_err(|e| e.to_string())?;
|
||||||
let update_cache = thread::spawn(move || {
|
let update_cache = thread::spawn(move || {
|
||||||
windows.iter().for_each(|item| {
|
windows.iter().for_each(|item| {
|
||||||
if let Some(window) = &item.data {
|
if let Some(window) = &item.data {
|
||||||
|
@ -155,7 +158,6 @@ fn main() -> Result<(), String> {
|
||||||
Err(e) => Err(Error::UpdateCacheError(e.to_string())),
|
Err(e) => Err(Error::UpdateCacheError(e.to_string())),
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
let result = gui::show(config, provider, false, None, None).map_err(|e| e.to_string())?;
|
|
||||||
|
|
||||||
if let Some(window) = result.menu.data {
|
if let Some(window) = result.menu.data {
|
||||||
hyprland::dispatch::Dispatch::call(DispatchType::FocusWindow(WindowIdentifier::Address(
|
hyprland::dispatch::Dispatch::call(DispatchType::FocusWindow(WindowIdentifier::Address(
|
||||||
|
|
Loading…
Add table
Reference in a new issue