1
0
Fork 0
mirror of https://github.com/Zedfrigg/ironbar.git synced 2025-07-01 18:51:04 +02:00

fix(focused): clear when no window is focused

Fixes #337
This commit is contained in:
Jake Stanger 2023-10-19 20:21:27 +01:00
parent 8fc516a85d
commit f24b21d242
No known key found for this signature in database
GPG key ID: C51FC8F9CB0BEA61

View file

@ -49,7 +49,7 @@ const fn default_icon_size() -> i32 {
} }
impl Module<gtk::Box> for FocusedModule { impl Module<gtk::Box> for FocusedModule {
type SendMessage = (String, String); type SendMessage = Option<(String, String)>;
type ReceiveMessage = (); type ReceiveMessage = ();
fn name() -> &'static str { fn name() -> &'static str {
@ -78,21 +78,34 @@ impl Module<gtk::Box> for FocusedModule {
if let Some(focused) = focused { if let Some(focused) = focused {
try_send!( try_send!(
tx, tx,
ModuleUpdateEvent::Update((focused.title.clone(), focused.app_id)) ModuleUpdateEvent::Update(Some((focused.title.clone(), focused.app_id)))
); );
}; };
while let Ok(event) = wlrx.recv().await { while let Ok(event) = wlrx.recv().await {
if let ToplevelEvent::Update(handle) = event { match event {
let info = handle.info().unwrap_or_default(); ToplevelEvent::Update(handle) => {
let info = handle.info().unwrap_or_default();
if info.focused { if info.focused {
debug!("Changing focus"); debug!("Changing focus");
send_async!( send_async!(
tx, tx,
ModuleUpdateEvent::Update((info.title.clone(), info.app_id.clone())) ModuleUpdateEvent::Update(Some((
); info.title.clone(),
info.app_id.clone()
)))
);
}
} }
ToplevelEvent::Remove(handle) => {
let info = handle.info().unwrap_or_default();
if info.focused {
debug!("Clearing focus");
send_async!(tx, ModuleUpdateEvent::Update(None));
}
}
ToplevelEvent::New(_) => {}
} }
} }
}); });
@ -126,18 +139,24 @@ impl Module<gtk::Box> for FocusedModule {
{ {
let icon_theme = icon_theme.clone(); let icon_theme = icon_theme.clone();
context.widget_rx.attach(None, move |(name, id)| { context.widget_rx.attach(None, move |data| {
if self.show_icon { if let Some((name, id)) = data {
match ImageProvider::parse(&id, &icon_theme, true, self.icon_size) if self.show_icon {
.map(|image| image.load_into_image(icon.clone())) match ImageProvider::parse(&id, &icon_theme, true, self.icon_size)
{ .map(|image| image.load_into_image(icon.clone()))
Some(Ok(_)) => icon.show(), {
_ => icon.hide(), Some(Ok(())) => icon.show(),
_ => icon.hide(),
}
} }
}
if self.show_title { if self.show_title {
label.set_label(&name); label.show();
label.set_label(&name);
}
} else {
icon.hide();
label.hide();
} }
Continue(true) Continue(true)