31 lines
882 B
Rust
31 lines
882 B
Rust
use {
|
|
crate::{
|
|
cli::{DpmsArgs, DpmsState, GlobalArgs},
|
|
ipc,
|
|
tools::tool_client::{ToolClient, with_tool_client},
|
|
utils::errorfmt::ErrorFmt,
|
|
wire::jay_compositor::SetDpms,
|
|
},
|
|
std::rc::Rc,
|
|
};
|
|
|
|
pub fn main(global: GlobalArgs, args: DpmsArgs) {
|
|
let active = args.state == DpmsState::On;
|
|
match ipc::request_unit(&ipc::Request::DpmsSet { active }) {
|
|
Ok(()) => return,
|
|
Err(e) if e.can_fallback() => {}
|
|
Err(e) => fatal!("Could not set DPMS state over IPC: {}", ErrorFmt(e)),
|
|
}
|
|
with_tool_client(global.log_level, |tc| async move {
|
|
run(tc, args).await;
|
|
});
|
|
}
|
|
|
|
async fn run(tc: Rc<ToolClient>, args: DpmsArgs) {
|
|
let comp = tc.jay_compositor().await;
|
|
tc.send(SetDpms {
|
|
self_id: comp,
|
|
active: (args.state == DpmsState::On) as u32,
|
|
});
|
|
tc.round_trip().await;
|
|
}
|