Skip to main content

wallr_common/
types.rs

1//! Shared data types: wallpaper scaling, theme providers, GPU preference.
2//!
3//! These enums travel over IPC and live in config files, so they live in the
4//! common crate where both the client and the daemon engine can use them
5//! without pulling in GPU or Wayland dependencies.
6
7use serde::{Deserialize, Serialize};
8
9#[derive(Debug, Clone, Serialize, Deserialize, clap::ValueEnum, Default, PartialEq)]
10#[serde(rename_all = "snake_case")]
11pub enum ScalingMode {
12    #[default]
13    Fill,
14    Fit,
15    Stretch,
16    Center,
17    Tile,
18}
19
20#[derive(Debug, Clone, Serialize, Deserialize, clap::ValueEnum, Default, PartialEq)]
21#[serde(rename_all = "snake_case")]
22pub enum ThemeProvider {
23    Matugen,
24    Wallust,
25    Pywal,
26    #[default]
27    None,
28}
29
30#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Default)]
31#[serde(rename_all = "lowercase")]
32pub enum GpuSelection {
33    #[default]
34    Auto,
35    Integrated,
36    Discrete,
37    Named(String),
38}
39
40impl std::fmt::Display for GpuSelection {
41    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
42        match self {
43            Self::Auto => write!(f, "auto"),
44            Self::Integrated => write!(f, "integrated"),
45            Self::Discrete => write!(f, "discrete"),
46            Self::Named(name) => write!(f, "{}", name),
47        }
48    }
49}
50
51#[cfg(test)]
52mod tests {
53    use super::*;
54
55    #[test]
56    fn gpu_selection_display() {
57        assert_eq!(GpuSelection::Auto.to_string(), "auto");
58        assert_eq!(GpuSelection::Integrated.to_string(), "integrated");
59        assert_eq!(GpuSelection::Discrete.to_string(), "discrete");
60        assert_eq!(
61            GpuSelection::Named("NVIDIA".to_string()).to_string(),
62            "NVIDIA"
63        );
64    }
65
66    #[test]
67    fn gpu_selection_default() {
68        assert_eq!(GpuSelection::default(), GpuSelection::Auto);
69    }
70}