mirror of
https://gitlab.com/asus-linux/asusctl.git
synced 2026-02-06 00:15:04 +01:00
Enable tray and notifs without supergfx
This commit is contained in:
@@ -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>(())
|
||||
});
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user