use std::process::Command;
pub mod hypr_monitors;
pub struct Monitor {
pub name: String,
pub make: String,
pub model: String,
pub serial: String,
pub resolution: String,
pub refreshrate: String,
pub offset: String,
pub scale: String,
pub transform: String,
pub vrr: bool,
}
impl Monitor {
pub fn set_resolution(&mut self, new_resolution: String) {
self.resolution = new_resolution;
}
pub fn set_refreshrate(&mut self, new_refreshrate: String) {
self.refreshrate = new_refreshrate;
}
pub fn set_offset(&mut self, new_offset: String) {
self.offset = new_offset;
}
pub fn set_scale(&mut self, new_scale: String) {
self.scale = new_scale;
}
pub fn set_transform(&mut self, new_transform: String) {
self.transform = new_transform;
}
pub fn set_vrr(&mut self, new_vrr: bool) {
self.vrr = new_vrr;
}
}
impl Monitor {
pub fn enable_hypr_monitor(&self) {
let monitor_string = format!(
"{},{}@{},{},{},transform,{}",
self.name, self.resolution, self.refreshrate, self.offset, self.scale, self.transform
);
Command::new("hyprctl")
.args(["keyword", "monitor", &monitor_string])
.spawn()
.expect("Could not enable specified monitor");
}
}
#[test]
fn monitor_import() {
use std::{fs::File, io::Write};
let output = Command::new("hyprctl").args(["-j", "monitors"]).output();
if output.is_err() {
println!("hyprctl not found, skipping test");
return;
}
let output = output.unwrap().stdout;
let mut file = File::create("example.json").expect("Could not open json file");
assert!(file.write_all(&output).is_ok());
}