add dpms on/off command
This commit is contained in:
parent
a29937ebe8
commit
2167484861
7 changed files with 76 additions and 13 deletions
17
src/cli.rs
17
src/cli.rs
|
|
@ -3,6 +3,7 @@ mod color;
|
||||||
mod color_management;
|
mod color_management;
|
||||||
mod config;
|
mod config;
|
||||||
mod damage_tracking;
|
mod damage_tracking;
|
||||||
|
mod dpms;
|
||||||
mod duration;
|
mod duration;
|
||||||
mod generate;
|
mod generate;
|
||||||
mod idle;
|
mod idle;
|
||||||
|
|
@ -85,6 +86,8 @@ pub enum Cmd {
|
||||||
Screenshot(ScreenshotArgs),
|
Screenshot(ScreenshotArgs),
|
||||||
/// Inspect/modify the idle (screensaver) settings.
|
/// Inspect/modify the idle (screensaver) settings.
|
||||||
Idle(IdleArgs),
|
Idle(IdleArgs),
|
||||||
|
/// Turn monitors on or off.
|
||||||
|
Dpms(DpmsArgs),
|
||||||
/// Run a privileged program.
|
/// Run a privileged program.
|
||||||
RunPrivileged(RunPrivilegedArgs),
|
RunPrivileged(RunPrivilegedArgs),
|
||||||
/// Run a program with a connection tag.
|
/// Run a program with a connection tag.
|
||||||
|
|
@ -131,6 +134,19 @@ pub struct IdleArgs {
|
||||||
pub command: Option<IdleCmd>,
|
pub command: Option<IdleCmd>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Args, Debug)]
|
||||||
|
pub struct DpmsArgs {
|
||||||
|
/// Whether monitors should be on or off.
|
||||||
|
#[clap(value_enum)]
|
||||||
|
pub state: DpmsState,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(ValueEnum, Debug, Copy, Clone, Eq, PartialEq)]
|
||||||
|
pub enum DpmsState {
|
||||||
|
On,
|
||||||
|
Off,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Args, Debug)]
|
#[derive(Args, Debug)]
|
||||||
pub struct RunPrivilegedArgs {
|
pub struct RunPrivilegedArgs {
|
||||||
/// The program to run
|
/// The program to run
|
||||||
|
|
@ -250,6 +266,7 @@ pub fn main() {
|
||||||
Cmd::SetLogLevel(a) => set_log_level::main(cli.global, a),
|
Cmd::SetLogLevel(a) => set_log_level::main(cli.global, a),
|
||||||
Cmd::Screenshot(a) => screenshot::main(cli.global, a),
|
Cmd::Screenshot(a) => screenshot::main(cli.global, a),
|
||||||
Cmd::Idle(a) => idle::main(cli.global, a),
|
Cmd::Idle(a) => idle::main(cli.global, a),
|
||||||
|
Cmd::Dpms(a) => dpms::main(cli.global, a),
|
||||||
Cmd::Unlock => unlock::main(cli.global),
|
Cmd::Unlock => unlock::main(cli.global),
|
||||||
Cmd::RunPrivileged(a) => run_privileged::main(cli.global, a),
|
Cmd::RunPrivileged(a) => run_privileged::main(cli.global, a),
|
||||||
Cmd::RunTagged(a) => run_tagged::main(cli.global, a),
|
Cmd::RunTagged(a) => run_tagged::main(cli.global, a),
|
||||||
|
|
|
||||||
23
src/cli/dpms.rs
Normal file
23
src/cli/dpms.rs
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
use {
|
||||||
|
crate::{
|
||||||
|
cli::{DpmsArgs, DpmsState, GlobalArgs},
|
||||||
|
tools::tool_client::{ToolClient, with_tool_client},
|
||||||
|
wire::jay_compositor::SetDpms,
|
||||||
|
},
|
||||||
|
std::rc::Rc,
|
||||||
|
};
|
||||||
|
|
||||||
|
pub fn main(global: GlobalArgs, args: DpmsArgs) {
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
use {
|
use {
|
||||||
crate::{
|
crate::{
|
||||||
|
backend::transaction::BackendConnectorTransactionError,
|
||||||
client::{CAP_JAY_COMPOSITOR, Client, ClientCaps, ClientError, ClientId},
|
client::{CAP_JAY_COMPOSITOR, Client, ClientCaps, ClientError, ClientId},
|
||||||
compositor::LogLevel,
|
compositor::LogLevel,
|
||||||
globals::{Global, GlobalName},
|
globals::{Global, GlobalName},
|
||||||
|
|
@ -78,7 +79,7 @@ global_base!(JayCompositorGlobal, JayCompositor, JayCompositorError);
|
||||||
|
|
||||||
impl Global for JayCompositorGlobal {
|
impl Global for JayCompositorGlobal {
|
||||||
fn version(&self) -> u32 {
|
fn version(&self) -> u32 {
|
||||||
30
|
31
|
||||||
}
|
}
|
||||||
|
|
||||||
fn required_caps(&self) -> ClientCaps {
|
fn required_caps(&self) -> ClientCaps {
|
||||||
|
|
@ -542,6 +543,14 @@ impl JayCompositorRequestHandler for JayCompositor {
|
||||||
});
|
});
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn set_dpms(&self, req: SetDpms, _slf: &Rc<Self>) -> Result<(), Self::Error> {
|
||||||
|
self.client
|
||||||
|
.state
|
||||||
|
.set_connectors_active(req.active != 0)
|
||||||
|
.map_err(JayCompositorError::SetDpms)?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
object_base! {
|
object_base! {
|
||||||
|
|
@ -559,5 +568,7 @@ pub enum JayCompositorError {
|
||||||
ClientError(Box<ClientError>),
|
ClientError(Box<ClientError>),
|
||||||
#[error("Unknown log level {0}")]
|
#[error("Unknown log level {0}")]
|
||||||
UnknownLogLevel(u32),
|
UnknownLogLevel(u32),
|
||||||
|
#[error("Could not set DPMS state")]
|
||||||
|
SetDpms(#[source] BackendConnectorTransactionError),
|
||||||
}
|
}
|
||||||
efrom!(JayCompositorError, ClientError);
|
efrom!(JayCompositorError, ClientError);
|
||||||
|
|
|
||||||
18
src/state.rs
18
src/state.rs
|
|
@ -7,7 +7,8 @@ use {
|
||||||
Backend, BackendConnectorState, BackendConnectorStateSerials, BackendDrmDevice,
|
Backend, BackendConnectorState, BackendConnectorStateSerials, BackendDrmDevice,
|
||||||
BackendEvent, Connector, ConnectorId, ConnectorIds, DrmDeviceId, DrmDeviceIds,
|
BackendEvent, Connector, ConnectorId, ConnectorIds, DrmDeviceId, DrmDeviceIds,
|
||||||
HardwareCursorUpdate, InputDevice, InputDeviceGroupIds, InputDeviceId, InputDeviceIds,
|
HardwareCursorUpdate, InputDevice, InputDeviceGroupIds, InputDeviceId, InputDeviceIds,
|
||||||
MonitorInfo, transaction::BackendConnectorTransactionError,
|
MonitorInfo,
|
||||||
|
transaction::{BackendConnectorTransactionError, ConnectorTransaction},
|
||||||
},
|
},
|
||||||
backends::dummy::DummyBackend,
|
backends::dummy::DummyBackend,
|
||||||
cli::RunArgs,
|
cli::RunArgs,
|
||||||
|
|
@ -1404,6 +1405,21 @@ impl State {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn set_connectors_active(
|
||||||
|
self: &Rc<Self>,
|
||||||
|
active: bool,
|
||||||
|
) -> Result<(), BackendConnectorTransactionError> {
|
||||||
|
let mut tran = ConnectorTransaction::new(self);
|
||||||
|
for connector in self.connectors.lock().values() {
|
||||||
|
let mut state = connector.state.borrow().clone();
|
||||||
|
state.active = active;
|
||||||
|
tran.add(&connector.connector, state)?;
|
||||||
|
}
|
||||||
|
tran.prepare()?.apply()?.commit();
|
||||||
|
self.set_backend_idle(!active);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
pub fn root_visible(&self) -> bool {
|
pub fn root_visible(&self) -> bool {
|
||||||
!self.idle.backend_idle.get()
|
!self.idle.backend_idle.get()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
use {
|
use {
|
||||||
crate::{
|
crate::{
|
||||||
backend::transaction::{BackendConnectorTransactionError, ConnectorTransaction},
|
backend::transaction::BackendConnectorTransactionError,
|
||||||
state::State,
|
state::State,
|
||||||
utils::{
|
utils::{
|
||||||
errorfmt::ErrorFmt,
|
errorfmt::ErrorFmt,
|
||||||
|
|
@ -136,15 +136,7 @@ impl Idle {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn try_set_idle(&self, idle: bool) -> Result<(), BackendConnectorTransactionError> {
|
fn try_set_idle(&self, idle: bool) -> Result<(), BackendConnectorTransactionError> {
|
||||||
let mut tran = ConnectorTransaction::new(&self.state);
|
self.state.set_connectors_active(!idle)
|
||||||
for connector in self.state.connectors.lock().values() {
|
|
||||||
let mut state = connector.state.borrow().clone();
|
|
||||||
state.active = !idle;
|
|
||||||
tran.add(&connector.connector, state)?;
|
|
||||||
}
|
|
||||||
tran.prepare()?.apply()?.commit();
|
|
||||||
self.state.set_backend_idle(idle);
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -330,7 +330,7 @@ impl ToolClient {
|
||||||
self_id: s.registry,
|
self_id: s.registry,
|
||||||
name: s.jay_compositor.0,
|
name: s.jay_compositor.0,
|
||||||
interface: JayCompositor.name(),
|
interface: JayCompositor.name(),
|
||||||
version: s.jay_compositor.1.min(30),
|
version: s.jay_compositor.1.min(31),
|
||||||
id: id.into(),
|
id: id.into(),
|
||||||
});
|
});
|
||||||
self.jay_compositor.set(Some(id));
|
self.jay_compositor.set(Some(id));
|
||||||
|
|
|
||||||
|
|
@ -135,6 +135,10 @@ request get_pid (since = 27) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
request set_dpms (since = 31) {
|
||||||
|
active: u32,
|
||||||
|
}
|
||||||
|
|
||||||
# events
|
# events
|
||||||
|
|
||||||
event client_id {
|
event client_id {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue