gdk4/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::{ffi, Display};
6use glib::{prelude::*, translate::*};
7
8glib::wrapper! {
9 /// Handles launching an application in a graphical context.
10 ///
11 /// It is an implementation of `GAppLaunchContext` that provides startup
12 /// notification and allows to launch applications on a specific workspace.
13 ///
14 /// ## Launching an application
15 ///
16 /// **⚠️ The following code is in c ⚠️**
17 ///
18 /// ```c
19 /// GdkAppLaunchContext *context;
20 ///
21 /// context = gdk_display_get_app_launch_context (display);
22 ///
23 /// gdk_app_launch_context_set_timestamp (gdk_event_get_time (event));
24 ///
25 /// if (!g_app_info_launch_default_for_uri ("http://www.gtk.org", context, &error))
26 /// g_warning ("Launching failed: %s\n", error->message);
27 ///
28 /// g_object_unref (context);
29 /// ```
30 ///
31 /// ## Properties
32 ///
33 ///
34 /// #### `display`
35 /// The display that the [`AppLaunchContext`][crate::AppLaunchContext] is on.
36 ///
37 /// Readable | Writeable | Construct Only
38 ///
39 /// # Implements
40 ///
41 /// [`GdkAppLaunchContextExt`][trait@crate::prelude::GdkAppLaunchContextExt], [`trait@gio::prelude::AppLaunchContextExt`]
42 #[doc(alias = "GdkAppLaunchContext")]
43 pub struct AppLaunchContext(Object<ffi::GdkAppLaunchContext>) @extends gio::AppLaunchContext;
44
45 match fn {
46 type_ => || ffi::gdk_app_launch_context_get_type(),
47 }
48}
49
50impl AppLaunchContext {
51 pub const NONE: Option<&'static AppLaunchContext> = None;
52}
53
54/// Trait containing all [`struct@AppLaunchContext`] methods.
55///
56/// # Implementors
57///
58/// [`AppLaunchContext`][struct@crate::AppLaunchContext]
59pub trait GdkAppLaunchContextExt: IsA<AppLaunchContext> + 'static {
60 /// Gets the [`Display`][crate::Display] that @self is for.
61 ///
62 /// # Returns
63 ///
64 /// the display of @self
65 #[doc(alias = "gdk_app_launch_context_get_display")]
66 #[doc(alias = "get_display")]
67 fn display(&self) -> Display {
68 unsafe {
69 from_glib_none(ffi::gdk_app_launch_context_get_display(
70 self.as_ref().to_glib_none().0,
71 ))
72 }
73 }
74
75 /// Sets the workspace on which applications will be launched.
76 ///
77 /// This only works when running under a window manager that
78 /// supports multiple workspaces, as described in the
79 /// [Extended Window Manager Hints](http://www.freedesktop.org/Standards/wm-spec).
80 /// Specifically this sets the `_NET_WM_DESKTOP` property described
81 /// in that spec.
82 ///
83 /// This only works when using the X11 backend.
84 ///
85 /// When the workspace is not specified or @desktop is set to -1,
86 /// it is up to the window manager to pick one, typically it will
87 /// be the current workspace.
88 /// ## `desktop`
89 /// the number of a workspace, or -1
90 #[doc(alias = "gdk_app_launch_context_set_desktop")]
91 fn set_desktop(&self, desktop: i32) {
92 unsafe {
93 ffi::gdk_app_launch_context_set_desktop(self.as_ref().to_glib_none().0, desktop);
94 }
95 }
96
97 /// Sets the icon for applications that are launched with this
98 /// context.
99 ///
100 /// Window Managers can use this information when displaying startup
101 /// notification.
102 ///
103 /// See also [`set_icon_name()`][Self::set_icon_name()].
104 /// ## `icon`
105 /// a `GIcon`
106 #[doc(alias = "gdk_app_launch_context_set_icon")]
107 fn set_icon(&self, icon: Option<&impl IsA<gio::Icon>>) {
108 unsafe {
109 ffi::gdk_app_launch_context_set_icon(
110 self.as_ref().to_glib_none().0,
111 icon.map(|p| p.as_ref()).to_glib_none().0,
112 );
113 }
114 }
115
116 /// Sets the icon for applications that are launched with this context.
117 ///
118 /// The @icon_name will be interpreted in the same way as the Icon field
119 /// in desktop files. See also [`set_icon()`][Self::set_icon()].
120 ///
121 /// If both @icon and @icon_name are set, the @icon_name takes priority.
122 /// If neither @icon or @icon_name is set, the icon is taken from either
123 /// the file that is passed to launched application or from the `GAppInfo`
124 /// for the launched application itself.
125 /// ## `icon_name`
126 /// an icon name
127 #[doc(alias = "gdk_app_launch_context_set_icon_name")]
128 fn set_icon_name(&self, icon_name: Option<&str>) {
129 unsafe {
130 ffi::gdk_app_launch_context_set_icon_name(
131 self.as_ref().to_glib_none().0,
132 icon_name.to_glib_none().0,
133 );
134 }
135 }
136
137 /// Sets the timestamp of @self.
138 ///
139 /// The timestamp should ideally be taken from the event that
140 /// triggered the launch.
141 ///
142 /// Window managers can use this information to avoid moving the
143 /// focus to the newly launched application when the user is busy
144 /// typing in another window. This is also known as 'focus stealing
145 /// prevention'.
146 /// ## `timestamp`
147 /// a timestamp
148 #[doc(alias = "gdk_app_launch_context_set_timestamp")]
149 fn set_timestamp(&self, timestamp: u32) {
150 unsafe {
151 ffi::gdk_app_launch_context_set_timestamp(self.as_ref().to_glib_none().0, timestamp);
152 }
153 }
154}
155
156impl<O: IsA<AppLaunchContext>> GdkAppLaunchContextExt for O {}