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 22, 2025
1 parent 37814e4 commit e7fef77
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion gio/src/subclass/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

use std::{ffi::OsString, fmt, ops::Deref, ptr};

use glib::{prelude::*, subclass::prelude::*, translate::*, Error, ExitCode, VariantDict};
use glib::{
prelude::*, subclass::prelude::*, translate::*, Error, ExitCode, Propagation, VariantDict,
};
use libc::{c_char, c_int, c_void};

use crate::{ffi, ActionGroup, ActionMap, Application, DBusConnection};
Expand Down Expand Up @@ -118,6 +120,10 @@ pub trait ApplicationImpl:
fn dbus_unregister(&self, connection: &DBusConnection, object_path: &str) {
self.parent_dbus_unregister(connection, object_path)
}

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

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

fn parent_name_lost(&self) -> Propagation {
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\"");
Propagation::from_glib(f(self
.obj()
.unsafe_cast_ref::<Application>()
.to_glib_none()
.0))
}
}
}

impl<T: ApplicationImpl> ApplicationImplExt for T {}
Expand All @@ -338,6 +359,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 +500,14 @@ 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();
imp.name_lost().into_glib()
}

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

0 comments on commit e7fef77

Please sign in to comment.