use glib::translate::from_glib_full;
use gtk4::{gio, prelude::*};
use crate::ActivationToken;
impl ActivationToken {
#[cfg_attr(docsrs, doc(cfg(any(feature = "gtk4_wayland", feature = "gtk4_x11"))))]
pub fn from_window(widget: &impl IsA<::gtk4::Widget>) -> Option<Self> {
if glib::check_version(2, 76, 0).is_some() {
#[cfg(feature = "tracing")]
tracing::info!("Need glib 2.76 for XDG Activation protocol support");
return None;
}
let display = widget.as_ref().display();
let context = display.app_launch_context();
if glib::check_version(2, 82, 0).is_some() {
unsafe {
let klass: *mut gtk4::gio::ffi::GAppLaunchContextClass =
&context.class().parent()? as *const _ as *mut _;
let get_startup_notify_id = (*klass).get_startup_notify_id.as_ref()?;
from_glib_full::<_, Option<String>>(get_startup_notify_id(
context.as_ptr().cast(),
std::ptr::null_mut(),
std::ptr::null_mut(),
))
}
} else {
context
.startup_notify_id(gio::AppInfo::NONE, &[])
.map(String::from)
}
.map(Self::from)
}
}