Skip to main content

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