Skip to content

Commit

Permalink
Fix replacement not updating layout properly (#145).
Browse files Browse the repository at this point in the history
  • Loading branch information
Toqozz committed Jun 5, 2024
1 parent 6bf4ed3 commit 4cc6446
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 21 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "wired"
version = "0.10.6"
version = "0.10.7"
authors = ["Michael Palmos <[email protected]>"]
edition = "2021"

Expand Down
50 changes: 32 additions & 18 deletions src/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,28 +151,30 @@ impl NotifyWindowManager {
return;
}

// Find any windows that have the same id, or the same app name and tag.
// If one exists then we should replace that (if replacing is enabled).
let mut maybe_windows = vec![];
//let mut maybe_window = None;
for w in self.layout_windows.values_mut().flatten() {
if notification_meets_layout_criteria(w.layout.as_ref().unwrap(), &notification)
&& ((w.notification.id == notification.id && cfg.replacing_enabled)
|| (w.notification.app_name == notification.app_name
// We need to match a layout at least to be able to show anything -- new or otherwise.
if let Some(layout) = find_matching_layout(&notification) {
// Find any windows that have the same id, or the same app name and tag.
// If one exists then we should replace that (if replacing is enabled).
let mut maybe_windows = vec![];
for w in self.layout_windows.values_mut().flatten() {
let id_matches = (w.notification.id == notification.id) && cfg.replacing_enabled;
let tag_matches =
w.notification.app_name == notification.app_name
&& w.notification.tag.is_some()
&& w.notification.tag == notification.tag))
{
maybe_windows.push(w);
//maybe_window = Some(w)
&& w.notification.tag == notification.tag;

if id_matches || tag_matches {
maybe_windows.push(w);
}
}
}

if !maybe_windows.is_empty() {
for w in maybe_windows {
w.replace_notification(notification.clone());
if !maybe_windows.is_empty() {
for w in maybe_windows{
w.replace_notification(notification.clone(), layout.clone());
}
} else {
self.new_notification(notification, el);
}
} else {
self.new_notification(notification, el);
}
}

Expand Down Expand Up @@ -635,6 +637,18 @@ fn notification_meets_layout_criteria(root: &LayoutBlock, notification: &Notific
false
}

fn find_matching_layout(notification: &Notification) -> Option<&LayoutBlock> {
for layout in &Config::get().layouts {
// Spawn a new window for each "root" layout that should be drawn.
// If this layout doesn't meet any criteria, skip, obviously.
if notification_meets_layout_criteria(layout, notification) {
return Some(layout)
}
}

None
}

// Checks if this block should be drawn (according to render criteria for each block).
// The root block is handled differently.
// If the root block doesn't meet criteria, then don't draw at all.
Expand Down
4 changes: 2 additions & 2 deletions src/rendering/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ impl NotifyWindow {
window
}

pub fn replace_notification(&mut self, new_notification: Notification) {
pub fn replace_notification(&mut self, new_notification: Notification, new_layout: LayoutBlock) {
let cfg = Config::get();

self.notification = new_notification;
Expand All @@ -237,7 +237,7 @@ impl NotifyWindow {

// As above. May be valuable to put this into a function like `prepare_notification` or
// something if we keep changing stuff.
let mut layout = self.layout_take();
let mut layout = new_layout;
let rect = layout.predict_rect_tree_and_init(
self,
&Rect::new(0.0, 0.0, width, height),
Expand Down

0 comments on commit 4cc6446

Please sign in to comment.