From 6fcefad3addb737ed7609ba58c21421973e7d0e5 Mon Sep 17 00:00:00 2001 From: lenemter Date: Mon, 6 Oct 2025 14:19:28 +0300 Subject: [PATCH] Fix memory leak --- src/AbstractBubble.vala | 45 ++++++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/src/AbstractBubble.vala b/src/AbstractBubble.vala index f0076bc..32d6b0e 100644 --- a/src/AbstractBubble.vala +++ b/src/AbstractBubble.vala @@ -1,5 +1,5 @@ /* -* Copyright 2020 elementary, Inc. (https://elementary.io) +* Copyright 2020-2025 elementary, Inc. (https://elementary.io) * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public @@ -31,6 +31,7 @@ public class Notifications.AbstractBubble : Gtk.Window { private Gtk.Revealer close_revealer; private Gtk.Box draw_area; + private Gtk.Overlay overlay; private uint timeout_id; @@ -72,7 +73,7 @@ public class Notifications.AbstractBubble : Gtk.Window { overflow = VISIBLE }; - var overlay = new Gtk.Overlay () { + overlay = new Gtk.Overlay () { child = draw_area }; overlay.add_overlay (close_revealer); @@ -92,11 +93,7 @@ public class Notifications.AbstractBubble : Gtk.Window { can_focus = false; set_titlebar (new Gtk.Grid ()); - carousel.page_changed.connect ((index) => { - if (index == 0) { - closed (Notifications.Server.CloseReason.DISMISSED); - } - }); + carousel.page_changed.connect (on_page_changed); close_button.clicked.connect (() => closed (Notifications.Server.CloseReason.DISMISSED)); var motion_controller = new Gtk.EventControllerMotion (); @@ -114,18 +111,7 @@ public class Notifications.AbstractBubble : Gtk.Window { } }); - carousel.notify["position"].connect (() => { - current_swipe_progress = carousel.position; - - if (desktop_panel != null) { - int left, right; - get_blur_margins (out left, out right); - - desktop_panel.add_blur (left, right, 16, 16, 9); - } else if (Gdk.Display.get_default () is Gdk.X11.Display) { - x11_update_mutter_hints (); - } - }); + carousel.notify["position"].connect (update_swipe_progress); transparency_settings.changed["use-transparency"].connect (update_transparency); update_transparency (); @@ -139,6 +125,27 @@ public class Notifications.AbstractBubble : Gtk.Window { } } + private void on_page_changed (Adw.Carousel carousel, uint index) { + if (carousel.get_nth_page (index) != overlay) { + closed (Notifications.Server.CloseReason.DISMISSED); + } + } + + private void update_swipe_progress (Object obj, ParamSpec pspec) { + var carousel = (Adw.Carousel) obj; + + current_swipe_progress = carousel.position; + + if (desktop_panel != null) { + int left, right; + get_blur_margins (out left, out right); + + desktop_panel.add_blur (left, right, 16, 16, 9); + } else if (Gdk.Display.get_default () is Gdk.X11.Display) { + x11_update_mutter_hints (); + } + } + public new void present () { if (timeout_id != 0) { Source.remove (timeout_id);