Skip to content

Commit

Permalink
Bind name_lost vfunc
Browse files Browse the repository at this point in the history
  • Loading branch information
swsnr committed Jan 21, 2025
1 parent f40c7d4 commit 77d82c5
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions gio/src/subclass/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ pub trait ApplicationImpl:
fn dbus_unregister(&self, connection: &DBusConnection, object_path: &str) {
self.parent_dbus_unregister(connection, object_path)
}

fn name_lost(&self) -> bool {
self.parent_name_lost()
}
}

pub trait ApplicationImplExt: ApplicationImpl {
Expand Down Expand Up @@ -316,6 +320,21 @@ pub trait ApplicationImplExt: ApplicationImpl {
);
}
}

fn parent_name_lost(&self) -> bool {
unsafe {
let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GApplicationClass;
let f = (*parent_class)
.name_lost
.expect("No parent class implementation for \"name_lost\"");
if f(self.obj().unsafe_cast_ref::<Application>().to_glib_none().0) == glib::ffi::GTRUE {
true
} else {
false
}
}
}
}

impl<T: ApplicationImpl> ApplicationImplExt for T {}
Expand All @@ -338,6 +357,7 @@ unsafe impl<T: ApplicationImpl> IsSubclassable<T> for Application {
klass.handle_local_options = Some(application_handle_local_options::<T>);
klass.dbus_register = Some(application_dbus_register::<T>);
klass.dbus_unregister = Some(application_dbus_unregister::<T>);
klass.name_lost = Some(application_name_lost::<T>);
}
}

Expand Down Expand Up @@ -478,6 +498,18 @@ unsafe extern "C" fn application_dbus_unregister<T: ApplicationImpl>(
);
}

unsafe extern "C" fn application_name_lost<T: ApplicationImpl>(
ptr: *mut ffi::GApplication,
) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp();
if imp.name_lost() {
glib::ffi::GTRUE
} else {
glib::ffi::GFALSE
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down

0 comments on commit 77d82c5

Please sign in to comment.