handle only dell
This commit is contained in:
52
src/main.rs
52
src/main.rs
@@ -11,6 +11,8 @@ enum SwayOutput {
|
|||||||
name: String,
|
name: String,
|
||||||
width: i32,
|
width: i32,
|
||||||
height: i32,
|
height: i32,
|
||||||
|
x: i32,
|
||||||
|
y: i32,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn main() {
|
fn main() {
|
||||||
@@ -24,34 +26,66 @@ fn main() {
|
|||||||
let mut outputs: Vec<SwayOutput> = Vec::new();
|
let mut outputs: Vec<SwayOutput> = Vec::new();
|
||||||
|
|
||||||
let json = json::parse(s).unwrap();
|
let json = json::parse(s).unwrap();
|
||||||
|
|
||||||
|
// TODO I think there is a better alternative syntax to match here.
|
||||||
let json_outputs = match json {
|
let json_outputs = match json {
|
||||||
JsonValue::Array(vec) => vec,
|
JsonValue::Array(vec) => vec,
|
||||||
_ => panic!("json was not an array")
|
_ => panic!("json was not an array")
|
||||||
};
|
};
|
||||||
|
|
||||||
let size = json_outputs.len();
|
let size = json_outputs.len();
|
||||||
println!("output count: {}", size);
|
|
||||||
if size == 1 {
|
if size == 1 {
|
||||||
println!("one output, use it");
|
// If there is 1 output, use it.
|
||||||
let json_output = &json_outputs[0];
|
let json_output = &json_outputs[0];
|
||||||
//println!("output:{:#}", output);
|
|
||||||
let name = &json_output["name"];
|
let name = &json_output["name"];
|
||||||
let mode = &json_output["modes"][0];
|
let mode = &json_output["modes"][0];
|
||||||
//println!("mode:{:#}",mode);
|
|
||||||
println!("swaymsg output {} mode {}x{}", name, mode["width"], mode["height"]);
|
|
||||||
outputs.push(SwayOutput::Enabled {
|
outputs.push(SwayOutput::Enabled {
|
||||||
name: name.to_string(),
|
name: name.to_string(),
|
||||||
width: 1,
|
width: mode["width"].as_i32().unwrap(),
|
||||||
height: 1
|
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 {
|
for output in &outputs {
|
||||||
match output {
|
match output {
|
||||||
SwayOutput::Disabled { name } => {
|
SwayOutput::Disabled { name } => {
|
||||||
println!("swaymsg output {} disabled", name);
|
println!("swaymsg output {} disabled", name);
|
||||||
|
// TODO run
|
||||||
},
|
},
|
||||||
SwayOutput::Enabled { name, width, height } => {
|
SwayOutput::Enabled { name, width, height, x, y } => {
|
||||||
println!("swaymsg output {} mode {}x{}", name, width, height);
|
println!(
|
||||||
|
"swaymsg output {} enable dpms on mode {}x{} pos {} {}",
|
||||||
|
name, width, height, x, y);
|
||||||
|
// TODO run
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user