Merge branch 'main' into main

This commit is contained in:
Luke Jones
2024-04-10 08:54:54 +12:00
committed by GitHub
61 changed files with 1573 additions and 3009 deletions

View File

@@ -23,22 +23,12 @@ pub mod types;
pub mod ui;
pub mod update_and_notify;
#[cfg(feature = "mocking")]
pub use mocking::RogDbusClientBlocking;
use nix::sys::stat;
use nix::unistd;
#[cfg(not(feature = "mocking"))]
pub use rog_dbus::RogDbusClientBlocking;
use tempfile::TempDir;
// use log::{error, info, warn};
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
#[cfg(not(feature = "mocking"))]
const DATA_DIR: &str = "/usr/share/rog-gui/";
#[cfg(feature = "mocking")]
const DATA_DIR: &str = env!("CARGO_MANIFEST_DIR");
const BOARD_NAME: &str = "/sys/class/dmi/id/board_name";
pub const APP_ICON_PATH: &str = "/usr/share/icons/hicolor/512x512/apps/rog-control-center.png";
pub fn print_versions() {
@@ -89,7 +79,7 @@ pub fn on_tmp_dir_exists() -> Result<TempDir, std::io::Error> {
ipc_file.write_all(&[SHOW_GUI, 0])?;
// tiny sleep to give the app a chance to respond
sleep(Duration::from_millis(10));
ipc_file.read(&mut buf).ok();
ipc_file.read_exact(&mut buf).ok();
// First entry is the actual state
if buf[0] == SHOWING_GUI {

View File

@@ -15,19 +15,28 @@ use rog_control_center::cli_options::CliStart;
use rog_control_center::config::Config;
use rog_control_center::error::Result;
use rog_control_center::slint::ComponentHandle;
use rog_control_center::system_state::{AuraCreation, SystemState};
use rog_control_center::system_state::SystemState;
use rog_control_center::tray::init_tray;
use rog_control_center::ui::setup_window;
use rog_control_center::update_and_notify::{start_notifications, EnabledNotifications};
use rog_control_center::{
get_ipc_file, on_tmp_dir_exists, print_versions, MainWindow, RogDbusClientBlocking, QUIT_APP,
SHOWING_GUI, SHOW_GUI,
get_ipc_file, on_tmp_dir_exists, print_versions, MainWindow, QUIT_APP, SHOWING_GUI, SHOW_GUI,
};
use tokio::runtime::Runtime;
// use winit::monitor::VideoMode;
// use winit::window::{Fullscreen, WindowLevel};
fn main() -> Result<()> {
#[tokio::main]
async fn main() -> Result<()> {
let self_version = env!("CARGO_PKG_VERSION");
let conn = zbus::blocking::Connection::system()?;
let proxy = rog_dbus::zbus_platform::PlatformProxyBlocking::new(&conn)?;
let asusd_version = proxy.version().unwrap();
if asusd_version != self_version {
println!("Version mismatch: asusctl = {self_version}, asusd = {asusd_version}");
return Ok(());
}
let dmi = DMIID::new().unwrap_or_default();
let board_name = dmi.board_name;
let prod_family = dmi.product_family;
@@ -66,17 +75,9 @@ fn main() -> Result<()> {
// Enter the runtime so that `tokio::spawn` is available immediately.
let _enter = rt.enter();
let (dbus, _) = RogDbusClientBlocking::new()
.map_err(|_| {
// TODO: show an error window
})
.unwrap();
let supported_properties = dbus
.proxies()
.platform()
.supported_properties()
.unwrap_or_else(|_e| {
let supported_properties = match proxy.supported_properties() {
Ok(s) => s,
Err(_e) => {
// TODO: show an error window
Vec::default()
});
@@ -91,24 +92,28 @@ fn main() -> Result<()> {
if cli_parsed.height_fullscreen != 0 {
config.fullscreen_height = cli_parsed.height_fullscreen;
}
config.write();
} else if cli_parsed.windowed {
config.start_fullscreen = false;
config.write();
}
if is_rog_ally {
config.enable_notifications = false;
config.enable_tray_icon = false;
config.run_in_background = false;
config.startup_in_background = false;
}
if config.startup_in_background {
config.run_in_background = true;
config.write();
} else {
get_ipc_file().unwrap().write_all(&[SHOW_GUI, 0]).unwrap();
}
config.write();
let enabled_notifications = EnabledNotifications::tokio_mutex(&config);
let aura_creation = AuraCreation::new(cli_parsed.board_name, cli_parsed.layout_viewing)?;
// TODO: config mutex to share config in various places
let states = setup_page_state_and_notifs(aura_creation, &enabled_notifications, &config)?;
let states = setup_page_state_and_notifs(&enabled_notifications, &config).await?;
let enable_tray_icon = config.enable_tray_icon;
let startup_in_background = config.startup_in_background;
@@ -207,17 +212,18 @@ fn main() -> Result<()> {
Ok(())
}
fn setup_page_state_and_notifs(
aura_creation: AuraCreation,
async fn setup_page_state_and_notifs(
enabled_notifications: &Arc<Mutex<EnabledNotifications>>,
config: &Config,
) -> Result<Arc<Mutex<SystemState>>> {
let page_states = Arc::new(Mutex::new(SystemState::new(
aura_creation,
enabled_notifications.clone(),
config.enable_tray_icon,
config.run_in_background,
)?));
let page_states = Arc::new(Mutex::new(
SystemState::new(
enabled_notifications.clone(),
config.enable_tray_icon,
config.run_in_background,
)
.await?,
));
start_notifications(config, &page_states, enabled_notifications)?;
@@ -254,8 +260,10 @@ fn setup_page_state_and_notifs(
// IconData {
// height,
// width,
// rgba,
// }
// rgba
//
//
// / }
// }
fn do_cli_help(parsed: &CliStart) -> bool {

View File

@@ -1,190 +1,15 @@
use std::collections::{BTreeMap, HashSet};
use std::path::PathBuf;
use std::sync::{Arc, Mutex};
use std::time::SystemTime;
use log::{error, warn};
use rog_anime::{Animations, DeviceState};
use rog_aura::aura_detection::{LaptopLedData, LedSupportFile};
use rog_aura::layouts::KeyLayout;
use rog_aura::usb::AuraPowerDev;
use rog_aura::{AuraEffect, AuraModeNum, LedBrightness};
use rog_platform::platform::{GpuMode, ThrottlePolicy};
use rog_profiles::fan_curve_set::CurveData;
use rog_profiles::FanCurvePU;
use log::error;
use supergfxctl::pci_device::{GfxMode, GfxPower};
#[cfg(not(feature = "mocking"))]
use supergfxctl::zbus_proxy::DaemonProxyBlocking as GfxProxyBlocking;
use supergfxctl::zbus_proxy::DaemonProxy as GfxProxy;
use zbus::Connection;
use crate::error::Result;
#[cfg(feature = "mocking")]
use crate::mocking::DaemonProxyBlocking as GfxProxyBlocking;
use crate::update_and_notify::EnabledNotifications;
use crate::{RogDbusClientBlocking, BOARD_NAME, DATA_DIR};
#[derive(Clone, Debug, Default)]
pub struct PlatformState {
/// To be shared to a thread that checks notifications.
/// It's a bit general in that it won't provide *what* was
/// updated, so the full state needs refresh
pub post_sound: Option<bool>,
pub gpu_mux_mode: Option<GpuMode>,
pub panel_overdrive: Option<bool>,
pub mini_led_mode: Option<bool>,
pub dgpu_disable: Option<bool>,
pub egpu_enable: Option<bool>,
pub throttle: Option<ThrottlePolicy>,
pub charge_limit: Option<u8>,
}
impl PlatformState {
pub fn new(dbus: &RogDbusClientBlocking<'_>) -> Result<Self> {
Ok(Self {
post_sound: dbus.proxies().platform().boot_sound().ok(),
gpu_mux_mode: dbus
.proxies()
.platform()
.gpu_mux_mode()
.map(GpuMode::from)
.ok(),
panel_overdrive: dbus.proxies().platform().panel_od().ok(),
mini_led_mode: dbus.proxies().platform().mini_led_mode().ok(),
// TODO: needs supergfx
dgpu_disable: dbus.proxies().platform().dgpu_disable().ok(),
egpu_enable: dbus.proxies().platform().egpu_enable().ok(),
throttle: dbus.proxies().platform().throttle_thermal_policy().ok(),
charge_limit: dbus
.proxies()
.platform()
.charge_control_end_threshold()
.ok(),
})
}
}
#[derive(Clone, Debug, Default)]
pub struct FanCurvesState {
pub show_curve: ThrottlePolicy,
pub show_graph: FanCurvePU,
pub curves: BTreeMap<ThrottlePolicy, Vec<CurveData>>,
pub available_fans: HashSet<FanCurvePU>,
// pub drag_delta: Vec2,
}
impl FanCurvesState {
pub fn new(dbus: &RogDbusClientBlocking<'_>) -> Result<Self> {
let profiles = vec![
ThrottlePolicy::Balanced,
ThrottlePolicy::Quiet,
ThrottlePolicy::Performance,
];
let mut available_fans = HashSet::new();
let mut curves: BTreeMap<ThrottlePolicy, Vec<CurveData>> = BTreeMap::new();
for p in &profiles {
if let Ok(curve) = dbus.proxies().fan_curves().fan_curve_data(*p) {
if available_fans.is_empty() {
for fan in &curve {
available_fans.insert(fan.fan);
}
}
curves.insert(*p, curve);
} else {
curves.insert(*p, Default::default());
}
}
let show_curve = dbus.proxies().platform().throttle_thermal_policy()?;
Ok(Self {
show_curve,
show_graph: FanCurvePU::CPU,
curves,
available_fans,
// drag_delta: Vec2::default(),
})
}
}
#[derive(Clone, Debug, Default)]
pub struct AuraState {
pub current_mode: AuraModeNum,
pub modes: BTreeMap<AuraModeNum, AuraEffect>,
pub enabled: AuraPowerDev,
/// Brightness from 0-3
pub bright: LedBrightness,
pub wave_red: [u8; 22],
pub wave_green: [u8; 22],
pub wave_blue: [u8; 22],
}
impl AuraState {
pub fn new(layout: &KeyLayout, dbus: &RogDbusClientBlocking<'_>) -> Result<Self> {
Ok(Self {
current_mode: if !layout.basic_modes().is_empty() {
dbus.proxies().aura().led_mode().unwrap_or_default()
} else {
AuraModeNum::Static
},
modes: if !layout.basic_modes().is_empty() {
dbus.proxies().aura().all_mode_data().unwrap_or_default()
} else {
BTreeMap::new()
},
enabled: dbus.proxies().aura().led_power().unwrap_or_default(),
bright: Default::default(),
wave_red: [0u8; 22],
wave_green: [0u8; 22],
wave_blue: [0u8; 22],
})
}
/// Bump value in to the wave and surf all along.
pub fn nudge_wave(&mut self, r: u8, g: u8, b: u8) {
for i in (0..self.wave_red.len()).rev() {
if i > 0 {
self.wave_red[i] = self.wave_red[i - 1];
self.wave_green[i] = self.wave_green[i - 1];
self.wave_blue[i] = self.wave_blue[i - 1];
}
}
self.wave_red[0] = r;
self.wave_green[0] = g;
self.wave_blue[0] = b;
}
}
#[derive(Clone, Debug, Default)]
pub struct AnimeState {
pub display_enabled: bool,
pub display_brightness: u8,
pub builtin_anims_enabled: bool,
pub builtin_anims: Animations,
}
impl AnimeState {
pub fn new(dbus: &RogDbusClientBlocking<'_>) -> Result<Self> {
let device_state = dbus.proxies().anime().device_state()?;
Ok(Self {
display_enabled: device_state.display_enabled,
display_brightness: device_state.display_brightness as u8,
builtin_anims_enabled: device_state.builtin_anims_enabled,
builtin_anims: device_state.builtin_anims,
})
}
}
impl From<DeviceState> for AnimeState {
fn from(dev: DeviceState) -> Self {
Self {
display_enabled: dev.display_enabled,
display_brightness: dev.display_brightness as u8,
builtin_anims_enabled: dev.builtin_anims_enabled,
builtin_anims: dev.builtin_anims,
}
}
}
#[derive(Clone, Debug)]
pub struct GfxState {
@@ -194,11 +19,11 @@ pub struct GfxState {
}
impl GfxState {
pub fn new(dbus: &GfxProxyBlocking<'_>) -> Result<Self> {
pub async fn new(dbus: &GfxProxy<'_>) -> Result<Self> {
Ok(Self {
has_supergfx: dbus.mode().is_ok(),
mode: dbus.mode().unwrap_or(GfxMode::None),
power_status: dbus.power().unwrap_or(GfxPower::Unknown),
has_supergfx: dbus.mode().await.is_ok(),
mode: dbus.mode().await.unwrap_or(GfxMode::None),
power_status: dbus.power().await.unwrap_or(GfxPower::Unknown),
})
}
}
@@ -213,115 +38,16 @@ impl Default for GfxState {
}
}
/// The keyboard layout, used for such things as per-key and zones
#[derive(Clone, Debug)]
pub struct AuraCreation {
/// Specifically for testing the development of keyboard layouts (combined
/// with `--layout-name` CLI option)
pub layout_testing: Option<PathBuf>,
pub layout_last_modified: SystemTime,
pub keyboard_layout: KeyLayout,
pub keyboard_layouts: Vec<PathBuf>,
/// current index in to `self.keyboard_layouts`
pub keyboard_layout_index: usize,
}
impl AuraCreation {
pub fn new(test_name: Option<String>, view_layout: bool) -> Result<Self> {
let mut led_support = LaptopLedData::get_data();
let mut path = PathBuf::from(DATA_DIR);
let mut layout_testing = None;
let mut keyboard_layouts = Vec::new();
// Find and load a matching layout for laptop
let mut board_name = std::fs::read_to_string(BOARD_NAME).map_err(|e| {
println!("DOH! {BOARD_NAME}, {e}");
e
})?;
if test_name.is_some() || view_layout {
if cfg!(feature = "mocking") {
path.pop();
path.push("rog-aura");
path.push("data");
}
keyboard_layouts = KeyLayout::layout_files(path.clone()).unwrap();
if let Some(name) = test_name {
if let Some(modes) = LedSupportFile::load_from_supoprt_db() {
if let Some(data) = modes.matcher(&name) {
led_support = data;
}
}
board_name = name;
for layout in &keyboard_layouts {
if layout
.file_name()
.unwrap()
.to_string_lossy()
.contains(&led_support.layout_name.to_lowercase())
{
layout_testing = Some(layout.clone());
}
}
} else {
board_name = "GQ401QM".to_owned();
};
if view_layout {
layout_testing = Some(keyboard_layouts[0].clone());
board_name = keyboard_layouts[0]
.file_name()
.unwrap()
.to_string_lossy()
.split_once('_')
.unwrap()
.0
.to_owned();
led_support.layout_name = board_name.clone();
}
}
let keyboard_layout = KeyLayout::find_layout(led_support, path)
.map_err(|e| {
println!("DERP! , {e}");
})
.unwrap_or_else(|_| {
warn!("Did not find a keyboard layout matching {board_name}");
KeyLayout::default_layout()
});
Ok(Self {
layout_testing,
layout_last_modified: SystemTime::now(),
keyboard_layout,
keyboard_layouts,
keyboard_layout_index: 0,
})
}
}
/// State stored from system daemons. This is shared with: tray, zbus
/// notifications thread and the GUI app thread.
pub struct SystemState {
pub aura_creation: AuraCreation,
//--
pub enabled_notifications: Arc<Mutex<EnabledNotifications>>,
/// Because much of the app state here is the same as
/// `RogBiosSupportedFunctions` we can re-use that structure.
pub bios: PlatformState,
pub aura: AuraState,
pub anime: AnimeState,
pub fan_curves: FanCurvesState,
pub gfx_state: GfxState,
pub error: Option<String>,
/// Specific field for the tray only so that we can know when it does need
/// update. The tray should set this to false when done.
pub tray_should_update: bool,
pub app_should_update: bool,
pub asus_dbus: RogDbusClientBlocking<'static>,
pub gfx_dbus: GfxProxyBlocking<'static>,
pub tray_enabled: bool,
pub run_in_bg: bool,
}
@@ -329,47 +55,22 @@ pub struct SystemState {
impl SystemState {
/// Creates self, including the relevant dbus connections and proixies for
/// internal use
pub fn new(
aura_creation: AuraCreation,
pub async fn new(
enabled_notifications: Arc<Mutex<EnabledNotifications>>,
tray_enabled: bool,
run_in_bg: bool,
) -> Result<Self> {
let (asus_dbus, conn) = RogDbusClientBlocking::new()?;
let aura = AuraState::new(&aura_creation.keyboard_layout, &asus_dbus)
.map_err(|e| {
let e = format!("Could not get AuraState state: {e}");
error!("{e}");
})
.unwrap_or_default();
let conn = Connection::system().await?;
let gfx_dbus = GfxProxyBlocking::builder(&conn)
let gfx_dbus = GfxProxy::builder(&conn)
.destination(":org.supergfxctl.Daemon")?
.build()
.await
.expect("Couldn't connect to supergfxd");
Ok(Self {
aura_creation,
enabled_notifications,
bios: PlatformState::new(&asus_dbus)
.map_err(|e| {
let e = format!("Could not get BiosState state: {e}");
error!("{e}");
})
.unwrap_or_default(),
aura,
anime: AnimeState::new(&asus_dbus)
.map_err(|e| {
let e = format!("Could not get AnimeState state: {e}");
error!("{e}");
})
.unwrap_or_default(),
fan_curves: FanCurvesState::new(&asus_dbus)
.map_err(|e| {
let e = format!("Could not get FanCurvesState state: {e}");
error!("{e}");
})
.unwrap_or_default(),
gfx_state: GfxState::new(&gfx_dbus)
.await
.map_err(|e| {
let e = format!("Could not get supergfxd state: {e}");
error!("{e}");
@@ -378,8 +79,6 @@ impl SystemState {
error: None,
tray_should_update: true,
app_should_update: true,
asus_dbus,
gfx_dbus,
tray_enabled,
run_in_bg,
})
@@ -390,51 +89,3 @@ impl SystemState {
self.app_should_update = true;
}
}
impl Default for SystemState {
fn default() -> Self {
let (asus_dbus, conn) = RogDbusClientBlocking::new().expect("Couldn't connect to asusd");
let gfx_dbus = GfxProxyBlocking::builder(&conn)
.build()
.expect("Couldn't connect to supergfxd");
Self {
aura_creation: AuraCreation {
layout_testing: None,
layout_last_modified: SystemTime::now(),
keyboard_layout: KeyLayout::default_layout(),
keyboard_layouts: Default::default(),
keyboard_layout_index: 0,
},
enabled_notifications: Default::default(),
bios: PlatformState {
post_sound: Default::default(),
gpu_mux_mode: None,
charge_limit: Some(100),
..Default::default()
},
aura: AuraState {
current_mode: AuraModeNum::Static,
modes: Default::default(),
enabled: AuraPowerDev::default(),
..Default::default()
},
anime: AnimeState::default(),
fan_curves: FanCurvesState {
..Default::default()
},
gfx_state: GfxState {
has_supergfx: false,
mode: GfxMode::None,
power_status: GfxPower::Unknown,
},
error: Default::default(),
tray_should_update: true,
app_should_update: true,
asus_dbus,
gfx_dbus,
tray_enabled: true,
run_in_bg: true,
}
}
}

View File

@@ -11,7 +11,7 @@ use std::time::Duration;
use betrayer::{Icon, Menu, MenuItem, TrayEvent, TrayIcon, TrayIconBuilder};
use log::{debug, error, info, warn};
use rog_platform::platform::{GpuMode, Properties};
use rog_platform::platform::Properties;
use supergfxctl::pci_device::{GfxMode, GfxPower};
use supergfxctl::zbus_proxy::DaemonProxyBlocking as GfxProxy;
use versions::Versioning;
@@ -113,16 +113,7 @@ fn set_tray_icon_and_tip(lock: &SystemState, tray: &TrayIcon<TrayAction>, superg
}
};
let current_gpu_mode = if supergfx_active {
lock.gfx_state.mode
} else if let Some(mode) = lock.bios.gpu_mux_mode {
match mode {
GpuMode::Discrete => GfxMode::AsusMuxDgpu,
_ => GfxMode::Hybrid,
}
} else {
GfxMode::Hybrid
};
let current_gpu_mode = lock.gfx_state.mode;
tray.set_tooltip(format!(
"ROG: gpu mode = {current_gpu_mode:?}, gpu power = {gpu_status:?}"
@@ -137,59 +128,61 @@ pub fn init_tray(
config: Arc<Mutex<Config>>,
) {
std::thread::spawn(move || {
debug!("init_tray");
let rog_blue = read_icon(&PathBuf::from("asus_notif_blue.png"));
let rog_red = read_icon(&PathBuf::from("asus_notif_red.png"));
let rog_green = read_icon(&PathBuf::from("asus_notif_green.png"));
let rog_white = read_icon(&PathBuf::from("asus_notif_white.png"));
let gpu_integrated = read_icon(&PathBuf::from("rog-control-center.png"));
ICONS.get_or_init(|| Icons {
rog_blue,
rog_red: rog_red.clone(),
rog_green,
rog_white,
gpu_integrated,
});
let conn = zbus::blocking::Connection::system().unwrap();
let gfx_proxy = GfxProxy::new(&conn).unwrap();
let mut supergfx_active = false;
if gfx_proxy.mode().is_ok() {
supergfx_active = true;
if let Ok(version) = gfx_proxy.version() {
if let Some(version) = Versioning::new(&version) {
let curr_gfx = Versioning::new("5.0.3-RC4").unwrap();
warn!("supergfxd version = {version}");
if version < curr_gfx {
// Don't allow mode changing if too old a version
warn!("supergfxd found but is too old to use");
// tray.gfx_proxy_is_active = false;
}
}
}
};
let tray = TrayIconBuilder::<TrayAction>::new()
if let Ok(tray) = TrayIconBuilder::<TrayAction>::new()
.with_icon(rog_red.clone())
.with_tooltip(TRAY_LABEL)
.with_menu(build_menu())
.build(do_action)
.unwrap();
info!("Started ROGTray");
loop {
// let states = states.clone();
if let Ok(mut lock) = states.lock() {
if lock.tray_should_update {
set_tray_icon_and_tip(&lock, &tray, supergfx_active);
lock.tray_should_update = false;
if let Ok(lock) = config.try_lock() {
if !lock.enable_tray_icon {
return;
.map_err(|e| log::error!("Tray unable to be initialised: {e:?}"))
{
info!("Tray started");
let rog_blue = read_icon(&PathBuf::from("asus_notif_blue.png"));
let rog_green = read_icon(&PathBuf::from("asus_notif_green.png"));
let rog_white = read_icon(&PathBuf::from("asus_notif_white.png"));
let gpu_integrated = read_icon(&PathBuf::from("rog-control-center.png"));
ICONS.get_or_init(|| Icons {
rog_blue,
rog_red: rog_red.clone(),
rog_green,
rog_white,
gpu_integrated,
});
let conn = zbus::blocking::Connection::system().unwrap();
let gfx_proxy = GfxProxy::new(&conn).unwrap();
let mut supergfx_active = false;
if gfx_proxy.mode().is_ok() {
supergfx_active = true;
if let Ok(version) = gfx_proxy.version() {
if let Some(version) = Versioning::new(&version) {
let curr_gfx = Versioning::new("5.0.3-RC4").unwrap();
warn!("supergfxd version = {version}");
if version < curr_gfx {
// Don't allow mode changing if too old a version
warn!("supergfxd found but is too old to use");
// tray.gfx_proxy_is_active = false;
}
}
}
};
info!("Started ROGTray");
loop {
if let Ok(mut lock) = states.lock() {
if lock.tray_should_update {
set_tray_icon_and_tip(&lock, &tray, supergfx_active);
lock.tray_should_update = false;
if let Ok(lock) = config.try_lock() {
if !lock.enable_tray_icon {
return;
}
}
}
}
sleep(Duration::from_millis(50));
}
sleep(Duration::from_millis(50));
}
});
}

View File

@@ -1,3 +1,7 @@
use crate::slint_generatedMainWindow::{
AuraPowerState as SlintAuraPowerState, LaptopAuraPower as SlintLaptopAuraPower,
};
impl From<rog_aura::AuraEffect> for crate::slint_generatedMainWindow::AuraEffect {
fn from(m: rog_aura::AuraEffect) -> Self {
Self {
@@ -46,66 +50,20 @@ impl From<crate::slint_generatedMainWindow::AuraEffect> for rog_aura::AuraEffect
}
}
use rog_aura::power::KbAuraPowerState;
use rog_aura::aura_detection::PowerZones;
use rog_aura::keyboard::{AuraPowerState, LaptopAuraPower};
use slint::{Model, ModelRc, RgbaColor};
use crate::slint_generatedMainWindow::AuraDevTuf as SlintAuraDevTuf;
impl From<rog_aura::usb::AuraDevTuf> for SlintAuraDevTuf {
fn from(value: rog_aura::usb::AuraDevTuf) -> Self {
match value {
rog_aura::usb::AuraDevTuf::Boot => SlintAuraDevTuf::Boot,
rog_aura::usb::AuraDevTuf::Awake => SlintAuraDevTuf::Awake,
rog_aura::usb::AuraDevTuf::Sleep => SlintAuraDevTuf::Sleep,
rog_aura::usb::AuraDevTuf::Keyboard => SlintAuraDevTuf::Keyboard,
}
}
}
impl From<SlintAuraDevTuf> for rog_aura::usb::AuraDevTuf {
fn from(value: SlintAuraDevTuf) -> Self {
match value {
SlintAuraDevTuf::Boot => rog_aura::usb::AuraDevTuf::Boot,
SlintAuraDevTuf::Awake => rog_aura::usb::AuraDevTuf::Awake,
SlintAuraDevTuf::Sleep => rog_aura::usb::AuraDevTuf::Sleep,
SlintAuraDevTuf::Keyboard => rog_aura::usb::AuraDevTuf::Keyboard,
}
}
}
use crate::slint_generatedMainWindow::AuraDevRog1 as SlintAuraDevRog1;
impl From<rog_aura::usb::AuraDevRog1> for SlintAuraDevRog1 {
fn from(value: rog_aura::usb::AuraDevRog1) -> Self {
match value {
rog_aura::usb::AuraDevRog1::Awake => SlintAuraDevRog1::Awake,
rog_aura::usb::AuraDevRog1::Keyboard => SlintAuraDevRog1::Keyboard,
rog_aura::usb::AuraDevRog1::Lightbar => SlintAuraDevRog1::Lightbar,
rog_aura::usb::AuraDevRog1::Boot => SlintAuraDevRog1::Boot,
rog_aura::usb::AuraDevRog1::Sleep => SlintAuraDevRog1::Sleep,
}
}
}
impl From<SlintAuraDevRog1> for rog_aura::usb::AuraDevRog1 {
fn from(value: SlintAuraDevRog1) -> Self {
match value {
SlintAuraDevRog1::Awake => rog_aura::usb::AuraDevRog1::Awake,
SlintAuraDevRog1::Keyboard => rog_aura::usb::AuraDevRog1::Keyboard,
SlintAuraDevRog1::Lightbar => rog_aura::usb::AuraDevRog1::Lightbar,
SlintAuraDevRog1::Boot => rog_aura::usb::AuraDevRog1::Boot,
SlintAuraDevRog1::Sleep => rog_aura::usb::AuraDevRog1::Sleep,
}
}
}
use crate::slint_generatedMainWindow::PowerZones as SlintPowerZones;
impl From<rog_aura::aura_detection::PowerZones> for SlintPowerZones {
fn from(value: rog_aura::aura_detection::PowerZones) -> Self {
match value {
rog_aura::aura_detection::PowerZones::Logo => SlintPowerZones::Logo,
rog_aura::aura_detection::PowerZones::Keyboard => SlintPowerZones::Keyboard,
rog_aura::aura_detection::PowerZones::Lightbar => SlintPowerZones::Lightbar,
rog_aura::aura_detection::PowerZones::Lid => SlintPowerZones::Lid,
rog_aura::aura_detection::PowerZones::RearGlow => SlintPowerZones::RearGlow,
PowerZones::Logo => SlintPowerZones::Logo,
PowerZones::Keyboard => SlintPowerZones::Keyboard,
PowerZones::Lightbar => SlintPowerZones::Lightbar,
PowerZones::Lid => SlintPowerZones::Lid,
PowerZones::RearGlow => SlintPowerZones::RearGlow,
PowerZones::KeyboardAndLightbar => todo!(),
}
}
}
@@ -118,134 +76,72 @@ impl From<SlintPowerZones> for rog_aura::aura_detection::PowerZones {
SlintPowerZones::Lightbar => rog_aura::aura_detection::PowerZones::Lightbar,
SlintPowerZones::Lid => rog_aura::aura_detection::PowerZones::Lid,
SlintPowerZones::RearGlow => rog_aura::aura_detection::PowerZones::RearGlow,
SlintPowerZones::KeyboardAndLightbar => {
rog_aura::aura_detection::PowerZones::KeyboardAndLightbar
}
}
}
}
use crate::slint_generatedMainWindow::{
AuraPower as SlintAuraPower, KbAuraPowerState as SlintKbAuraPowerState,
};
impl From<rog_aura::power::AuraPower> for SlintAuraPower {
fn from(value: rog_aura::power::AuraPower) -> Self {
impl From<SlintAuraPowerState> for AuraPowerState {
fn from(value: SlintAuraPowerState) -> Self {
Self {
keyboard: SlintKbAuraPowerState {
awake: value.keyboard.awake,
boot: value.keyboard.boot,
shutdown: value.keyboard.shutdown,
sleep: value.keyboard.sleep,
zone: value.keyboard.zone.into(),
},
lid: SlintKbAuraPowerState {
awake: value.lid.awake,
boot: value.lid.boot,
shutdown: value.lid.shutdown,
sleep: value.lid.sleep,
zone: value.lid.zone.into(),
},
lightbar: SlintKbAuraPowerState {
awake: value.lightbar.awake,
boot: value.lightbar.boot,
shutdown: value.lightbar.shutdown,
sleep: value.lightbar.sleep,
zone: value.lightbar.zone.into(),
},
logo: SlintKbAuraPowerState {
awake: value.logo.awake,
boot: value.logo.boot,
shutdown: value.logo.shutdown,
sleep: value.logo.sleep,
zone: value.logo.zone.into(),
},
rear_glow: SlintKbAuraPowerState {
awake: value.rear_glow.awake,
boot: value.rear_glow.boot,
shutdown: value.rear_glow.shutdown,
sleep: value.rear_glow.sleep,
zone: value.rear_glow.zone.into(),
},
zone: value.zone.into(),
boot: value.boot.into(),
awake: value.awake.into(),
sleep: value.sleep.into(),
shutdown: value.shutdown.into(),
}
}
}
impl From<SlintAuraPower> for rog_aura::power::AuraPower {
fn from(value: SlintAuraPower) -> Self {
Self {
keyboard: KbAuraPowerState {
awake: value.keyboard.awake,
boot: value.keyboard.boot,
shutdown: value.keyboard.shutdown,
sleep: value.keyboard.sleep,
zone: value.keyboard.zone.into(),
},
lid: KbAuraPowerState {
awake: value.lid.awake,
boot: value.lid.boot,
shutdown: value.lid.shutdown,
sleep: value.lid.sleep,
zone: value.lid.zone.into(),
},
lightbar: KbAuraPowerState {
awake: value.lightbar.awake,
boot: value.lightbar.boot,
shutdown: value.lightbar.shutdown,
sleep: value.lightbar.sleep,
zone: value.lightbar.zone.into(),
},
logo: KbAuraPowerState {
awake: value.logo.awake,
boot: value.logo.boot,
shutdown: value.logo.shutdown,
sleep: value.logo.sleep,
zone: value.logo.zone.into(),
},
rear_glow: KbAuraPowerState {
awake: value.rear_glow.awake,
boot: value.rear_glow.boot,
shutdown: value.rear_glow.shutdown,
sleep: value.rear_glow.sleep,
zone: value.rear_glow.zone.into(),
},
impl From<AuraPowerState> for SlintAuraPowerState {
fn from(value: AuraPowerState) -> Self {
let zone = value.zone.into();
SlintAuraPowerState {
boot: value.boot.into(),
awake: value.awake.into(),
sleep: value.sleep.into(),
shutdown: value.shutdown.into(),
zone,
zone_name_idx: zone as i32,
}
}
}
use crate::slint_generatedMainWindow::AuraPowerDev as SlintAuraPowerDev;
impl From<rog_aura::usb::AuraPowerDev> for SlintAuraPowerDev {
fn from(value: rog_aura::usb::AuraPowerDev) -> Self {
let tuf: Vec<SlintAuraDevTuf> = value
.tuf
.iter()
.map(|n| SlintAuraDevTuf::from(*n))
.collect();
let old_rog: Vec<SlintAuraDevRog1> = value
.old_rog
.iter()
.map(|n| SlintAuraDevRog1::from(*n))
.collect();
Self {
tuf: ModelRc::from(tuf.as_slice()),
old_rog: ModelRc::from(old_rog.as_slice()),
rog: value.rog.into(),
impl From<&AuraPowerState> for SlintAuraPowerState {
fn from(value: &AuraPowerState) -> Self {
let zone = value.zone.into();
SlintAuraPowerState {
boot: value.boot.into(),
awake: value.awake.into(),
sleep: value.sleep.into(),
shutdown: value.shutdown.into(),
zone,
zone_name_idx: zone as i32,
}
}
}
impl From<SlintAuraPowerDev> for rog_aura::usb::AuraPowerDev {
fn from(value: SlintAuraPowerDev) -> Self {
let tuf: Vec<rog_aura::usb::AuraDevTuf> = value
.tuf
impl From<SlintLaptopAuraPower> for rog_aura::keyboard::LaptopAuraPower {
fn from(value: SlintLaptopAuraPower) -> Self {
let mut states = Vec::new();
for state in value.states.iter() {
states.push(state.into());
}
Self { states }
}
}
impl From<LaptopAuraPower> for SlintLaptopAuraPower {
fn from(value: LaptopAuraPower) -> Self {
let converted: Vec<SlintAuraPowerState> = value
.states
.iter()
.map(rog_aura::usb::AuraDevTuf::from)
.collect();
let old_rog: Vec<rog_aura::usb::AuraDevRog1> = value
.old_rog
.iter()
.map(rog_aura::usb::AuraDevRog1::from)
.map(|s| SlintAuraPowerState::from(s))
.collect();
Self {
tuf,
old_rog,
rog: value.rog.into(),
states: ModelRc::from(converted.as_slice()),
}
}
}

View File

@@ -1,6 +1,6 @@
use std::sync::{Arc, Mutex};
use rog_aura::usb::AuraPowerDev;
use rog_aura::keyboard::LaptopAuraPower;
use rog_dbus::zbus_aura::AuraProxy;
use slint::{ComponentHandle, Model, RgbaColor, SharedString};
@@ -166,11 +166,11 @@ pub fn setup_aura_page(ui: &MainWindow, _states: Arc<Mutex<Config>>) {
.on_set_led_power(move |power| {
let handle_copy = handle_copy.clone();
let proxy_copy = aura.clone();
let power: AuraPowerDev = power.into();
let power: LaptopAuraPower = power.into();
tokio::spawn(async move {
show_toast(
"Anime builtin animations changed".into(),
"Failed to set Anime builtin animations".into(),
"Aura power settings changed".into(),
"Failed to set Aura power settings".into(),
handle_copy,
proxy_copy.set_led_power(power).await,
);

View File

@@ -11,10 +11,8 @@ use std::time::Duration;
use log::{error, info, trace, warn};
use notify_rust::{Hint, Notification, NotificationHandle, Urgency};
use rog_dbus::zbus_anime::AnimeProxy;
use rog_dbus::zbus_aura::AuraProxy;
use rog_dbus::zbus_platform::PlatformProxy;
use rog_platform::platform::{GpuMode, ThrottlePolicy};
use rog_platform::platform::GpuMode;
use serde::{Deserialize, Serialize};
use supergfxctl::actions::UserActionRequired as GfxUserAction;
use supergfxctl::pci_device::{GfxMode, GfxPower};
@@ -31,45 +29,12 @@ const NOTIF_HEADER: &str = "ROG Control";
static mut POWER_AC_CMD: Option<Command> = None;
static mut POWER_BAT_CMD: Option<Command> = None;
#[derive(Debug, Clone, Deserialize, Serialize)]
#[derive(Debug, Default, Clone, Deserialize, Serialize)]
#[serde(default)]
pub struct EnabledNotifications {
pub receive_boot_sound_changed: bool,
pub receive_panel_od_changed: bool,
pub receive_mini_led_mode_changed: bool,
pub receive_dgpu_disable_changed: bool,
pub receive_egpu_enable_changed: bool,
pub receive_gpu_mux_mode_changed: bool,
pub receive_charge_control_end_threshold_changed: bool,
pub receive_notify_mains_online: bool,
pub receive_throttle_thermal_policy_changed: bool,
pub receive_led_mode_data_changed: bool,
/// Anime
pub receive_power_states: bool,
pub receive_notify_gfx: bool,
pub receive_notify_gfx_status: bool,
pub all_enabled: bool,
}
impl Default for EnabledNotifications {
fn default() -> Self {
Self {
receive_boot_sound_changed: false,
receive_panel_od_changed: true,
receive_mini_led_mode_changed: true,
receive_dgpu_disable_changed: true,
receive_egpu_enable_changed: true,
receive_gpu_mux_mode_changed: true,
receive_charge_control_end_threshold_changed: true,
receive_notify_mains_online: false,
receive_throttle_thermal_policy_changed: true,
receive_led_mode_data_changed: true,
receive_power_states: false,
receive_notify_gfx: false,
receive_notify_gfx_status: false,
all_enabled: false,
}
}
}
impl EnabledNotifications {
@@ -78,6 +43,18 @@ impl EnabledNotifications {
}
}
fn gpu_to_gfx(value: GpuMode) -> GfxMode {
match value {
GpuMode::Optimus => GfxMode::Hybrid,
GpuMode::Integrated => GfxMode::Integrated,
GpuMode::Egpu => GfxMode::AsusEgpu,
GpuMode::Vfio => GfxMode::Vfio,
GpuMode::Ultimate => GfxMode::AsusMuxDgpu,
GpuMode::Error => GfxMode::None,
GpuMode::NotSupported => GfxMode::None,
}
}
// TODO: drop the macro and use generics plus closure
macro_rules! recv_notif {
($proxy:ident,
@@ -107,7 +84,7 @@ macro_rules! recv_notif {
while let Some(e) = p.next().await {
if let Ok(out) = e.args() {
if let Ok(config) = notifs_enabled1.lock() {
if config.all_enabled && config.$signal {
if config.$signal {
trace!("zbus signal {}", stringify!($signal));
$notifier($msg, &out.$($out_arg)+()).ok();
}
@@ -124,49 +101,6 @@ macro_rules! recv_notif {
};
}
macro_rules! recv_changed {
($proxy:ident,
$signal:ident,
$last_notif:ident,
$notif_enabled:ident,
$page_states:ident,
($($args: tt)*),
// ($($out_arg:tt)+),
$msg:literal,
$notifier:ident) => {
let notifs_enabled1 = $notif_enabled.clone();
let page_states1 = $page_states.clone();
tokio::spawn(async move {
let conn = zbus::Connection::system().await.map_err(|e| {
log::error!("zbus signal: {}: {e}", stringify!($signal));
e
}).unwrap();
let proxy = $proxy::new(&conn).await.map_err(|e| {
log::error!("zbus signal: {}: {e}", stringify!($signal));
e
}).unwrap();
info!("Started zbus signal thread: {}", stringify!($signal));
while let Some(e) = proxy.$signal().await.next().await {
if let Ok(out) = e.get().await {
if let Ok(config) = notifs_enabled1.lock() {
if config.all_enabled && config.$signal {
trace!("zbus signal {}", stringify!($signal));
$notifier($msg, &out).ok();
}
}
if let Ok(mut lock) = page_states1.lock() {
lock.$($args)+ = out.into();
lock.set_notified();
}
}
sleep(Duration::from_millis(500)).await;
}
});
};
}
pub fn start_notifications(
config: &Config,
page_states: &Arc<Mutex<SystemState>>,
@@ -196,155 +130,6 @@ pub fn start_notifications(
}
}
// BIOS notif
recv_changed!(
PlatformProxy,
receive_boot_sound_changed,
last_notification,
enabled_notifications,
page_states,
(bios.post_sound),
"BIOS Post sound",
do_notification
);
recv_changed!(
PlatformProxy,
receive_panel_od_changed,
last_notification,
enabled_notifications,
page_states,
(bios.panel_overdrive),
"Panel Overdrive enabled:",
do_notification
);
recv_changed!(
PlatformProxy,
receive_mini_led_mode_changed,
last_notification,
enabled_notifications,
page_states,
(bios.mini_led_mode),
"MiniLED mode enabled:",
do_notification
);
recv_changed!(
PlatformProxy,
receive_dgpu_disable_changed,
last_notification,
enabled_notifications,
page_states,
(bios.dgpu_disable),
"BIOS dGPU disabled",
do_notification
);
recv_changed!(
PlatformProxy,
receive_egpu_enable_changed,
last_notification,
enabled_notifications,
page_states,
(bios.egpu_enable),
"BIOS eGPU enabled",
do_notification
);
// Charge notif
recv_changed!(
PlatformProxy,
receive_charge_control_end_threshold_changed,
last_notification,
enabled_notifications,
page_states,
(bios.charge_limit),
"Battery charge limit changed to",
do_notification
);
// Profile notif
recv_changed!(
PlatformProxy,
receive_throttle_thermal_policy_changed,
last_notification,
enabled_notifications,
page_states,
(bios.throttle),
"Profile changed to",
do_thermal_notif
);
// notify!(do_thermal_notif(&out.profile), lock);
// LED notif
recv_changed!(
AuraProxy,
receive_led_mode_data_changed,
last_notification,
enabled_notifications,
page_states,
(aura.current_mode),
"Keyboard LED mode changed to",
do_notification
);
// let page_states1 = page_states.clone();
// tokio::spawn(async move {
// let conn = zbus::Connection::system()
// .await
// .map_err(|e| {
// error!("zbus signal: receive_device_state: {e}");
// e
// })
// .unwrap();
// let proxy = AuraProxy::new(&conn)
// .await
// .map_err(|e| {
// error!("zbus signal: receive_device_state: {e}");
// e
// })
// .unwrap();
// let p = proxy.receive_led_power_changed().await;
// info!("Started zbus signal thread: receive_notify_power_states");
// while let Some(e) = p.next().await {
// if let Ok(out) = e.get().await {
// if let Ok(mut lock) = page_states1.lock() {
// lock.aura.enabled = out;
// lock.set_notified();
// }
// }
// }
// });
let page_states1 = page_states.clone();
tokio::spawn(async move {
let conn = zbus::Connection::system()
.await
.map_err(|e| {
error!("zbus signal: receive_device_state: {e}");
e
})
.unwrap();
let proxy = AnimeProxy::new(&conn)
.await
.map_err(|e| {
error!("zbus signal: receive_device_state: {e}");
e
})
.unwrap();
if let Ok(mut p) = proxy.receive_notify_device_state().await {
info!("Started zbus signal thread: receive_device_state");
while let Some(e) = p.next().await {
if let Ok(out) = e.args() {
if let Ok(mut lock) = page_states1.lock() {
lock.anime = out.data.into();
}
}
}
};
});
let page_states1 = page_states.clone();
tokio::spawn(async move {
let conn = zbus::Connection::system()
@@ -375,7 +160,7 @@ pub fn start_notifications(
continue;
}
if let Ok(mut lock) = page_states1.lock() {
lock.bios.gpu_mux_mode = Some(mode);
lock.gfx_state.mode = gpu_to_gfx(mode);
lock.set_notified();
}
do_mux_notification("Reboot required. BIOS GPU MUX mode set to", &mode).ok();
@@ -397,7 +182,7 @@ pub fn start_notifications(
if let Ok(status) = dev.get_runtime_status() {
if status != GfxPower::Unknown && status != last_status {
if let Ok(config) = notifs_enabled1.lock() {
if config.all_enabled && config.receive_notify_gfx_status {
if config.receive_notify_gfx_status {
// Required check because status cycles through
// active/unknown/suspended
do_gpu_status_notif("dGPU status changed:", &status).ok();
@@ -498,7 +283,7 @@ fn convert_gfx_mode(gfx: GfxMode) -> GpuMode {
match gfx {
GfxMode::Hybrid => GpuMode::Optimus,
GfxMode::Integrated => GpuMode::Integrated,
GfxMode::NvidiaNoModeset => GpuMode::Discrete,
GfxMode::NvidiaNoModeset => GpuMode::Optimus,
GfxMode::Vfio => GpuMode::Vfio,
GfxMode::AsusEgpu => GpuMode::Egpu,
GfxMode::AsusMuxDgpu => GpuMode::Ultimate,
@@ -553,17 +338,6 @@ fn _ac_power_notification(message: &str, on: &bool) -> Result<NotificationHandle
Ok(base_notification(message, &data).show()?)
}
fn do_thermal_notif(message: &str, profile: &ThrottlePolicy) -> Result<NotificationHandle> {
let icon = match profile {
ThrottlePolicy::Balanced => "asus_notif_yellow",
ThrottlePolicy::Performance => "asus_notif_red",
ThrottlePolicy::Quiet => "asus_notif_green",
};
let profile: &str = (*profile).into();
let mut notif = base_notification(message, &profile.to_uppercase());
Ok(notif.icon(icon).show()?)
}
fn do_gpu_status_notif(message: &str, data: &GfxPower) -> Result<NotificationHandle> {
// eww
let mut notif = base_notification(message, &<&str>::from(data).to_owned());