ashpd/activation_token/
gtk4.rs1use glib::translate::from_glib_full;
2use gtk4::{gio, prelude::*};
3
4use crate::ActivationToken;
5
6impl ActivationToken {
7 #[cfg_attr(docsrs, doc(cfg(any(feature = "gtk4_wayland", feature = "gtk4_x11"))))]
12 pub fn from_window(widget: &impl IsA<::gtk4::Widget>) -> Option<Self> {
13 if glib::check_version(2, 76, 0).is_some() {
14 #[cfg(feature = "tracing")]
15 tracing::info!("Need glib 2.76 for XDG Activation protocol support");
16
17 return None;
18 }
19
20 let display = widget.as_ref().display();
21 let context = display.app_launch_context();
22
23 if glib::check_version(2, 82, 0).is_some() {
26 unsafe {
27 let klass: *mut gtk4::gio::ffi::GAppLaunchContextClass =
28 &context.class().parent()? as *const _ as *mut _;
29 let get_startup_notify_id = (*klass).get_startup_notify_id.as_ref()?;
30 from_glib_full::<_, Option<String>>(get_startup_notify_id(
31 context.as_ptr().cast(),
32 std::ptr::null_mut(),
33 std::ptr::null_mut(),
34 ))
35 }
36 } else {
37 context
38 .startup_notify_id(gio::AppInfo::NONE, &[])
39 .map(String::from)
40 }
41 .map(Self::from)
42 }
43}