Add Drop impl for Notification

The notification is now unrefed via the GObject system.
This commit is contained in:
Ospald, Julian 2017-07-10 11:53:22 +02:00
parent 437f2cc756
commit 9f6e3f5d31
2 changed files with 19 additions and 0 deletions

View File

@ -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"

View File

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