Major update to supergfx and others

This commit is contained in:
Luke D. Jones
2021-08-26 11:43:47 +12:00
parent 60b7f3be69
commit 498e604531
33 changed files with 535 additions and 278 deletions

View File

@@ -1,10 +1,10 @@
pub static DBUS_NAME: &str = "org.asuslinux.Daemon";
pub static DBUS_NAME_GFX: &str = "org.supergfxctl.Daemon";
pub static DBUS_PATH: &str = "/org/asuslinux/Daemon";
pub static DBUS_IFACE: &str = "org.asuslinux.Daemon";
pub mod zbus_anime;
pub mod zbus_charge;
pub mod zbus_gfx;
pub mod zbus_led;
pub mod zbus_profile;
pub mod zbus_rogbios;
@@ -13,7 +13,6 @@ pub mod zbus_supported;
use rog_anime::AnimePowerStates;
use rog_aura::{AuraEffect, LedPowerStates};
use rog_profiles::Profile;
use supergfxctl::gfx_vendors::{GfxRequiredUserAction, GfxVendors};
use std::sync::mpsc::{channel, Receiver};
use zbus::{Connection, Result, SignalReceiver};
@@ -21,7 +20,6 @@ pub static VERSION: &str = env!("CARGO_PKG_VERSION");
pub struct DbusProxies<'a> {
anime: zbus_anime::AnimeProxy<'a>,
charge: zbus_charge::ChargeProxy<'a>,
gfx: zbus_gfx::GfxProxy<'a>,
led: zbus_led::LedProxy<'a>,
profile: zbus_profile::ProfileProxy<'a>,
rog_bios: zbus_rogbios::RogBiosProxy<'a>,
@@ -38,7 +36,6 @@ impl<'a> DbusProxies<'a> {
anime: zbus_anime::AnimeProxy::new(&conn)?,
led: zbus_led::LedProxy::new(&conn)?,
charge: zbus_charge::ChargeProxy::new(&conn)?,
gfx: zbus_gfx::GfxProxy::new(&conn)?,
profile: zbus_profile::ProfileProxy::new(&conn)?,
rog_bios: zbus_rogbios::RogBiosProxy::new(&conn)?,
supported: zbus_supported::SupportProxy::new(&conn)?,
@@ -52,7 +49,6 @@ impl<'a> DbusProxies<'a> {
recv.receive_for(self.anime.proxy());
recv.receive_for(self.led.proxy());
recv.receive_for(self.charge.proxy());
recv.receive_for(self.gfx.proxy());
recv.receive_for(self.profile.proxy());
recv.receive_for(self.rog_bios.proxy());
recv.receive_for(self.supported.proxy());
@@ -67,10 +63,6 @@ impl<'a> DbusProxies<'a> {
&self.charge
}
pub fn gfx(&self) -> &zbus_gfx::GfxProxy<'a> {
&self.gfx
}
pub fn led(&self) -> &zbus_led::LedProxy<'a> {
&self.led
}
@@ -90,8 +82,6 @@ impl<'a> DbusProxies<'a> {
// Signals separated out
pub struct Signals {
pub gfx_vendor: Receiver<GfxVendors>,
pub gfx_action: Receiver<GfxRequiredUserAction>,
pub profile: Receiver<Profile>,
pub led_mode: Receiver<AuraEffect>,
pub led_power_state: Receiver<LedPowerStates>,
@@ -105,16 +95,6 @@ impl Signals {
#[inline]
pub fn new(proxies: &DbusProxies) -> Result<Self> {
Ok(Signals {
gfx_vendor: {
let (tx, rx) = channel();
proxies.gfx.connect_notify_gfx(tx)?;
rx
},
gfx_action: {
let (tx, rx) = channel();
proxies.gfx.connect_notify_action(tx)?;
rx
},
profile: {
let (tx, rx) = channel();
proxies.profile.connect_notify_profile(tx)?;
@@ -182,26 +162,9 @@ impl<'a> RogDbusClient<'a> {
recv.receive_for(self.proxies.anime.proxy());
recv.receive_for(self.proxies.led.proxy());
recv.receive_for(self.proxies.charge.proxy());
recv.receive_for(self.proxies.gfx.proxy());
recv.receive_for(self.proxies.profile.proxy());
recv.receive_for(self.proxies.rog_bios.proxy());
recv.receive_for(self.proxies.supported.proxy());
recv
}
/*
* GFX
*/
pub fn gfx_wait_changed(&self) -> Result<GfxRequiredUserAction> {
loop {
if let Ok(res) = self.proxies.gfx.proxy().next_signal() {
if res.is_none() {
if let Ok(stuff) = self.signals.gfx_action.try_recv() {
return Ok(stuff);
}
// return Ok("Failed for unknown reason".to_owned());
}
}
}
}
}

View File

@@ -1,98 +0,0 @@
//! # DBus interface proxy for: `org.asuslinux.Gfx`
//!
//! This code was generated by `zbus-xmlgen` `1.0.0` from DBus introspection data.
//! Source: `Interface '/org/asuslinux/Gfx' from service 'org.asuslinux.Daemon' on system bus`.
//!
//! You may prefer to adapt it, instead of using it verbatim.
//!
//! More information can be found in the
//! [Writing a client proxy](https://zeenix.pages.freedesktop.org/zbus/client.html)
//! section of the zbus documentation.
//!
//! This DBus object implements
//! [standard DBus interfaces](https://dbus.freedesktop.org/doc/dbus-specification.html),
//! (`org.freedesktop.DBus.*`) for which the following zbus proxies can be used:
//!
//! * [`zbus::fdo::PropertiesProxy`]
//! * [`zbus::fdo::IntrospectableProxy`]
//! * [`zbus::fdo::PeerProxy`]
//!
//! …consequently `zbus-xmlgen` did not generate code for the above interfaces.
use std::sync::mpsc::Sender;
use supergfxctl::gfx_vendors::{GfxPower, GfxRequiredUserAction, GfxVendors};
use zbus::{dbus_proxy, Connection, Result};
#[dbus_proxy(
interface = "org.asuslinux.Daemon",
default_path = "/org/asuslinux/Gfx"
)]
trait Daemon {
/// Power method
fn power(&self) -> zbus::Result<GfxPower>;
/// SetVendor method
fn set_vendor(&self, vendor: &GfxVendors) -> zbus::Result<GfxRequiredUserAction>;
/// Vendor method
fn vendor(&self) -> zbus::Result<GfxVendors>;
/// NotifyAction signal
#[dbus_proxy(signal)]
fn notify_action(&self, action: GfxRequiredUserAction) -> zbus::Result<()>;
/// NotifyGfx signal
#[dbus_proxy(signal)]
fn notify_gfx(&self, vendor: GfxVendors) -> zbus::Result<()>;
}
pub struct GfxProxy<'a>(DaemonProxy<'a>);
impl<'a> GfxProxy<'a> {
#[inline]
pub fn new(conn: &Connection) -> Result<Self> {
Ok(GfxProxy(DaemonProxy::new(conn)?))
}
#[inline]
pub fn proxy(&self) -> &DaemonProxy<'a> {
&self.0
}
#[inline]
pub fn gfx_get_pwr(&self) -> Result<GfxPower> {
self.0.power()
}
#[inline]
pub fn gfx_get_mode(&self) -> Result<GfxVendors> {
self.0.vendor()
}
#[inline]
pub fn gfx_write_mode(&self, vendor: &GfxVendors) -> Result<GfxRequiredUserAction> {
self.0.set_vendor(vendor)
}
#[inline]
pub fn connect_notify_action(
&self,
send: Sender<GfxRequiredUserAction>,
) -> zbus::fdo::Result<()> {
self.0.connect_notify_action(move |data| {
send.send(data)
.map_err(|err| zbus::fdo::Error::Failed(err.to_string()))?;
Ok(())
})
}
#[inline]
pub fn connect_notify_gfx(&self, send: Sender<GfxVendors>) -> zbus::fdo::Result<()> {
self.0.connect_notify_gfx(move |data| {
send.send(data)
.map_err(|err| zbus::fdo::Error::Failed(err.to_string()))?;
Ok(())
})
}
}