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
73/// Trait containing all [`struct@PowerProfileMonitor`] methods.
74///
75/// # Implementors
76///
77/// [`PowerProfileMonitor`][struct@crate::PowerProfileMonitor]
78pub trait PowerProfileMonitorExt: IsA<PowerProfileMonitor> + 'static {
79    /// Gets whether the system is in “Power Saver” mode.
80    ///
81    /// You are expected to listen to the
82    /// #GPowerProfileMonitor::notify::power-saver-enabled signal to know when the profile has
83    /// changed.
84    ///
85    /// # Returns
86    ///
87    /// Whether the system is in “Power Saver” mode.
88    #[doc(alias = "g_power_profile_monitor_get_power_saver_enabled")]
89    #[doc(alias = "get_power_saver_enabled")]
90    #[doc(alias = "power-saver-enabled")]
91    fn is_power_saver_enabled(&self) -> bool {
92        unsafe {
93            from_glib(ffi::g_power_profile_monitor_get_power_saver_enabled(
94                self.as_ref().to_glib_none().0,
95            ))
96        }
97    }
98
99    #[cfg(feature = "v2_70")]
100    #[cfg_attr(docsrs, doc(cfg(feature = "v2_70")))]
101    #[doc(alias = "power-saver-enabled")]
102    fn connect_power_saver_enabled_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
103        unsafe extern "C" fn notify_power_saver_enabled_trampoline<
104            P: IsA<PowerProfileMonitor>,
105            F: Fn(&P) + 'static,
106        >(
107            this: *mut ffi::GPowerProfileMonitor,
108            _param_spec: glib::ffi::gpointer,
109            f: glib::ffi::gpointer,
110        ) {
111            let f: &F = &*(f as *const F);
112            f(PowerProfileMonitor::from_glib_borrow(this).unsafe_cast_ref())
113        }
114        unsafe {
115            let f: Box_<F> = Box_::new(f);
116            connect_raw(
117                self.as_ptr() as *mut _,
118                c"notify::power-saver-enabled".as_ptr() as *const _,
119                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
120                    notify_power_saver_enabled_trampoline::<Self, F> as *const (),
121                )),
122                Box_::into_raw(f),
123            )
124        }
125    }
126}
127
128impl<O: IsA<PowerProfileMonitor>> PowerProfileMonitorExt for O {}