Skip to content

Commit f182f2b

Browse files
committed
Fixed removed floating notifications sometimes being rendered for a few ticks
Caused when the notification windows input region is set right after a notification has been removed, before the AnimatedLists size-allocation has been re-computed. Can be reproduced by running this command in sway: `notify-send "test 1" -u critical; notify-send "test 2" -t 2000; sleep 1; swaymsg "output * power off"; notify-send "test 3" -t 500; sleep 3; swaymsg "output * power on"`
1 parent 3258727 commit f182f2b

File tree

2 files changed

+30
-11
lines changed

2 files changed

+30
-11
lines changed

src/animatedList/animatedList.vala

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -674,17 +674,29 @@ public class AnimatedList : Gtk.Widget, Gtk.Scrollable {
674674

675675
AnimatedListItem ?item = try_get_ancestor (widget);
676676
if (item == null) {
677+
warn_if_reached ();
677678
return false;
678679
}
679680

680681
// Will unparent itself when done animating
681-
bool result = yield item.removed (transition_children && transition);
682+
if (!yield item.removed (transition_children && transition)) {
683+
debug ("Skipping extra removal of AnimatedListItem");
684+
return false;
685+
}
682686

683687
item.unparent ();
684688
children.remove (item);
685689
n_children--;
690+
691+
// Make sure that we don't render/compute the bounds of this destroyed widget.
692+
// queue_resize might not finish in-time before iterating the visible children
693+
unowned List<unowned AnimatedListItem> visible_item = visible_children.find (item);
694+
if (visible_item != null) {
695+
visible_children.delete_link (visible_item);
696+
}
697+
686698
queue_resize ();
687-
return result;
699+
return true;
688700
}
689701

690702
public bool move_to_beginning (Gtk.Widget widget, bool scroll_to) {

src/notificationWindow/notificationWindow.vala

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -178,19 +178,26 @@ namespace SwayNotificationCenter {
178178
}
179179

180180
Cairo.Region region = new Cairo.Region ();
181-
foreach (AnimatedListItem item in list.visible_children) {
181+
foreach (unowned AnimatedListItem item in list.visible_children) {
182+
if (item == null || !(item is Object)) {
183+
critical (
184+
"Could not iter over AnimatedListItem (%p) while setting input region\n",
185+
item);
186+
continue;
187+
}
182188
if (item.destroying) {
183189
continue;
184190
}
185191
Graphene.Rect out_bounds;
186-
item.compute_bounds (this, out out_bounds);
187-
Cairo.RectangleInt item_rect = Cairo.RectangleInt () {
188-
x = (int) out_bounds.get_x (),
189-
y = (int) out_bounds.get_y (),
190-
width = (int) out_bounds.get_width (),
191-
height = (int) out_bounds.get_height (),
192-
};
193-
region.union_rectangle (item_rect);
192+
if (item.compute_bounds (this, out out_bounds)) {
193+
Cairo.RectangleInt item_rect = Cairo.RectangleInt () {
194+
x = (int) out_bounds.get_x (),
195+
y = (int) out_bounds.get_y (),
196+
width = (int) out_bounds.get_width (),
197+
height = (int) out_bounds.get_height (),
198+
};
199+
region.union_rectangle (item_rect);
200+
}
194201
}
195202

196203
// The input region should only cover each preview widget

0 commit comments

Comments
 (0)