gio/auto/
power_profile_monitor.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::{ffi, Initable};
6use glib::{
7    prelude::*,
8    signal::{connect_raw, SignalHandlerId},
9    translate::*,
10};
11use std::boxed::Box as Box_;
12
13glib::wrapper! {
14    /// `GPowerProfileMonitor` makes it possible for applications as well as OS
15    /// components to monitor system power profiles and act upon them. It currently
16    /// only exports whether the system is in “Power Saver” mode (known as
17    /// “Low Power” mode on some systems).
18    ///
19    /// When in “Low Power” mode, it is recommended that applications:
20    ///
21    /// - disable automatic downloads;
22    /// - reduce the rate of refresh from online sources such as calendar or
23    ///   email synchronisation;
24    /// - reduce the use of expensive visual effects.
25    ///
26    /// It is also likely that OS components providing services to applications will
27    /// lower their own background activity, for the sake of the system.
28    ///
29    /// There are a variety of tools that exist for power consumption analysis, but those
30    /// usually depend on the OS and hardware used. On Linux, one could use `upower` to
31    /// monitor the battery discharge rate, `powertop` to check on the background activity
32    /// or activity at all), `sysprof` to inspect CPU usage, and `intel_gpu_time` to
33    /// profile GPU usage.
34    ///
35    /// Don’t forget to disconnect the [`notify`][struct@crate::glib::Object#notify] signal for
36    /// [`power-saver-enabled`][struct@crate::PowerProfileMonitor#power-saver-enabled], and unref the
37    /// `GPowerProfileMonitor` itself when exiting.
38    ///
39    /// ## Properties
40    ///
41    ///
42    /// #### `power-saver-enabled`
43    ///  Whether “Power Saver” mode is enabled on the system.
44    ///
45    /// Readable
46    ///
47    /// # Implements
48    ///
49    /// [`PowerProfileMonitorExt`][trait@crate::prelude::PowerProfileMonitorExt], [`InitableExt`][trait@crate::prelude::InitableExt]
50    #[doc(alias = "GPowerProfileMonitor")]
51    pub struct PowerProfileMonitor(Interface<ffi::GPowerProfileMonitor, ffi::GPowerProfileMonitorInterface>) @requires Initable;
52
53    match fn {
54        type_ => || ffi::g_power_profile_monitor_get_type(),
55    }
56}
57
58impl PowerProfileMonitor {
59    pub const NONE: Option<&'static PowerProfileMonitor> = None;
60
61    /// Gets a reference to the default #GPowerProfileMonitor for the system.
62    ///
63    /// # Returns
64    ///
65    /// a new reference to the default #GPowerProfileMonitor
66    #[doc(alias = "g_power_profile_monitor_dup_default")]
67    #[doc(alias = "dup_default")]
68    pub fn get_default() -> PowerProfileMonitor {
69        unsafe { from_glib_full(ffi::g_power_profile_monitor_dup_default()) }
70    }
71}
72
73mod sealed {
74    pub trait Sealed {}
75    impl<T: super::IsA<super::PowerProfileMonitor>> Sealed for T {}
76}
77
78/// Trait containing all [`struct@PowerProfileMonitor`] methods.
79///
80/// # Implementors
81///
82/// [`PowerProfileMonitor`][struct@crate::PowerProfileMonitor]
83pub trait PowerProfileMonitorExt: IsA<PowerProfileMonitor> + sealed::Sealed + 'static {
84    /// Gets whether the system is in “Power Saver” mode.
85    ///
86    /// You are expected to listen to the
87    /// #GPowerProfileMonitor::notify::power-saver-enabled signal to know when the profile has
88    /// changed.
89    ///
90    /// # Returns
91    ///
92    /// Whether the system is in “Power Saver” mode.
93    #[doc(alias = "g_power_profile_monitor_get_power_saver_enabled")]
94    #[doc(alias = "get_power_saver_enabled")]
95    #[doc(alias = "power-saver-enabled")]
96    fn is_power_saver_enabled(&self) -> bool {
97        unsafe {
98            from_glib(ffi::g_power_profile_monitor_get_power_saver_enabled(
99                self.as_ref().to_glib_none().0,
100            ))
101        }
102    }
103
104    #[cfg(feature = "v2_70")]
105    #[cfg_attr(docsrs, doc(cfg(feature = "v2_70")))]
106    #[doc(alias = "power-saver-enabled")]
107    fn connect_power_saver_enabled_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
108        unsafe extern "C" fn notify_power_saver_enabled_trampoline<
109            P: IsA<PowerProfileMonitor>,
110            F: Fn(&P) + 'static,
111        >(
112            this: *mut ffi::GPowerProfileMonitor,
113            _param_spec: glib::ffi::gpointer,
114            f: glib::ffi::gpointer,
115        ) {
116            let f: &F = &*(f as *const F);
117            f(PowerProfileMonitor::from_glib_borrow(this).unsafe_cast_ref())
118        }
119        unsafe {
120            let f: Box_<F> = Box_::new(f);
121            connect_raw(
122                self.as_ptr() as *mut _,
123                b"notify::power-saver-enabled\0".as_ptr() as *const _,
124                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
125                    notify_power_saver_enabled_trampoline::<Self, F> as *const (),
126                )),
127                Box_::into_raw(f),
128            )
129        }
130    }
131}
132
133impl<O: IsA<PowerProfileMonitor>> PowerProfileMonitorExt for O {}