From 7c9f04adccfb33af9d2ee2e02a733e4407850440 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Thu, 29 Jan 2026 12:16:00 -0700 Subject: [PATCH] Fix compilation without wgpu feature --- cosmic-settings/src/pages/system/info.rs | 115 +++++++++++++---------- 1 file changed, 64 insertions(+), 51 deletions(-) diff --git a/cosmic-settings/src/pages/system/info.rs b/cosmic-settings/src/pages/system/info.rs index a1158ff..97a96a9 100644 --- a/cosmic-settings/src/pages/system/info.rs +++ b/cosmic-settings/src/pages/system/info.rs @@ -1,6 +1,7 @@ // Copyright 2023 System76 // SPDX-License-Identifier: GPL-3.0-only +#[cfg(feature = "wgpu")] use cosmic::iced_wgpu::wgpu; use std::{collections::HashMap, collections::HashSet, ffi::OsStr, process::Command}; @@ -21,55 +22,9 @@ pub struct Info { } impl Info { - pub fn load() -> Info { - let mut info = Info { - os_architecture: architecture(), - kernel_version: kernel_version(), - hardware_model: hardware_model(), - operating_system: operating_system(), - processor: processor_name(), - ..Default::default() - }; - - let mut sys = sysinfo::System::new(); - let disks = sysinfo::Disks::new_with_refreshed_list(); - sys.refresh_memory(); - - let mut total_capacity = 0; - let mut disk_set = HashSet::new(); - for disk in disks.list() { - if disk_set.contains(disk.name()) { - continue; - } - disk_set.insert(disk.name()); - total_capacity += disk.total_space(); - } - - info.disk_capacity = format_size(total_capacity); - - if let Some(name) = sysinfo::System::host_name() { - info.device_name = name; - } - - info.memory = format_size(sys.total_memory()); - - if let Ok(mut session) = std::env::var("XDG_SESSION_TYPE") { - if let Some(first) = session.get_mut(0..1) { - first.make_ascii_uppercase(); - } - info.windowing_system = session; - } - - // prefer XDG_SESSION_DESKTOP because the value is singular - if let Ok(mut session) = std::env::var("XDG_SESSION_DESKTOP") - .or_else(|_| std::env::var("XDG_CURRENT_DESKTOP")) - .or_else(|_| std::env::var("DESKTOP_SESSION")) - { - if let Some(first) = session.get_mut(0..1) { - first.make_ascii_uppercase(); - } - info.desktop_environment = session; - } + #[cfg(feature = "wgpu")] + fn wgpu_graphics() -> Vec { + let mut graphics = Vec::new(); // Use wgpu to enumerate GPUs. Works cross-platform and doesn't require external tools let instance = wgpu::Instance::default(); @@ -157,7 +112,7 @@ impl Info { seen_devices.insert(device_key); } seen_names.insert(gpu_name.clone()); - info.graphics.push(gpu_name); + graphics.push(gpu_name); } // NVIDIA Optimus quirk: On laptops with NVIDIA Optimus (switchable graphics), @@ -170,10 +125,68 @@ impl Info { let device_key = (vendor, device); if !seen_devices.contains(&device_key) { seen_devices.insert(device_key); - info.graphics.push(name); + graphics.push(name); } } + graphics + } + + pub fn load() -> Info { + let mut info = Info { + os_architecture: architecture(), + kernel_version: kernel_version(), + hardware_model: hardware_model(), + operating_system: operating_system(), + processor: processor_name(), + ..Default::default() + }; + + let mut sys = sysinfo::System::new(); + let disks = sysinfo::Disks::new_with_refreshed_list(); + sys.refresh_memory(); + + let mut total_capacity = 0; + let mut disk_set = HashSet::new(); + for disk in disks.list() { + if disk_set.contains(disk.name()) { + continue; + } + disk_set.insert(disk.name()); + total_capacity += disk.total_space(); + } + + info.disk_capacity = format_size(total_capacity); + + if let Some(name) = sysinfo::System::host_name() { + info.device_name = name; + } + + info.memory = format_size(sys.total_memory()); + + if let Ok(mut session) = std::env::var("XDG_SESSION_TYPE") { + if let Some(first) = session.get_mut(0..1) { + first.make_ascii_uppercase(); + } + info.windowing_system = session; + } + + // prefer XDG_SESSION_DESKTOP because the value is singular + if let Ok(mut session) = std::env::var("XDG_SESSION_DESKTOP") + .or_else(|_| std::env::var("XDG_CURRENT_DESKTOP")) + .or_else(|_| std::env::var("DESKTOP_SESSION")) + { + if let Some(first) = session.get_mut(0..1) { + first.make_ascii_uppercase(); + } + info.desktop_environment = session; + } + + #[cfg(feature = "wgpu")] + { + info.graphics = Self::wgpu_graphics(); + } + info } }