Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 0 additions & 24 deletions data/com.system76.PowerDaemon.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,30 +28,6 @@
<arg name="profiles" type="aa{sv}" direction="out"/>
</method>

<method name="GetDefaultGraphics">
<arg name="vendor" type="s" direction="out"/>
</method>

<method name="GetGraphics">
<arg name="vendor" type="s" direction="out"/>
</method>

<method name="SetGraphics">
<arg name="vendor" type="s" direction="in"/>
</method>

<method name="GetGraphicsPower">
<arg name="power" type="b" direction="out"/>
</method>

<method name="SetGraphicsPower">
<arg name="power" type="b" direction="in"/>
</method>

<method name="GetSwitchable">
<arg name="switchable" type="b" direction="out"/>
</method>

<method name="GetDesktop">
<arg name="desktop" type="b" direction="out"/>
</method>
Expand Down
32 changes: 0 additions & 32 deletions src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,6 @@

use clap::{builder::PossibleValuesParser, Parser};

#[derive(Parser)]
#[clap(
about = "Query or set the graphics mode",
long_about = "Query or set the graphics mode.\n\n - If an argument is not provided, the \
graphics profile will be queried\n - Otherwise, that profile will be set, if it \
is a valid profile\n\nA reboot is required after switching modes."
)]
pub enum GraphicsArgs {
#[clap(about = "Like integrated, but the dGPU is available for compute")]
Compute,
#[clap(about = "Set the graphics mode to Hybrid (PRIME)")]
Hybrid,
#[clap(about = "Set the graphics mode to integrated")]
Integrated,
#[clap(about = "Set the graphics mode to NVIDIA")]
Nvidia,
#[clap(about = "Determines if the system has switchable graphics")]
Switchable,
#[clap(about = "Query or set the discrete graphics power state")]
Power {
#[clap(help = "Set whether discrete graphics should be on or off")]
#[arg(
value_parser = PossibleValuesParser::new(["auto", "off", "on"])
)]
state: Option<String>,
},
}

#[derive(Parser)]
#[clap(
name = "system76-power",
Expand Down Expand Up @@ -78,10 +50,6 @@ pub enum Args {
)]
profile: Option<String>,
},
Graphics {
#[clap(subcommand)]
cmd: Option<GraphicsArgs>,
},
#[clap(
about = "Set thresholds for battery charging",
// Autogenerated usage seemed to have issues
Expand Down
49 changes: 1 addition & 48 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// SPDX-License-Identifier: GPL-3.0-only

