mirror of
https://github.com/Zedfrigg/ironbar.git
synced 2025-09-15 19:26:58 +02:00
fix: app_id StartupWMClass resolution in launcher
This commit is contained in:
parent
dea571506f
commit
0159c0155e
1 changed files with 40 additions and 21 deletions
|
@ -244,21 +244,43 @@ impl Module<gtk::Box> for LauncherModule {
|
||||||
let tx2 = context.tx.clone();
|
let tx2 = context.tx.clone();
|
||||||
|
|
||||||
let wl = context.client::<wayland::Client>();
|
let wl = context.client::<wayland::Client>();
|
||||||
|
let desktop_files = context.ironbar.desktop_files();
|
||||||
spawn(async move {
|
spawn(async move {
|
||||||
let items = items2;
|
let items = items2;
|
||||||
let tx = tx2;
|
let tx = tx2;
|
||||||
|
|
||||||
|
// Build app_id mapping once at startup
|
||||||
|
let mut app_id_map = IndexMap::<String, String>::new();
|
||||||
|
{
|
||||||
|
let favorites: Vec<_> = lock!(items).keys().cloned().collect();
|
||||||
|
for fav in favorites {
|
||||||
|
if let Ok(Some(file)) = desktop_files.find(&fav).await {
|
||||||
|
if let Some(wm_class) = file.startup_wm_class {
|
||||||
|
app_id_map.insert(wm_class, fav);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let resolve_app_id = |app_id: &str| {
|
||||||
|
app_id_map
|
||||||
|
.get(app_id)
|
||||||
|
.cloned()
|
||||||
|
.unwrap_or_else(|| app_id.to_string())
|
||||||
|
};
|
||||||
|
|
||||||
let mut wlrx = wl.subscribe_toplevels();
|
let mut wlrx = wl.subscribe_toplevels();
|
||||||
let handles = wl.toplevel_info_all();
|
let handles = wl.toplevel_info_all();
|
||||||
|
|
||||||
for info in handles {
|
for info in handles {
|
||||||
let mut items = lock!(items);
|
let mut items = lock!(items);
|
||||||
let item = items.get_mut(&info.app_id);
|
let app_id = resolve_app_id(&info.app_id);
|
||||||
if let Some(item) = item {
|
if let Some(item) = items.get_mut(&app_id) {
|
||||||
item.merge_toplevel(info.clone());
|
item.merge_toplevel(info.clone());
|
||||||
} else {
|
} else {
|
||||||
let item = Item::from(info.clone());
|
let mut item = Item::from(info.clone());
|
||||||
items.insert(info.app_id.clone(), item);
|
item.app_id = app_id.clone();
|
||||||
|
items.insert(app_id, item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -284,14 +306,14 @@ impl Module<gtk::Box> for LauncherModule {
|
||||||
|
|
||||||
match event {
|
match event {
|
||||||
ToplevelEvent::New(info) => {
|
ToplevelEvent::New(info) => {
|
||||||
let app_id = info.app_id.clone();
|
let app_id = resolve_app_id(&info.app_id);
|
||||||
|
|
||||||
let new_item = {
|
let new_item = {
|
||||||
let mut items = lock!(items);
|
let mut items = lock!(items);
|
||||||
let item = items.get_mut(&info.app_id);
|
match items.get_mut(&app_id) {
|
||||||
match item {
|
|
||||||
None => {
|
None => {
|
||||||
let item: Item = info.into();
|
let mut item: Item = info.into();
|
||||||
|
item.app_id = app_id.clone();
|
||||||
items.insert(app_id.clone(), item.clone());
|
items.insert(app_id.clone(), item.clone());
|
||||||
|
|
||||||
ItemOrWindow::Item(item)
|
ItemOrWindow::Item(item)
|
||||||
|
@ -313,9 +335,10 @@ impl Module<gtk::Box> for LauncherModule {
|
||||||
}?;
|
}?;
|
||||||
}
|
}
|
||||||
ToplevelEvent::Update(info) => {
|
ToplevelEvent::Update(info) => {
|
||||||
|
let app_id = resolve_app_id(&info.app_id);
|
||||||
// check if open, as updates can be sent as program closes
|
// check if open, as updates can be sent as program closes
|
||||||
// if it's a focused favourite closing, it otherwise incorrectly re-focuses.
|
// if it's a focused favourite closing, it otherwise incorrectly re-focuses.
|
||||||
let is_open = if let Some(item) = lock!(items).get_mut(&info.app_id) {
|
let is_open = if let Some(item) = lock!(items).get_mut(&app_id) {
|
||||||
item.set_window_focused(info.id, info.focused);
|
item.set_window_focused(info.id, info.focused);
|
||||||
item.set_window_name(info.id, info.title.clone());
|
item.set_window_name(info.id, info.title.clone());
|
||||||
|
|
||||||
|
@ -325,27 +348,27 @@ impl Module<gtk::Box> for LauncherModule {
|
||||||
};
|
};
|
||||||
|
|
||||||
send_update(LauncherUpdate::Focus(
|
send_update(LauncherUpdate::Focus(
|
||||||
info.app_id.clone(),
|
app_id.clone(),
|
||||||
is_open && info.focused,
|
is_open && info.focused,
|
||||||
))
|
))
|
||||||
.await?;
|
.await?;
|
||||||
send_update(LauncherUpdate::Title(
|
send_update(LauncherUpdate::Title(
|
||||||
info.app_id.clone(),
|
app_id.clone(),
|
||||||
info.id,
|
info.id,
|
||||||
info.title.clone(),
|
info.title.clone(),
|
||||||
))
|
))
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
ToplevelEvent::Remove(info) => {
|
ToplevelEvent::Remove(info) => {
|
||||||
|
let app_id = resolve_app_id(&info.app_id);
|
||||||
let remove_item = {
|
let remove_item = {
|
||||||
let mut items = lock!(items);
|
let mut items = lock!(items);
|
||||||
let item = items.get_mut(&info.app_id);
|
match items.get_mut(&app_id) {
|
||||||
match item {
|
|
||||||
Some(item) => {
|
Some(item) => {
|
||||||
item.unmerge_toplevel(&info);
|
item.unmerge_toplevel(&info);
|
||||||
|
|
||||||
if item.windows.is_empty() {
|
if item.windows.is_empty() {
|
||||||
items.shift_remove(&info.app_id);
|
items.shift_remove(&app_id);
|
||||||
Some(ItemOrWindowId::Item)
|
Some(ItemOrWindowId::Item)
|
||||||
} else {
|
} else {
|
||||||
Some(ItemOrWindowId::Window)
|
Some(ItemOrWindowId::Window)
|
||||||
|
@ -357,14 +380,10 @@ impl Module<gtk::Box> for LauncherModule {
|
||||||
|
|
||||||
match remove_item {
|
match remove_item {
|
||||||
Some(ItemOrWindowId::Item) => {
|
Some(ItemOrWindowId::Item) => {
|
||||||
send_update(LauncherUpdate::RemoveItem(info.app_id.clone()))
|
send_update(LauncherUpdate::RemoveItem(app_id.clone())).await?;
|
||||||
.await?;
|
|
||||||
}
|
}
|
||||||
Some(ItemOrWindowId::Window) => {
|
Some(ItemOrWindowId::Window) => {
|
||||||
send_update(LauncherUpdate::RemoveWindow(
|
send_update(LauncherUpdate::RemoveWindow(app_id.clone(), info.id))
|
||||||
info.app_id.clone(),
|
|
||||||
info.id,
|
|
||||||
))
|
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
None => {}
|
None => {}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue