hyprswitch improvements

* update cache after window is shown instead before
* lookup icons based on process name too
This commit is contained in:
Alexander Mohr 2025-06-11 21:03:06 +02:00
parent 419d099904
commit ad5a888186

View file

@ -50,7 +50,8 @@ 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 =
cache.get(&process_name).cloned().or_else(|| {
freedesktop_icons::lookup(&process_name) freedesktop_icons::lookup(&process_name)
.with_size(cfg.image_size()) .with_size(cfg.image_size())
.with_scale(1) .with_scale(1)
@ -66,7 +67,9 @@ impl WindowProvider {
*wm_class.to_lowercase() *wm_class.to_lowercase()
== c.initial_class.to_lowercase() == c.initial_class.to_lowercase()
}, },
) { ) || app.exec.as_ref().is_some_and(|app| {
app.starts_with(&process_name)
}) {
d.entry d.entry
.icon .icon
.as_ref() .as_ref()
@ -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(