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