use crate::args::{Args, GraphicsArgs};
use crate::args::Args;
use anyhow::Context;
use intel_pstate::PState;
use std::io;
Expand Down Expand Up @@ -75,53 +75,6 @@ Battery power profile is not supported on desktop computers.
Some("performance") => client.performance().await.map_err(zbus_error),
_ => profile(&mut client).await.context("failed to get power profile"),
},
Args::Graphics { cmd } => {
if !client.get_switchable().await? {
return Err(anyhow::anyhow!(
r#"
Graphics switching is not supported on this device, because
this device is either a desktop or doesn't have both an iGPU and dGPU.
"#,
));
}

match cmd.as_ref() {
Some(GraphicsArgs::Compute) => {
client.set_graphics("compute").await.map_err(zbus_error)
}
Some(GraphicsArgs::Hybrid) => {
client.set_graphics("hybrid").await.map_err(zbus_error)
}
Some(GraphicsArgs::Integrated) => {
client.set_graphics("integrated").await.map_err(zbus_error)
}
Some(GraphicsArgs::Nvidia) => {
client.set_graphics("nvidia").await.map_err(zbus_error)
}
Some(GraphicsArgs::Switchable) => client
.get_switchable()
.await
.map_err(zbus_error)
.map(|b| println!("{}", if b { "switchable" } else { "not switchable" })),
Some(GraphicsArgs::Power { state }) => match state.as_deref() {
Some("auto") => client.auto_graphics_power().await.map_err(zbus_error),
Some("off") => client.set_graphics_power(false).await.map_err(zbus_error),
Some("on") => client.set_graphics_power(true).await.map_err(zbus_error),
_ => {
if client.get_graphics_power().await.map_err(zbus_error)? {
println!("on (discrete)");
} else {
println!("off (discrete)");
}
Ok(())
}
},
None => {
println!("{}", client.get_graphics().await.map_err(zbus_error)?);
Ok(())
}
}
}
Args::ChargeThresholds { profile, list_profiles, thresholds } => {
if client.get_desktop().await.map_err(zbus_error)? {
return Err(anyhow::anyhow!(
Expand Down
58 changes: 1 addition & 57 deletions src/daemon/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use crate::{
charge_thresholds::{get_charge_profiles, get_charge_thresholds, set_charge_thresholds},
errors::ProfileError,
fan::FanDaemon,
graphics::{Graphics, GraphicsMode},
graphics::Graphics,
hid_backlight,
hotplug::{mux, Detect, HotPlugDetect},
kernel_parameters::{KernelParameter, NmiWatchdog},
Expand Down Expand Up @@ -238,60 +238,11 @@ impl System76Power {
.map_err(zbus_error_from_display)
}

#[dbus_interface(out_args("vendor"))]
async fn get_default_graphics(&self) -> zbus::fdo::Result<String> {
self.0
.lock()
.await
.graphics
.get_default_graphics()
.map_err(zbus_error_from_display)
.map(|mode| <&'static str>::from(mode).to_owned())
}

#[dbus_interface(out_args("vendor"))]
async fn get_graphics(&self) -> zbus::fdo::Result<String> {
self.0
.lock()
.await
.graphics
.get_vendor()
.map_err(zbus_error_from_display)
.map(|mode| <&'static str>::from(mode).to_owned())
}

async fn set_graphics(&mut self, vendor: &str) -> zbus::fdo::Result<()> {
self.0
.lock()
.await
.graphics
.set_vendor(GraphicsMode::from(vendor))
.map_err(zbus_error_from_display)
}

#[dbus_interface(out_args("desktop"))]
async fn get_desktop(&mut self) -> zbus::fdo::Result<bool> {
Ok(self.0.lock().await.graphics.is_desktop())
}

#[dbus_interface(out_args("switchable"))]
async fn get_switchable(&mut self) -> zbus::fdo::Result<bool> {
Ok(self.0.lock().await.graphics.can_switch())
}

#[dbus_interface(out_args("power"))]
async fn get_graphics_power(&mut self) -> zbus::fdo::Result<bool> {
self.0.lock().await.graphics.get_power().map_err(zbus_error_from_display)
}

async fn set_graphics_power(&mut self, power: bool) -> zbus::fdo::Result<()> {
self.0.lock().await.graphics.set_power(power).map_err(zbus_error_from_display)
}

async fn auto_graphics_power(&mut self) -> zbus::fdo::Result<()> {
self.0.lock().await.graphics.auto_power().map_err(zbus_error_from_display)
}

#[dbus_interface(out_args("start", "end"))]
async fn get_charge_thresholds(&mut self) -> zbus::fdo::Result<(u8, u8)> {
get_charge_thresholds().map_err(zbus_error_from_display)
Expand Down Expand Up @@ -532,13 +483,6 @@ pub async fn daemon() -> anyhow::Result<()> {
let daemon = Arc::new(Mutex::new(daemon));
let mut system76_daemon = System76Power(daemon.clone());

match system76_daemon.auto_graphics_power().await {
Ok(()) => (),
Err(err) => {
log::warn!("Failed to set automatic graphics power: {}", err);
}
}

let vendor = fs::read_to_string("/sys/class/dmi/id/sys_vendor")?;
let model = fs::read_to_string("/sys/class/dmi/id/product_version")?;
match runtime_pm_quirks(&vendor, &model) {
Expand Down
Loading