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
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from ..
// from ../gir-files
// DO NOT EDIT
use crate::{ffi};
use glib::{object::ObjectType as _,prelude::*,signal::{connect_raw, SignalHandlerId},translate::*};
use std::{boxed::Box as Box_};
glib::wrapper! {
/// An instance of the object used to control locking the screen.
/// Multiple instances can exist at once, but only one can be locked at a time.
///
/// ## Signals
///
///
/// #### `failed`
/// The ::failed signal is fired when the lock could not be acquired.
///
///
///
///
/// #### `locked`
/// The ::locked signal is fired when the screen is successfully locked.
///
///
///
///
/// #### `monitor`
/// The ::monitor signal is fired once for each monitor that exists when a lock is started, and then whenever a new
/// monitor is detected during the lock. You generally want to call gtk_session_lock_instance_assign_window_to_monitor()
/// once in the handler for this signal with a newly created window and the given monitor.
///
/// This API does not directly tell you when a monitor is removed (GTK APIs can be used for that), however the window you
/// send to gtk_session_lock_instance_assign_window_to_monitor() will be automatically unmapped and dereferenced when its
/// monitor is removed or the screen is unlocked.
///
///
///
///
/// #### `unlocked`
/// The ::unlocked signal is fired when the session is unlocked, which may have been caused by a call to
/// gtk_session_lock_instance_unlock() or by the compositor.
///
///
#[doc(alias = "GtkSessionLockInstance")]
pub struct Instance(Object<ffi::GtkSessionLockInstance, ffi::GtkSessionLockInstanceClass>);
match fn {
type_ => || ffi::gtk_session_lock_instance_get_type(),
}
}
impl Instance {
///
/// # Returns
///
/// new session lock instance
#[doc(alias = "gtk_session_lock_instance_new")]
pub fn new() -> Instance {
assert_initialized_main_thread!();
unsafe {
from_glib_full(ffi::gtk_session_lock_instance_new())
}
}
/// This must be called with a different unrealized window once for each monitor immediately after calling
/// gtk_session_lock_lock(). Hiding a window that is active on a monitor or not letting a window be resized by the
/// library is not allowed (may result in a Wayland protocol error). The window will be unmapped and gtk_window_destroy()
/// called on it when the current lock ends.
/// ## `window`
/// The GTK Window to use as a lock surface
/// ## `monitor`
/// The monitor to show it on
#[doc(alias = "gtk_session_lock_instance_assign_window_to_monitor")]
pub fn assign_window_to_monitor(&self, window: &impl IsA<gtk::Window>, monitor: &gdk::Monitor) {
unsafe {
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);
}
}
/// Returns if this instance currently holds a lock.
#[doc(alias = "gtk_session_lock_instance_is_locked")]
pub fn is_locked(&self) -> bool {
unsafe {
from_glib(ffi::gtk_session_lock_instance_is_locked(self.to_glib_none().0))
}
}
/// Lock the screen. This should be called before assigning any windows to monitors. If this function fails the ::failed
/// signal is emitted, if it succeeds the ::locked signal is emitted. The ::failed signal may be emitted before the
/// function returns (for example, if another #GtkSessionLockInstance holds a lock) or later (if another process holds a
/// lock). The only case where neither signal is triggered is if the instance is already locked.
///
/// # Returns
///
/// false on immediate fail, true if lock acquisition was successfully started
#[doc(alias = "gtk_session_lock_instance_lock")]
pub fn lock(&self) -> bool {
unsafe {
from_glib(ffi::gtk_session_lock_instance_lock(self.to_glib_none().0))
}
}
/// If the screen is locked by this instance unlocks it and fires ::unlocked. Otherwise has no effect
#[doc(alias = "gtk_session_lock_instance_unlock")]
pub fn unlock(&self) {
unsafe {
ffi::gtk_session_lock_instance_unlock(self.to_glib_none().0);
}
}
/// The ::failed signal is fired when the lock could not be acquired.
#[doc(alias = "failed")]
pub fn connect_failed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn failed_trampoline<F: Fn(&Instance) + 'static>(this: *mut ffi::GtkSessionLockInstance, f: glib::ffi::gpointer) { unsafe {
let f: &F = &*(f as *const F);
f(&from_glib_borrow(this))
}}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(self.as_ptr() as *mut _, c"failed".as_ptr(),
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(failed_trampoline::<F> as *const ())), Box_::into_raw(f))
}
}
/// The ::locked signal is fired when the screen is successfully locked.
#[doc(alias = "locked")]
pub fn connect_locked<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn locked_trampoline<F: Fn(&Instance) + 'static>(this: *mut ffi::GtkSessionLockInstance, f: glib::ffi::gpointer) { unsafe {
let f: &F = &*(f as *const F);
f(&from_glib_borrow(this))
}}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(self.as_ptr() as *mut _, c"locked".as_ptr(),
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(locked_trampoline::<F> as *const ())), Box_::into_raw(f))
}
}
/// The ::monitor signal is fired once for each monitor that exists when a lock is started, and then whenever a new
/// monitor is detected during the lock. You generally want to call gtk_session_lock_instance_assign_window_to_monitor()
/// once in the handler for this signal with a newly created window and the given monitor.
///
/// This API does not directly tell you when a monitor is removed (GTK APIs can be used for that), however the window you
/// send to gtk_session_lock_instance_assign_window_to_monitor() will be automatically unmapped and dereferenced when its
/// monitor is removed or the screen is unlocked.
/// ## `monitor`
/// the #GdkMonitor that exists or was added
#[cfg(feature = "v1_2")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_2")))]
#[doc(alias = "monitor")]
pub fn connect_monitor<F: Fn(&Self, &gdk::Monitor) + 'static>(&self, f: F) -> SignalHandlerId {
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) { unsafe {
let f: &F = &*(f as *const F);
f(&from_glib_borrow(this), &from_glib_borrow(monitor))
}}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(self.as_ptr() as *mut _, c"monitor".as_ptr(),
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(monitor_trampoline::<F> as *const ())), Box_::into_raw(f))
}
}
/// The ::unlocked signal is fired when the session is unlocked, which may have been caused by a call to
/// gtk_session_lock_instance_unlock() or by the compositor.
#[doc(alias = "unlocked")]
pub fn connect_unlocked<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn unlocked_trampoline<F: Fn(&Instance) + 'static>(this: *mut ffi::GtkSessionLockInstance, f: glib::ffi::gpointer) { unsafe {
let f: &F = &*(f as *const F);
f(&from_glib_borrow(this))
}}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(self.as_ptr() as *mut _, c"unlocked".as_ptr(),
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(unlocked_trampoline::<F> as *const ())), Box_::into_raw(f))
}
}
}
#[cfg(feature = "v1_1")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_1")))]
impl Default for Instance {
fn default() -> Self {
Self::new()
}
}