diff --git a/src/main.rs b/src/main.rs index 958e624..72523c3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -70,22 +70,29 @@ fn main() { }); }); } else { - println!("unknown state, do nothing") + println!("unknown state, do nothing"); } } - // TODO if there are no enables do nothing. - outputs.iter() - .for_each(|output| { - if let SwayOutput::Disabled{name} = output { - println!("swaymsg output {} disabled", name); - } - }); - outputs.iter() - .for_each(|output| { - if let SwayOutput::Enabled{name,width,height,x,y} = output { - println!("swaymsg output {} enable dpms on mode {}x{} pos {} {}", - name, width, height, x, y); - } - }); + let enabled_count = outputs.iter() + .filter(|output| matches!(output,SwayOutput::Enabled{name:_,width:_,height:_,x:_,y:_})) + .count(); + if enabled_count >= 1 { + // enable then disable + outputs.iter() + .for_each(|output| { + if let SwayOutput::Enabled{name,width,height,x,y} = output { + println!("swaymsg output {} enable dpms on mode {}x{} pos {} {}", + name, width, height, x, y); + } + }); + outputs.iter() + .for_each(|output| { + if let SwayOutput::Disabled{name} = output { + println!("swaymsg output {} disabled", name); + } + }); + } else { + println!("No enabled outputs, do nothing"); + } } \ No newline at end of file