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