Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
LuckyTurtleDev committed Oct 24, 2023
1 parent 8411a0a commit c69e852
Showing 1 changed file with 55 additions and 2 deletions.
57 changes: 55 additions & 2 deletions more-wallpapers/src/linux/sway.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,45 @@ use crate::{
};
use serde::Deserialize;
use std::{io::StdoutLock, process::Command};
use strum_macros::{Display, EnumString};

#[derive(Debug, Clone, Copy, EnumString, Display, PartialEq, Eq)]
#[strum(serialize_all = "lowercase")]
enum SMode {
Stretch,
Fill,
Fit,
Center,
Tile,
}

impl From<Mode> for SMode {
fn from(value: Mode) -> Self {
match value {
Mode::Center => Self::Center,
Mode::Crop => Self::Fill,
Mode::Fit => Self::Fit,
Mode::Stretch => Self::Stretch,
Mode::Tile => Self::Tile,
}
}
}

impl From<SMode> for Mode {
fn from(value: SMode) -> Self {
match value {
SMode::Center => Self::Center,
SMode::Fill => Self::Crop,
SMode::Fit => Self::Fit,
SMode::Stretch => Self::Stretch,
SMode::Tile => Self::Tile,
}
}
}

#[derive(Deserialize, Debug)]
struct OutputScreens {
id: usize,
name: String,
current_mode: OutputMode,
active: bool,
}
Expand All @@ -28,9 +63,27 @@ pub(crate) fn get_screens() -> Result<Vec<Screen>, WallpaperError> {
println!("{output}");
let output: Vec<OutputScreens> = serde_json::from_str(&output)?;
println!("{output:#?}");
todo!() //Ok(screens)
Ok(output
.into_iter()
.map(|screen| Screen {
name: screen.name,
wallpaper: None,
mode: None,
active: screen.active,
})
.collect())
}

pub(crate) fn set_screens(screens: Vec<Screen>) -> Result<(), WallpaperError> {
for screen in screens {
let mut command = Command::new("swaymsg");
command
.arg("output")
.arg(screen.name)
.arg("bg")
.arg(screen.wallpaper.unwrap())
.arg(format!("{}", SMode::from(screen.mode.unwrap())));
check_command_error(command.output(), "swaymsg")?;
}
Ok(())
}

0 comments on commit c69e852

Please sign in to comment.