code format

This commit is contained in:
2024-12-31 02:51:58 +00:00
parent c5f35ebf06
commit 20ec42d126
4 changed files with 98 additions and 66 deletions

View File

@@ -1,8 +1,8 @@
use crate::config::OutputConfig;
use serde_json::{from_str, Value};
use std::collections::HashMap;
use std::process::Command;
use std::str::from_utf8;
use serde_json::{from_str, Value};
use crate::config::OutputConfig;
/// An output, as returned by `swaymsg -t get_outputs`.
pub struct Output {
@@ -68,12 +68,11 @@ fn get_mode(output: &Value) -> String {
/// Apply the specified outputs. Enable all outputs in [outputs], disable others.
pub fn apply_outputs(all_outputs: &Vec<Output>, outputs: &HashMap<&String, &OutputConfig>) {
// set enabled outputs first, then set disabled outputs.
// That way if some work before an error, you have at least one output enabled.
// for outputs to be enabled: map of output name to config
let mut enabled: HashMap<&String,&OutputConfig> = HashMap::new();
let mut enabled: HashMap<&String, &OutputConfig> = HashMap::new();
// for outputs to be disabled: output names
let mut disabled: Vec<&String> = Vec::new();
@@ -86,7 +85,7 @@ pub fn apply_outputs(all_outputs: &Vec<Output>, outputs: &HashMap<&String, &Outp
});
let mut cmd = Command::new("swaymsg");
enabled.iter().for_each(|(output_name,output_config)| {
enabled.iter().for_each(|(output_name, output_config)| {
cmd.arg("output");
cmd.arg(&output_name);
cmd.arg("enable");