diff --git a/src/app/mod.rs b/src/app/mod.rs index 0de53d9d..21dcf29a 100644 --- a/src/app/mod.rs +++ b/src/app/mod.rs @@ -135,11 +135,28 @@ pub(crate) fn iced_settings( /// /// Returns error on application failure. pub fn run(settings: Settings, flags: App::Flags) -> iced::Result { + #[cfg(feature = "wgpu")] + wgpu_power_pref(); + let settings = iced_settings::(settings, flags); cosmic::Cosmic::::run(settings) } +/// Default to rendering the application with the low power GPU preference. +#[cfg(feature = "wgpu")] +fn wgpu_power_pref() { + // Ignore if requested to run on NVIDIA GPU + if std::env::var("__NV_PRIME_RENDER_OFFLOAD").ok().as_deref() == Some("1") { + return; + } + + const VAR: &str = "WGPU_POWER_PREF"; + if std::env::var(VAR).is_err() { + std::env::set_var(VAR, "low"); + } +} + #[cfg(feature = "single-instance")] #[derive(Debug, Clone)] pub struct DbusActivationMessage> {