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. ///