Enable tray and notifs without supergfx

This commit is contained in:
Luke D. Jones
2024-05-24 12:58:37 +12:00
parent e443ab00c9
commit 792fae3ed7
6 changed files with 166 additions and 128 deletions

View File

@@ -51,6 +51,10 @@ fn start_dpu_status_mon(config: Arc<Mutex<Config>>) {
let mut found_dgpu = false; // just for logging
for dev in dev {
if dev.is_dgpu() {
info!(
"Found dGPU: {}, starting status notifications",
dev.pci_id()
);
let enabled_notifications_copy = config.clone();
// Plain old thread is perfectly fine since most of this is potentially blocking
std::thread::spawn(move || {
@@ -138,6 +142,13 @@ pub fn start_notifications(
}
});
let enabled_notifications_copy = config.clone();
let no_supergfx = move |e: &zbus::Error| {
error!("zbus signal: receive_notify_gfx_status: {e}");
warn!("Attempting to start plain dgpu status monitor");
start_dpu_status_mon(enabled_notifications_copy.clone());
};
// GPU MUX Mode notif
let enabled_notifications_copy = config.clone();
tokio::spawn(async move {
@@ -176,68 +187,65 @@ pub fn start_notifications(
let enabled_notifications_copy = config.clone();
// GPU Mode change/action notif
tokio::spawn(async move {
if let Err(e) = {
let conn = zbus::Connection::system().await?;
let proxy = SuperProxy::builder(&conn).build().await?;
let _ = proxy.mode().await?;
let conn = zbus::Connection::system().await.map_err(|e| {
no_supergfx(&e);
e
})?;
let proxy = SuperProxy::builder(&conn).build().await.map_err(|e| {
no_supergfx(&e);
e
})?;
let _ = proxy.mode().await.map_err(|e| {
no_supergfx(&e);
e
})?;
let proxy_copy = proxy.clone();
if let Ok(mut p) = proxy.receive_notify_action().await {
tokio::spawn(async move {
info!("Started zbus signal thread: receive_notify_action");
while let Some(e) = p.next().await {
if let Ok(out) = e.args() {
let action = out.action();
let mode = convert_gfx_mode(proxy.mode().await.unwrap_or_default());
match action {
supergfxctl::actions::UserActionRequired::Reboot => {
do_mux_notification(
"Graphics mode change requires reboot",
&mode,
)
}
_ => do_gfx_action_notif(<&str>::from(action), *action, mode),
}
.map_err(|e| {
error!("zbus signal: do_gfx_action_notif: {e}");
e
})
.ok();
let proxy_copy = proxy.clone();
let mut p = proxy.receive_notify_action().await?;
tokio::spawn(async move {
info!("Started zbus signal thread: receive_notify_action");
while let Some(e) = p.next().await {
if let Ok(out) = e.args() {
let action = out.action();
let mode = convert_gfx_mode(proxy.mode().await.unwrap_or_default());
match action {
supergfxctl::actions::UserActionRequired::Reboot => {
do_mux_notification("Graphics mode change requires reboot", &mode)
}
_ => do_gfx_action_notif(<&str>::from(action), *action, mode),
}
});
};
.map_err(|e| {
error!("zbus signal: do_gfx_action_notif: {e}");
e
})
.ok();
}
}
});
if let Ok(mut p) = proxy_copy.receive_notify_gfx_status().await {
tokio::spawn(async move {
info!("Started zbus signal thread: receive_notify_gfx_status");
let mut last_status = GfxPower::Unknown;
while let Some(e) = p.next().await {
if let Ok(out) = e.args() {
let status = out.status;
if status != GfxPower::Unknown && status != last_status {
if let Ok(config) = enabled_notifications_copy.lock() {
if !config.notifications.receive_notify_gfx_status
|| !config.notifications.enabled
{
continue;
}
}
// Required check because status cycles through
// active/unknown/suspended
do_gpu_status_notif("dGPU status changed:", &status).ok();
let mut p = proxy_copy.receive_notify_gfx_status().await?;
tokio::spawn(async move {
info!("Started zbus signal thread: receive_notify_gfx_status");
let mut last_status = GfxPower::Unknown;
while let Some(e) = p.next().await {
if let Ok(out) = e.args() {
let status = out.status;
if status != GfxPower::Unknown && status != last_status {
if let Ok(config) = enabled_notifications_copy.lock() {
if !config.notifications.receive_notify_gfx_status
|| !config.notifications.enabled
{
continue;
}
last_status = status;
}
// Required check because status cycles through
// active/unknown/suspended
do_gpu_status_notif("dGPU status changed:", &status).ok();
}
});
};
Ok::<(), zbus::Error>(())
} {
error!("zbus signal: receive_notify_gfx_status: {e}");
info!("Attempting to start plain dgpu status monitor");
start_dpu_status_mon(config.clone());
}
last_status = status;
}
}
});
Ok::<(), zbus::Error>(())
});

View File

@@ -12,7 +12,7 @@ use std::time::Duration;
use betrayer::{Icon, Menu, MenuItem, TrayEvent, TrayIcon, TrayIconBuilder};
use log::{debug, error, info, warn};
use rog_platform::platform::Properties;
use supergfxctl::pci_device::{GfxMode, GfxPower};
use supergfxctl::pci_device::{Device, GfxMode, GfxPower};
use supergfxctl::zbus_proxy::DaemonProxyBlocking as GfxProxy;
use versions::Versioning;
@@ -71,7 +71,7 @@ fn build_menu() -> Menu<TrayAction> {
Menu::new([
MenuItem::separator(),
MenuItem::button("Open", TrayAction::Open),
MenuItem::button("Quit", TrayAction::Quit),
MenuItem::button("Quit App", TrayAction::Quit),
])
}
@@ -126,6 +126,20 @@ fn set_tray_icon_and_tip(
}
}
fn find_dgpu() -> Option<Device> {
use supergfxctl::pci_device::Device;
let dev = Device::find().unwrap_or_default();
for dev in dev {
if dev.is_dgpu() {
info!("Found dGPU: {}", dev.pci_id());
// Plain old thread is perfectly fine since most of this is potentially blocking
return Some(dev);
}
}
warn!("Did not find a dGPU on this system, dGPU status won't be avilable");
None
}
/// The tray is controlled somewhat by `Arc<Mutex<SystemState>>`
pub fn init_tray(_supported_properties: Vec<Properties>, config: Arc<Mutex<Config>>) {
std::thread::spawn(move || {
@@ -155,27 +169,30 @@ pub fn init_tray(_supported_properties: Vec<Properties>, config: Arc<Mutex<Confi
gpu_integrated,
});
let mut has_supergfx = true;
let mut has_supergfx = false;
let conn = zbus::blocking::Connection::system().unwrap();
if let Ok(gfx_proxy) = GfxProxy::new(&conn) {
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.2.0").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");
has_supergfx = false;
match gfx_proxy.mode() {
Ok(_) => {
has_supergfx = true;
if let Ok(version) = gfx_proxy.version() {
if let Some(version) = Versioning::new(&version) {
let curr_gfx = Versioning::new("5.2.0").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");
has_supergfx = false;
}
}
}
}
};
Err(e) => warn!("Couldn't get mode form supergfxd: {e:?}"),
}
info!("Started ROGTray");
let mut last_power = GfxPower::Unknown;
let dev = find_dgpu();
loop {
sleep(Duration::from_millis(1000));
if let Ok(lock) = config.try_lock() {
@@ -187,11 +204,23 @@ pub fn init_tray(_supported_properties: Vec<Properties>, config: Arc<Mutex<Confi
if let Ok(mode) = gfx_proxy.mode() {
if let Ok(power) = gfx_proxy.power() {
if last_power != power {
set_tray_icon_and_tip(mode, power, &mut tray, supergfx_active);
set_tray_icon_and_tip(mode, power, &mut tray, has_supergfx);
last_power = power;
}
}
}
} else if let Some(dev) = dev.as_ref() {
if let Ok(power) = dev.get_runtime_status() {
if last_power != power {
set_tray_icon_and_tip(
GfxMode::Hybrid,
power,
&mut tray,
has_supergfx,
);
last_power = power;
}
}
}
}
}

View File

@@ -2,7 +2,7 @@
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"POT-Creation-Date: 2024-05-20 22:11+0000\n"
"POT-Creation-Date: 2024-05-24 00:58+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@@ -334,37 +334,37 @@ msgstr ""
#: rog-control-center/ui/pages/system.slint:188
msgctxt "ppt_pl1_spl"
msgid "ppt_pl1_spl"
msgid "PL1, Sustained Power Limit"
msgstr ""
#: rog-control-center/ui/pages/system.slint:198
msgctxt "ppt_pl2_sppt"
msgid "ppt_pl2_sppt"
msgid "PL2, turbo power limit"
msgstr ""
#: rog-control-center/ui/pages/system.slint:208
msgctxt "ppt_fppt"
msgid "ppt_fppt"
msgid "fPPT, fast power limit"
msgstr ""
#: rog-control-center/ui/pages/system.slint:218
msgctxt "ppt_apu_sppt"
msgid "ppt_apu_sppt"
msgid "sPPT, APU slow power limit"
msgstr ""
#: rog-control-center/ui/pages/system.slint:228
msgctxt "ppt_platform_sppt"
msgid "ppt_platform_sppt"
msgid "Slow Package Power Tracking Limit"
msgstr ""
#: rog-control-center/ui/pages/system.slint:238
msgctxt "nv_dynamic_boost"
msgid "nv_dynamic_boost"
msgid "dGPU boost overclock"
msgstr ""
#: rog-control-center/ui/pages/system.slint:248
msgctxt "nv_temp_target"
msgid "nv_temp_target"
msgid "dGPU temperature max"
msgstr ""
#: rog-control-center/ui/pages/system.slint:294
@@ -412,46 +412,6 @@ msgctxt "PageSystem"
msgid "Throttle Policy on AC"
msgstr ""
#: rog-control-center/ui/widgets/aura_power.slint:33
msgctxt "AuraPowerGroup"
msgid "Boot"
msgstr ""
#: rog-control-center/ui/widgets/aura_power.slint:43
msgctxt "AuraPowerGroup"
msgid "Awake"
msgstr ""
#: rog-control-center/ui/widgets/aura_power.slint:53
msgctxt "AuraPowerGroup"
msgid "Sleep"
msgstr ""
#: rog-control-center/ui/widgets/aura_power.slint:63
msgctxt "AuraPowerGroup"
msgid "Shutdown"
msgstr ""
#: rog-control-center/ui/widgets/aura_power.slint:102
msgctxt "AuraPowerGroupOld"
msgid "Zone Selection"
msgstr ""
#: rog-control-center/ui/widgets/aura_power.slint:114
msgctxt "AuraPowerGroupOld"
msgid "Boot"
msgstr ""
#: rog-control-center/ui/widgets/aura_power.slint:124
msgctxt "AuraPowerGroupOld"
msgid "Awake"
msgstr ""
#: rog-control-center/ui/widgets/aura_power.slint:134
msgctxt "AuraPowerGroupOld"
msgid "Sleep"
msgstr ""
#: rog-control-center/ui/types/aura_types.slint:49
msgctxt "Aura power zone"
msgid "Logo"
@@ -642,6 +602,46 @@ msgctxt "Aura speed"
msgid "High"
msgstr ""
#: rog-control-center/ui/widgets/aura_power.slint:33
msgctxt "AuraPowerGroup"
msgid "Boot"
msgstr ""
#: rog-control-center/ui/widgets/aura_power.slint:43
msgctxt "AuraPowerGroup"
msgid "Awake"
msgstr ""
#: rog-control-center/ui/widgets/aura_power.slint:53
msgctxt "AuraPowerGroup"
msgid "Sleep"
msgstr ""
#: rog-control-center/ui/widgets/aura_power.slint:63
msgctxt "AuraPowerGroup"
msgid "Shutdown"
msgstr ""
#: rog-control-center/ui/widgets/aura_power.slint:102
msgctxt "AuraPowerGroupOld"
msgid "Zone Selection"
msgstr ""
#: rog-control-center/ui/widgets/aura_power.slint:114
msgctxt "AuraPowerGroupOld"
msgid "Boot"
msgstr ""
#: rog-control-center/ui/widgets/aura_power.slint:124
msgctxt "AuraPowerGroupOld"
msgid "Awake"
msgstr ""
#: rog-control-center/ui/widgets/aura_power.slint:134
msgctxt "AuraPowerGroupOld"
msgid "Sleep"
msgstr ""
#: rog-control-center/ui/main_window.slint:51
msgctxt "MainWindow"
msgid "ROG"
@@ -679,6 +679,6 @@ msgstr ""
#: rog-control-center/ui/main_window.slint:70
msgctxt "MainWindow"
msgid "Quit"
msgid "Quit App"
msgstr ""

View File

@@ -67,7 +67,7 @@ export component MainWindow inherits Window {
Text {
vertical-alignment: center;
horizontal-alignment: center;
text: @tr("Quit");
text: @tr("Quit App");
}
TouchArea {

View File

@@ -185,7 +185,7 @@ export component PageSystem inherits Rectangle {
}
if SystemPageData.available.ppt-pl1-spl: SystemSlider {
text: @tr("ppt_pl1_spl" => "ppt_pl1_spl");
text: @tr("ppt_pl1_spl" => "PL1, Sustained Power Limit");
minimum: 5;
maximum: 250;
value <=> SystemPageData.ppt_pl1_spl;
@@ -195,7 +195,7 @@ export component PageSystem inherits Rectangle {
}
if SystemPageData.available.ppt-pl2-sppt: SystemSlider {
text: @tr("ppt_pl2_sppt" => "ppt_pl2_sppt");
text: @tr("ppt_pl2_sppt" => "PL2, turbo power limit");
minimum: 5;
maximum: 250;
value <=> SystemPageData.ppt_pl2_sppt;
@@ -205,7 +205,7 @@ export component PageSystem inherits Rectangle {
}
if SystemPageData.available.ppt-fppt: SystemSlider {
text: @tr("ppt_fppt" => "ppt_fppt");
text: @tr("ppt_fppt" => "fPPT, fast power limit");
minimum: 5;
maximum: 250;
value <=> SystemPageData.ppt_fppt;
@@ -215,7 +215,7 @@ export component PageSystem inherits Rectangle {
}
if SystemPageData.available.ppt-apu-sppt: SystemSlider {
text: @tr("ppt_apu_sppt" => "ppt_apu_sppt");
text: @tr("ppt_apu_sppt" => "sPPT, APU slow power limit");
minimum: 5;
maximum: 130;
value <=> SystemPageData.ppt_apu_sppt;
@@ -225,7 +225,7 @@ export component PageSystem inherits Rectangle {
}
if SystemPageData.available.ppt-platform-sppt: SystemSlider {
text: @tr("ppt_platform_sppt" => "ppt_platform_sppt");
text: @tr("ppt_platform_sppt" => "Slow Package Power Tracking Limit");
maximum: 130;
minimum: 5;
value <=> SystemPageData.ppt_platform_sppt;
@@ -235,7 +235,7 @@ export component PageSystem inherits Rectangle {
}
if SystemPageData.available.nv-dynamic-boost: SystemSlider {
text: @tr("nv_dynamic_boost" => "nv_dynamic_boost");
text: @tr("nv_dynamic_boost" => "dGPU boost overclock");
minimum: 5;
maximum: 25;
value <=> SystemPageData.nv_dynamic_boost;
@@ -245,7 +245,7 @@ export component PageSystem inherits Rectangle {
}
if SystemPageData.available.nv-temp-target: SystemSlider {
text: @tr("nv_temp_target" => "nv_temp_target");
text: @tr("nv_temp_target" => "dGPU temperature max");
minimum: 75;
maximum: 87;
value <=> SystemPageData.nv_temp_target;