gtk4_session_lock/auto/instance.rs
1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from ..
3// from ../gir-files
4// DO NOT EDIT
5
6use crate::{ffi};
7use glib::{object::ObjectType as _,prelude::*,signal::{connect_raw, SignalHandlerId},translate::*};
8use std::{boxed::Box as Box_};
9
10glib::wrapper! {
11 /// An instance of the object used to control locking the screen.
12 /// Multiple instances can exist at once, but only one can be locked at a time.
13 ///
14 /// ## Signals
15 ///
16 ///
17 /// #### `failed`
18 /// The ::failed signal is fired when the lock could not be acquired.
19 ///
20 ///
21 ///
22 ///
23 /// #### `locked`
24 /// The ::locked signal is fired when the screen is successfully locked.
25 ///
26 ///
27 ///
28 ///
29 /// #### `monitor`
30 /// The ::monitor signal is fired once for each monitor that exists when a lock is started, and then whenever a new
31 /// monitor is detected during the lock. You generally want to call [`Instance::assign_window_to_monitor()`][crate::Instance::assign_window_to_monitor()]
32 /// once in the handler for this signal with a newly created window and the given monitor.
33 ///
34 /// This API does not directly tell you when a monitor is removed (GTK APIs can be used for that), however the window you
35 /// send to [`Instance::assign_window_to_monitor()`][crate::Instance::assign_window_to_monitor()] will be automatically unmapped and dereferenced when its
36 /// monitor is removed or the screen is unlocked.
37 ///
38 ///
39 ///
40 ///
41 /// #### `unlocked`
42 /// The ::unlocked signal is fired when the session is unlocked, which may have been caused by a call to
43 /// [`Instance::unlock()`][crate::Instance::unlock()] or by the compositor.
44 ///
45 ///
46 #[doc(alias = "GtkSessionLockInstance")]
47 pub struct Instance(Object<ffi::GtkSessionLockInstance, ffi::GtkSessionLockInstanceClass>);
48
49 match fn {
50 type_ => || ffi::gtk_session_lock_instance_get_type(),
51 }
52}
53
54impl Instance {
55 ///
56 /// # Returns
57 ///
58 /// new session lock instance
59 #[doc(alias = "gtk_session_lock_instance_new")]
60 pub fn new() -> Instance {
61 assert_initialized_main_thread!();
62 unsafe {
63 from_glib_full(ffi::gtk_session_lock_instance_new())
64 }
65 }
66
67 /// This must be called with a different unrealized window once for each monitor immediately after calling
68 /// `gtk_session_lock_lock()`. Hiding a window that is active on a monitor or not letting a window be resized by the
69 /// library is not allowed (may result in a Wayland protocol error). The window will be unmapped and `gtk_window_destroy()`
70 /// called on it when the current lock ends.
71 /// ## `window`
72 /// The GTK Window to use as a lock surface
73 /// ## `monitor`
74 /// The monitor to show it on
75 #[doc(alias = "gtk_session_lock_instance_assign_window_to_monitor")]
76 pub fn assign_window_to_monitor(&self, window: &impl IsA<gtk::Window>, monitor: &gdk::Monitor) {
77 unsafe {
78 ffi::gtk_session_lock_instance_assign_window_to_monitor(self.to_glib_none().0, window.as_ref().to_glib_none().0, monitor.to_glib_none().0);
79 }
80 }
81
82 /// Returns if this instance currently holds a lock.
83 #[doc(alias = "gtk_session_lock_instance_is_locked")]
84 pub fn is_locked(&self) -> bool {
85 unsafe {
86 from_glib(ffi::gtk_session_lock_instance_is_locked(self.to_glib_none().0))
87 }
88 }
89
90 /// Lock the screen. This should be called before assigning any windows to monitors. If this function fails the ::failed
91 /// signal is emitted, if it succeeds the ::locked signal is emitted. The ::failed signal may be emitted before the
92 /// function returns (for example, if another [`Instance`][crate::Instance] holds a lock) or later (if another process holds a
93 /// lock). The only case where neither signal is triggered is if the instance is already locked.
94 ///
95 /// # Returns
96 ///
97 /// false on immediate fail, true if lock acquisition was successfully started
98 #[doc(alias = "gtk_session_lock_instance_lock")]
99 pub fn lock(&self) -> bool {
100 unsafe {
101 from_glib(ffi::gtk_session_lock_instance_lock(self.to_glib_none().0))
102 }
103 }
104
105 /// If the screen is locked by this instance unlocks it and fires ::unlocked. Otherwise has no effect
106 #[doc(alias = "gtk_session_lock_instance_unlock")]
107 pub fn unlock(&self) {
108 unsafe {
109 ffi::gtk_session_lock_instance_unlock(self.to_glib_none().0);
110 }
111 }
112
113 /// The ::failed signal is fired when the lock could not be acquired.
114 #[doc(alias = "failed")]
115 pub fn connect_failed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
116 unsafe extern "C" fn failed_trampoline<F: Fn(&Instance) + 'static>(this: *mut ffi::GtkSessionLockInstance, f: glib::ffi::gpointer) {
117 let f: &F = &*(f as *const F);
118 f(&from_glib_borrow(this))
119 }
120 unsafe {
121 let f: Box_<F> = Box_::new(f);
122 connect_raw(self.as_ptr() as *mut _, c"failed".as_ptr() as *const _,
123 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(failed_trampoline::<F> as *const ())), Box_::into_raw(f))
124 }
125 }
126
127 /// The ::locked signal is fired when the screen is successfully locked.
128 #[doc(alias = "locked")]
129 pub fn connect_locked<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
130 unsafe extern "C" fn locked_trampoline<F: Fn(&Instance) + 'static>(this: *mut ffi::GtkSessionLockInstance, f: glib::ffi::gpointer) {
131 let f: &F = &*(f as *const F);
132 f(&from_glib_borrow(this))
133 }
134 unsafe {
135 let f: Box_<F> = Box_::new(f);
136 connect_raw(self.as_ptr() as *mut _, c"locked".as_ptr() as *const _,
137 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(locked_trampoline::<F> as *const ())), Box_::into_raw(f))
138 }
139 }
140
141 /// The ::monitor signal is fired once for each monitor that exists when a lock is started, and then whenever a new
142 /// monitor is detected during the lock. You generally want to call [`assign_window_to_monitor()`][Self::assign_window_to_monitor()]
143 /// once in the handler for this signal with a newly created window and the given monitor.
144 ///
145 /// This API does not directly tell you when a monitor is removed (GTK APIs can be used for that), however the window you
146 /// send to [`assign_window_to_monitor()`][Self::assign_window_to_monitor()] will be automatically unmapped and dereferenced when its
147 /// monitor is removed or the screen is unlocked.
148 /// ## `monitor`
149 /// the [`gdk::Monitor`][crate::gdk::Monitor] that exists or was added
150 #[cfg(feature = "v1_2")]
151 #[cfg_attr(docsrs, doc(cfg(feature = "v1_2")))]
152 #[doc(alias = "monitor")]
153 pub fn connect_monitor<F: Fn(&Self, &gdk::Monitor) + 'static>(&self, f: F) -> SignalHandlerId {
154 unsafe extern "C" fn monitor_trampoline<F: Fn(&Instance, &gdk::Monitor) + 'static>(this: *mut ffi::GtkSessionLockInstance, monitor: *mut gdk::ffi::GdkMonitor, f: glib::ffi::gpointer) {
155 let f: &F = &*(f as *const F);
156 f(&from_glib_borrow(this), &from_glib_borrow(monitor))
157 }
158 unsafe {
159 let f: Box_<F> = Box_::new(f);
160 connect_raw(self.as_ptr() as *mut _, c"monitor".as_ptr() as *const _,
161 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(monitor_trampoline::<F> as *const ())), Box_::into_raw(f))
162 }
163 }
164
165 /// The ::unlocked signal is fired when the session is unlocked, which may have been caused by a call to
166 /// [`unlock()`][Self::unlock()] or by the compositor.
167 #[doc(alias = "unlocked")]
168 pub fn connect_unlocked<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
169 unsafe extern "C" fn unlocked_trampoline<F: Fn(&Instance) + 'static>(this: *mut ffi::GtkSessionLockInstance, f: glib::ffi::gpointer) {
170 let f: &F = &*(f as *const F);
171 f(&from_glib_borrow(this))
172 }
173 unsafe {
174 let f: Box_<F> = Box_::new(f);
175 connect_raw(self.as_ptr() as *mut _, c"unlocked".as_ptr() as *const _,
176 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(unlocked_trampoline::<F> as *const ())), Box_::into_raw(f))
177 }
178 }
179}
180
181#[cfg(feature = "v1_1")]
182#[cfg_attr(docsrs, doc(cfg(feature = "v1_1")))]
183impl Default for Instance {
184 fn default() -> Self {
185 Self::new()
186 }
187 }