gio/auto/app_launch_context.rs
1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// DO NOT EDIT
4
5use crate::{AppInfo, File, ffi};
6use glib::{
7 object::ObjectType as _,
8 prelude::*,
9 signal::{SignalHandlerId, connect_raw},
10 translate::*,
11};
12use std::boxed::Box as Box_;
13
14glib::wrapper! {
15 /// Integrating the launch with the launching application. This is used to
16 /// handle for instance startup notification and launching the new application
17 /// on the same screen as the launching window.
18 ///
19 /// ## Signals
20 ///
21 ///
22 /// #### `launch-failed`
23 /// The [`launch-failed`][struct@crate::AppLaunchContext#launch-failed] signal is emitted when a
24 /// [`AppInfo`][crate::AppInfo] launch fails. The startup notification id is provided,
25 /// so that the launcher can cancel the startup notification.
26 ///
27 /// Because a launch operation may involve spawning multiple instances of the
28 /// target application, you should expect this signal to be emitted multiple
29 /// times, one for each spawned instance.
30 ///
31 ///
32 ///
33 ///
34 /// #### `launch-started`
35 /// The [`launch-started`][struct@crate::AppLaunchContext#launch-started] signal is emitted when a
36 /// [`AppInfo`][crate::AppInfo] is about to be launched. If non-null the
37 /// @platform_data is an GVariant dictionary mapping strings to variants
38 /// (ie `a{sv}`), which contains additional, platform-specific data about this
39 /// launch. On UNIX, at least the `startup-notification-id` keys will be
40 /// present.
41 ///
42 /// The value of the `startup-notification-id` key (type `s`) is a startup
43 /// notification ID corresponding to the format from the [startup-notification
44 /// specification](https://specifications.freedesktop.org/startup-notification-spec/startup-notification-0.1.txt).
45 /// It allows tracking the progress of the launchee through startup.
46 ///
47 /// It is guaranteed that this signal is followed by either a
48 /// [`launched`][struct@crate::AppLaunchContext#launched] or
49 /// [`launch-failed`][struct@crate::AppLaunchContext#launch-failed] signal.
50 ///
51 /// Because a launch operation may involve spawning multiple instances of the
52 /// target application, you should expect this signal to be emitted multiple
53 /// times, one for each spawned instance.
54 ///
55 ///
56 ///
57 ///
58 /// #### `launched`
59 /// t known (for
60 /// example if the process was launched via D-Bus). The `pid` may not be
61 /// set at all in subsequent releases.
62 ///
63 /// On Windows, `pid` is guaranteed to be valid only for the duration of the
64 /// [`launched`][struct@crate::AppLaunchContext#launched] signal emission; after the signal
65 /// is emitted, GLib will call `spawn_close_pid()`. If you need to
66 /// keep the `alias::GLib.Pid` after the signal has been emitted, then you can
67 /// duplicate `pid` using `DuplicateHandle()`.
68 ///
69 ///
70 ///
71 /// # Implements
72 ///
73 /// [`AppLaunchContextExt`][trait@crate::prelude::AppLaunchContextExt], [`trait@glib::ObjectExt`]
74 #[doc(alias = "GAppLaunchContext")]
75 pub struct AppLaunchContext(Object<ffi::GAppLaunchContext, ffi::GAppLaunchContextClass>);
76
77 match fn {
78 type_ => || ffi::g_app_launch_context_get_type(),
79 }
80}
81
82impl AppLaunchContext {
83 pub const NONE: Option<&'static AppLaunchContext> = None;
84
85 /// Creates a new application launch context. This is not normally used,
86 /// instead you instantiate a subclass of this, such as
87 /// [`GdkAppLaunchContext`](https://docs.gtk.org/gdk4/class.AppLaunchContext.html).
88 ///
89 /// # Returns
90 ///
91 /// a launch context.
92 #[doc(alias = "g_app_launch_context_new")]
93 pub fn new() -> AppLaunchContext {
94 unsafe { from_glib_full(ffi::g_app_launch_context_new()) }
95 }
96}
97
98impl Default for AppLaunchContext {
99 fn default() -> Self {
100 Self::new()
101 }
102}
103
104/// Trait containing all [`struct@AppLaunchContext`] methods.
105///
106/// # Implementors
107///
108/// [`AppLaunchContext`][struct@crate::AppLaunchContext]
109pub trait AppLaunchContextExt: IsA<AppLaunchContext> + 'static {
110 /// Gets the display string for the @self. This is used to ensure new
111 /// applications are started on the same display as the launching
112 /// application, by setting the `DISPLAY` environment variable.
113 /// ## `info`
114 /// the app info
115 /// ## `files`
116 /// a list of [`File`][crate::File] objects
117 ///
118 /// # Returns
119 ///
120 /// a display string for the display.
121 #[doc(alias = "g_app_launch_context_get_display")]
122 #[doc(alias = "get_display")]
123 fn display(&self, info: &impl IsA<AppInfo>, files: &[File]) -> Option<glib::GString> {
124 unsafe {
125 from_glib_full(ffi::g_app_launch_context_get_display(
126 self.as_ref().to_glib_none().0,
127 info.as_ref().to_glib_none().0,
128 files.to_glib_none().0,
129 ))
130 }
131 }
132
133 /// Gets the complete environment variable list to be passed to
134 /// the child process when @self is used to launch an application.
135 /// This is a `NULL`-terminated array of strings, where each string has
136 /// the form `KEY=VALUE`.
137 ///
138 /// # Returns
139 ///
140 /// s environment
141 #[doc(alias = "g_app_launch_context_get_environment")]
142 #[doc(alias = "get_environment")]
143 fn environment(&self) -> Vec<std::ffi::OsString> {
144 unsafe {
145 FromGlibPtrContainer::from_glib_full(ffi::g_app_launch_context_get_environment(
146 self.as_ref().to_glib_none().0,
147 ))
148 }
149 }
150
151 /// s not supported by the backend,
152 /// the returned token will be `NULL`.
153 /// ## `info`
154 /// the app info
155 /// ## `files`
156 /// a list of [`File`][crate::File] objects
157 ///
158 /// # Returns
159 ///
160 /// a startup notification ID for the application, or `NULL` if
161 /// not supported.
162 #[doc(alias = "g_app_launch_context_get_startup_notify_id")]
163 #[doc(alias = "get_startup_notify_id")]
164 fn startup_notify_id(
165 &self,
166 info: Option<&impl IsA<AppInfo>>,
167 files: &[File],
168 ) -> Option<glib::GString> {
169 unsafe {
170 from_glib_full(ffi::g_app_launch_context_get_startup_notify_id(
171 self.as_ref().to_glib_none().0,
172 info.map(|p| p.as_ref()).to_glib_none().0,
173 files.to_glib_none().0,
174 ))
175 }
176 }
177
178 /// Called when an application has failed to launch, so that it can cancel
179 /// the application startup notification started in
180 /// [`startup_notify_id()`][Self::startup_notify_id()].
181 /// ## `startup_notify_id`
182 /// the startup notification id that was returned by
183 /// [`startup_notify_id()`][Self::startup_notify_id()].
184 #[doc(alias = "g_app_launch_context_launch_failed")]
185 fn launch_failed(&self, startup_notify_id: &str) {
186 unsafe {
187 ffi::g_app_launch_context_launch_failed(
188 self.as_ref().to_glib_none().0,
189 startup_notify_id.to_glib_none().0,
190 );
191 }
192 }
193
194 /// s environment when
195 /// @self is used to launch an application.
196 /// ## `variable`
197 /// the environment variable to set
198 /// ## `value`
199 /// the value for to set the variable to.
200 #[doc(alias = "g_app_launch_context_setenv")]
201 fn setenv(&self, variable: impl AsRef<std::ffi::OsStr>, value: impl AsRef<std::ffi::OsStr>) {
202 unsafe {
203 ffi::g_app_launch_context_setenv(
204 self.as_ref().to_glib_none().0,
205 variable.as_ref().to_glib_none().0,
206 value.as_ref().to_glib_none().0,
207 );
208 }
209 }
210
211 /// s environment when @self
212 /// is used to launch an application.
213 /// ## `variable`
214 /// the environment variable to remove
215 #[doc(alias = "g_app_launch_context_unsetenv")]
216 fn unsetenv(&self, variable: impl AsRef<std::ffi::OsStr>) {
217 unsafe {
218 ffi::g_app_launch_context_unsetenv(
219 self.as_ref().to_glib_none().0,
220 variable.as_ref().to_glib_none().0,
221 );
222 }
223 }
224
225 /// The [`launch-failed`][struct@crate::AppLaunchContext#launch-failed] signal is emitted when a
226 /// [`AppInfo`][crate::AppInfo] launch fails. The startup notification id is provided,
227 /// so that the launcher can cancel the startup notification.
228 ///
229 /// Because a launch operation may involve spawning multiple instances of the
230 /// target application, you should expect this signal to be emitted multiple
231 /// times, one for each spawned instance.
232 /// ## `startup_notify_id`
233 /// the startup notification id for the failed launch
234 #[doc(alias = "launch-failed")]
235 fn connect_launch_failed<F: Fn(&Self, &str) + 'static>(&self, f: F) -> SignalHandlerId {
236 unsafe extern "C" fn launch_failed_trampoline<
237 P: IsA<AppLaunchContext>,
238 F: Fn(&P, &str) + 'static,
239 >(
240 this: *mut ffi::GAppLaunchContext,
241 startup_notify_id: *mut std::ffi::c_char,
242 f: glib::ffi::gpointer,
243 ) {
244 unsafe {
245 let f: &F = &*(f as *const F);
246 f(
247 AppLaunchContext::from_glib_borrow(this).unsafe_cast_ref(),
248 &glib::GString::from_glib_borrow(startup_notify_id),
249 )
250 }
251 }
252 unsafe {
253 let f: Box_<F> = Box_::new(f);
254 connect_raw(
255 self.as_ptr() as *mut _,
256 c"launch-failed".as_ptr(),
257 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
258 launch_failed_trampoline::<Self, F> as *const (),
259 )),
260 Box_::into_raw(f),
261 )
262 }
263 }
264
265 /// The [`launch-started`][struct@crate::AppLaunchContext#launch-started] signal is emitted when a
266 /// [`AppInfo`][crate::AppInfo] is about to be launched. If non-null the
267 /// @platform_data is an GVariant dictionary mapping strings to variants
268 /// (ie `a{sv}`), which contains additional, platform-specific data about this
269 /// launch. On UNIX, at least the `startup-notification-id` keys will be
270 /// present.
271 ///
272 /// The value of the `startup-notification-id` key (type `s`) is a startup
273 /// notification ID corresponding to the format from the [startup-notification
274 /// specification](https://specifications.freedesktop.org/startup-notification-spec/startup-notification-0.1.txt).
275 /// It allows tracking the progress of the launchee through startup.
276 ///
277 /// It is guaranteed that this signal is followed by either a
278 /// [`launched`][struct@crate::AppLaunchContext#launched] or
279 /// [`launch-failed`][struct@crate::AppLaunchContext#launch-failed] signal.
280 ///
281 /// Because a launch operation may involve spawning multiple instances of the
282 /// target application, you should expect this signal to be emitted multiple
283 /// times, one for each spawned instance.
284 /// ## `info`
285 /// the [`AppInfo`][crate::AppInfo] that is about to be launched
286 /// ## `platform_data`
287 /// additional platform-specific data for this launch
288 #[cfg(feature = "v2_72")]
289 #[cfg_attr(docsrs, doc(cfg(feature = "v2_72")))]
290 #[doc(alias = "launch-started")]
291 fn connect_launch_started<F: Fn(&Self, &AppInfo, Option<&glib::Variant>) + 'static>(
292 &self,
293 f: F,
294 ) -> SignalHandlerId {
295 unsafe extern "C" fn launch_started_trampoline<
296 P: IsA<AppLaunchContext>,
297 F: Fn(&P, &AppInfo, Option<&glib::Variant>) + 'static,
298 >(
299 this: *mut ffi::GAppLaunchContext,
300 info: *mut ffi::GAppInfo,
301 platform_data: *mut glib::ffi::GVariant,
302 f: glib::ffi::gpointer,
303 ) {
304 unsafe {
305 let f: &F = &*(f as *const F);
306 f(
307 AppLaunchContext::from_glib_borrow(this).unsafe_cast_ref(),
308 &from_glib_borrow(info),
309 Option::<glib::Variant>::from_glib_borrow(platform_data)
310 .as_ref()
311 .as_ref(),
312 )
313 }
314 }
315 unsafe {
316 let f: Box_<F> = Box_::new(f);
317 connect_raw(
318 self.as_ptr() as *mut _,
319 c"launch-started".as_ptr(),
320 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
321 launch_started_trampoline::<Self, F> as *const (),
322 )),
323 Box_::into_raw(f),
324 )
325 }
326 }
327
328 /// t known (for
329 /// example if the process was launched via D-Bus). The `pid` may not be
330 /// set at all in subsequent releases.
331 ///
332 /// On Windows, `pid` is guaranteed to be valid only for the duration of the
333 /// [`launched`][struct@crate::AppLaunchContext#launched] signal emission; after the signal
334 /// is emitted, GLib will call `spawn_close_pid()`. If you need to
335 /// keep the `alias::GLib.Pid` after the signal has been emitted, then you can
336 /// duplicate `pid` using `DuplicateHandle()`.
337 /// ## `info`
338 /// the [`AppInfo`][crate::AppInfo] that was just launched
339 /// ## `platform_data`
340 /// additional platform-specific data for this launch
341 #[doc(alias = "launched")]
342 fn connect_launched<F: Fn(&Self, &AppInfo, &glib::Variant) + 'static>(
343 &self,
344 f: F,
345 ) -> SignalHandlerId {
346 unsafe extern "C" fn launched_trampoline<
347 P: IsA<AppLaunchContext>,
348 F: Fn(&P, &AppInfo, &glib::Variant) + 'static,
349 >(
350 this: *mut ffi::GAppLaunchContext,
351 info: *mut ffi::GAppInfo,
352 platform_data: *mut glib::ffi::GVariant,
353 f: glib::ffi::gpointer,
354 ) {
355 unsafe {
356 let f: &F = &*(f as *const F);
357 f(
358 AppLaunchContext::from_glib_borrow(this).unsafe_cast_ref(),
359 &from_glib_borrow(info),
360 &from_glib_borrow(platform_data),
361 )
362 }
363 }
364 unsafe {
365 let f: Box_<F> = Box_::new(f);
366 connect_raw(
367 self.as_ptr() as *mut _,
368 c"launched".as_ptr(),
369 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
370 launched_trampoline::<Self, F> as *const (),
371 )),
372 Box_::into_raw(f),
373 )
374 }
375 }
376}
377
378impl<O: IsA<AppLaunchContext>> AppLaunchContextExt for O {}