gtk4-session-lock 0.4.0

Safe gir-generated wrapper for gtk4-session-lock
Documentation
// 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()
                     }
                 }