1
0
Fork 0
forked from wry/wry

add config options for waking dpms on mouse and keyboard interaction

This commit is contained in:
kossLAN 2026-05-25 22:57:29 -04:00
parent 2167484861
commit eece44a59c
No known key found for this signature in database
12 changed files with 116 additions and 9 deletions

View file

@ -279,11 +279,14 @@ fn start_compositor2(
change: Default::default(),
timeout: Cell::new(Duration::from_secs(10 * 60)),
grace_period: Cell::new(Duration::from_secs(5)),
key_press_enables_dpms: Cell::new(false),
mouse_move_enables_dpms: Cell::new(false),
timeout_changed: Default::default(),
inhibitors: Default::default(),
inhibitors_changed: Default::default(),
inhibited_idle_notifications: Default::default(),
backend_idle: Cell::new(true),
dpms_off_by_command: Cell::new(false),
in_grace_period: Cell::new(false),
},
run_args,

View file

@ -1134,6 +1134,14 @@ impl ConfigProxyHandler {
self.state.idle.set_timeout(&self.state, timeout);
}
fn handle_set_key_press_enables_dpms(&self, enabled: bool) {
self.state.idle.key_press_enables_dpms.set(enabled);
}
fn handle_set_mouse_move_enables_dpms(&self, enabled: bool) {
self.state.idle.mouse_move_enables_dpms.set(enabled);
}
fn handle_set_idle_grace_period(&self, period: Duration) {
self.state.idle.set_grace_period(&self.state, period);
}
@ -3129,6 +3137,12 @@ impl ConfigProxyHandler {
.handle_get_input_device_devnode(device)
.wrn("get_input_device_devnode")?,
ClientMessage::SetIdle { timeout } => self.handle_set_idle(timeout),
ClientMessage::SetKeyPressEnablesDpms { enabled } => {
self.handle_set_key_press_enables_dpms(enabled)
}
ClientMessage::SetMouseMoveEnablesDpms { enabled } => {
self.handle_set_mouse_move_enables_dpms(enabled)
}
ClientMessage::MoveToOutput {
workspace,
connector,

View file

@ -547,7 +547,7 @@ impl JayCompositorRequestHandler for JayCompositor {
fn set_dpms(&self, req: SetDpms, _slf: &Rc<Self>) -> Result<(), Self::Error> {
self.client
.state
.set_connectors_active(req.active != 0)
.set_dpms_active(req.active != 0)
.map_err(JayCompositorError::SetDpms)?;
Ok(())
}

View file

@ -342,10 +342,13 @@ pub struct IdleState {
pub change: AsyncEvent,
pub timeout: Cell<Duration>,
pub grace_period: Cell<Duration>,
pub key_press_enables_dpms: Cell<bool>,
pub mouse_move_enables_dpms: Cell<bool>,
pub timeout_changed: Cell<bool>,
pub inhibitors: CopyHashMap<IdleInhibitorId, Rc<ZwpIdleInhibitorV1>>,
pub inhibitors_changed: Cell<bool>,
pub backend_idle: Cell<bool>,
pub dpms_off_by_command: Cell<bool>,
pub inhibited_idle_notifications:
CopyHashMap<(ClientId, ExtIdleNotificationV1Id), Rc<ExtIdleNotificationV1>>,
pub in_grace_period: Cell<bool>,
@ -975,7 +978,14 @@ impl State {
}
}
pub fn input_occurred(&self) {
pub fn input_occurred(self: &Rc<Self>, key_press: bool, mouse_move: bool) {
if self.idle.dpms_off_by_command.get() {
let enable_dpms = key_press && self.idle.key_press_enables_dpms.get()
|| mouse_move && self.idle.mouse_move_enables_dpms.get();
if enable_dpms && let Err(e) = self.set_dpms_active(true) {
log::error!("Could not enable DPMS after input: {}", ErrorFmt(e));
}
}
if !self.idle.input.replace(true) {
self.idle.change.trigger();
}
@ -1420,6 +1430,15 @@ impl State {
Ok(())
}
pub fn set_dpms_active(
self: &Rc<Self>,
active: bool,
) -> Result<(), BackendConnectorTransactionError> {
self.set_connectors_active(active)?;
self.idle.dpms_off_by_command.set(!active);
Ok(())
}
pub fn root_visible(&self) -> bool {
!self.idle.backend_idle.get()
}

View file

@ -1,6 +1,6 @@
use {
crate::{
backend::{InputDevice, InputDeviceCapability},
backend::{InputDevice, InputDeviceCapability, InputEvent, KeyState},
ifs::wl_seat::PX_PER_SCROLL,
state::{DeviceHandlerData, InputDeviceData, State},
tasks::udev_utils::{UdevProps, udev_props},
@ -80,13 +80,21 @@ impl DeviceHandler {
}
if let Some(seat) = self.data.seat.get() {
let mut any_events = false;
let mut key_press = false;
let mut mouse_move = false;
while let Some(event) = self.dev.event() {
let (is_key_press, is_mouse_move) = dpms_wake_triggers_for(&event);
key_press |= is_key_press;
mouse_move |= is_mouse_move;
if is_key_press || is_mouse_move {
self.state.input_occurred(is_key_press, is_mouse_move);
}
seat.event(&self.data, event);
any_events = true;
}
if any_events {
seat.mark_last_active();
self.state.input_occurred();
self.state.input_occurred(key_press, mouse_move);
}
} else {
while self.dev.event().is_some() {
@ -105,3 +113,16 @@ impl DeviceHandler {
self.data.set_seat(&self.state, None);
}
}
fn dpms_wake_triggers_for(event: &InputEvent) -> (bool, bool) {
match event {
InputEvent::Key {
state: KeyState::Pressed,
..
} => (true, false),
InputEvent::ConnectorPosition { .. }
| InputEvent::Motion { .. }
| InputEvent::MotionAbsolute { .. } => (false, true),
_ => (false, false),
}
}