diff --git a/src/main.rs b/src/main.rs index 1159206..7b5a523 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,6 +11,8 @@ enum SwayOutput { name: String, width: i32, height: i32, + x: i32, + y: i32, } } fn main() { @@ -24,34 +26,66 @@ fn main() { let mut outputs: Vec = Vec::new(); let json = json::parse(s).unwrap(); + + // TODO I think there is a better alternative syntax to match here. let json_outputs = match json { JsonValue::Array(vec) => vec, _ => panic!("json was not an array") }; + let size = json_outputs.len(); - println!("output count: {}", size); if size == 1 { - println!("one output, use it"); + // If there is 1 output, use it. let json_output = &json_outputs[0]; - //println!("output:{:#}", output); let name = &json_output["name"]; let mode = &json_output["modes"][0]; - //println!("mode:{:#}",mode); - println!("swaymsg output {} mode {}x{}", name, mode["width"], mode["height"]); outputs.push(SwayOutput::Enabled { name: name.to_string(), - width: 1, - height: 1 + width: mode["width"].as_i32().unwrap(), + height: mode["height"].as_i32().unwrap(), + x: 0, + y: 0, }); + } else { + let dell_option:Option<&JsonValue> = json_outputs.iter() + .find( |json_output| json_output["serial"].to_string() == "CFV9N99T0Y0U"); + if dell_option.is_some() { + // The Dell on my desk is attached. Use it, and disable others. + let dell = dell_option.unwrap(); + outputs.push(SwayOutput::Enabled { + name: dell["name"].to_string(), + width: 1920, + height: 1200, + x: 0, + y: 0 + }); + json_outputs.iter() + .filter( |json_output| { + json_output["serial"].to_string() != "CFV9N99T0Y0U" + }) + .for_each( |json_output| { + outputs.push(SwayOutput::Disabled { + name: json_output["name"].to_string() + }); + }); + } else { + println!("unknown state, do nothing") + } } + // TODO do all enables then all disables. + // TODO if there are only disables then do nothing. for output in &outputs { match output { SwayOutput::Disabled { name } => { println!("swaymsg output {} disabled", name); + // TODO run }, - SwayOutput::Enabled { name, width, height } => { - println!("swaymsg output {} mode {}x{}", name, width, height); + SwayOutput::Enabled { name, width, height, x, y } => { + println!( + "swaymsg output {} enable dpms on mode {}x{} pos {} {}", + name, width, height, x, y); + // TODO run } } }