From 9f6e3f5d3100b992651f0b2cd97f72fef7005743 Mon Sep 17 00:00:00 2001 From: "Ospald, Julian" Date: Mon, 10 Jul 2017 11:53:22 +0200 Subject: [PATCH] Add Drop impl for Notification The notification is now unrefed via the GObject system. --- Cargo.toml | 1 + src/lib.rs | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index 83fcf510..ae16f34f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,5 +16,6 @@ libnotify-sys = "^0.5.0" gdk-pixbuf = "^0.1.3" gdk-pixbuf-sys = "^0.3.4" glib-sys = "^0.3.4" +gobject-sys = "^0.3.4" gtypes = "^0.2.0" glib = "^0.1.3" diff --git a/src/lib.rs b/src/lib.rs index 595267ac..37206535 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -26,6 +26,7 @@ #[macro_use] extern crate error_chain; +extern crate gobject_sys; extern crate gdk_pixbuf; extern crate gdk_pixbuf_sys; extern crate glib; @@ -91,6 +92,23 @@ pub struct Notification { handle: *mut sys::NotifyNotification, } +impl Drop for Notification { + fn drop(&mut self) { + unsafe { + if gobject_sys::g_type_check_instance_is_a( + self.handle as *mut gobject_sys::GTypeInstance, + gobject_sys::G_TYPE_OBJECT, + ) == FALSE + { + panic!("Not a GObject!"); + } + let gobject = self.handle as + *mut gobject_sys::GObject; + gobject_sys::g_object_unref(gobject); + } + } +} + impl Notification { /// Creates a new Notification. ///