Merge pull request #347 from mahkoh/jorth/idle-notification-v2
idle_notifier: implement v2
This commit is contained in:
commit
de0327e7e4
8 changed files with 91 additions and 29 deletions
|
|
@ -1,5 +1,9 @@
|
||||||
# Unreleased
|
# Unreleased
|
||||||
|
|
||||||
|
- Needs jay-config release.
|
||||||
|
- Needs jay-toml-config release.
|
||||||
|
- Needs jay-compositor release.
|
||||||
|
|
||||||
# 1.7.0
|
# 1.7.0
|
||||||
|
|
||||||
- Needs jay-config release.
|
- Needs jay-config release.
|
||||||
|
|
|
||||||
|
|
@ -143,7 +143,7 @@ Jay supports the following wayland protocols:
|
||||||
| ext_data_control_manager_v1 | 1 | Yes |
|
| ext_data_control_manager_v1 | 1 | Yes |
|
||||||
| ext_foreign_toplevel_image_capture_source_manager_v1 | 1 | |
|
| ext_foreign_toplevel_image_capture_source_manager_v1 | 1 | |
|
||||||
| ext_foreign_toplevel_list_v1 | 1 | Yes |
|
| ext_foreign_toplevel_list_v1 | 1 | Yes |
|
||||||
| ext_idle_notifier_v1 | 1 | Yes |
|
| ext_idle_notifier_v1 | 2 | Yes |
|
||||||
| ext_image_copy_capture_manager_v1 | 1[^composited] | Yes |
|
| ext_image_copy_capture_manager_v1 | 1[^composited] | Yes |
|
||||||
| ext_output_image_capture_source_manager_v1 | 1 | |
|
| ext_output_image_capture_source_manager_v1 | 1 | |
|
||||||
| ext_session_lock_manager_v1 | 1 | Yes |
|
| ext_session_lock_manager_v1 | 1 | Yes |
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@
|
||||||
- Add support fo ext-data-control-v1.
|
- Add support fo ext-data-control-v1.
|
||||||
- Implement wl-fixes.
|
- Implement wl-fixes.
|
||||||
- Implement ei_touchscreen v2.
|
- Implement ei_touchscreen v2.
|
||||||
|
- Implement idle-notification v2.
|
||||||
|
|
||||||
# 1.7.0 (2024-10-25)
|
# 1.7.0 (2024-10-25)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -203,6 +203,7 @@ fn start_compositor2(
|
||||||
timeout_changed: Default::default(),
|
timeout_changed: Default::default(),
|
||||||
inhibitors: Default::default(),
|
inhibitors: Default::default(),
|
||||||
inhibitors_changed: Default::default(),
|
inhibitors_changed: Default::default(),
|
||||||
|
inhibited_idle_notifications: Default::default(),
|
||||||
backend_idle: Cell::new(true),
|
backend_idle: Cell::new(true),
|
||||||
},
|
},
|
||||||
run_args,
|
run_args,
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,7 @@ pub struct ExtIdleNotificationV1 {
|
||||||
impl ExtIdleNotificationV1 {
|
impl ExtIdleNotificationV1 {
|
||||||
fn detach(&self) {
|
fn detach(&self) {
|
||||||
self.seat.remove_idle_notification(self);
|
self.seat.remove_idle_notification(self);
|
||||||
|
self.client.state.idle.remove_inhibited_notification(self);
|
||||||
self.task.take();
|
self.task.take();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ use {
|
||||||
leaks::Tracker,
|
leaks::Tracker,
|
||||||
object::{Object, Version},
|
object::{Object, Version},
|
||||||
utils::errorfmt::ErrorFmt,
|
utils::errorfmt::ErrorFmt,
|
||||||
wire::{ext_idle_notifier_v1::*, ExtIdleNotifierV1Id},
|
wire::{ext_idle_notifier_v1::*, ExtIdleNotificationV1Id, ExtIdleNotifierV1Id, WlSeatId},
|
||||||
},
|
},
|
||||||
std::{cell::Cell, rc::Rc},
|
std::{cell::Cell, rc::Rc},
|
||||||
thiserror::Error,
|
thiserror::Error,
|
||||||
|
|
@ -46,6 +46,36 @@ pub struct ExtIdleNotifierV1 {
|
||||||
pub version: Version,
|
pub version: Version,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl ExtIdleNotifierV1 {
|
||||||
|
fn create_notification(
|
||||||
|
&self,
|
||||||
|
id: ExtIdleNotificationV1Id,
|
||||||
|
timeout: u32,
|
||||||
|
seat: WlSeatId,
|
||||||
|
skip_if_inhibited: bool,
|
||||||
|
) -> Result<(), ExtIdleNotifierV1Error> {
|
||||||
|
let seat = self.client.lookup(seat)?;
|
||||||
|
let notification = Rc::new(ExtIdleNotificationV1 {
|
||||||
|
id,
|
||||||
|
client: self.client.clone(),
|
||||||
|
tracker: Default::default(),
|
||||||
|
resume: Default::default(),
|
||||||
|
task: Cell::new(None),
|
||||||
|
seat: seat.global.clone(),
|
||||||
|
duration_usec: (timeout as u64).max(1000).saturating_mul(1000),
|
||||||
|
version: self.version,
|
||||||
|
});
|
||||||
|
track!(self.client, notification);
|
||||||
|
self.client.add_client_obj(¬ification)?;
|
||||||
|
let future = self.client.state.eng.spawn(
|
||||||
|
"idle notifier",
|
||||||
|
run(notification.clone(), skip_if_inhibited),
|
||||||
|
);
|
||||||
|
notification.task.set(Some(future));
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl ExtIdleNotifierV1RequestHandler for ExtIdleNotifierV1 {
|
impl ExtIdleNotifierV1RequestHandler for ExtIdleNotifierV1 {
|
||||||
type Error = ExtIdleNotifierV1Error;
|
type Error = ExtIdleNotifierV1Error;
|
||||||
|
|
||||||
|
|
@ -59,30 +89,19 @@ impl ExtIdleNotifierV1RequestHandler for ExtIdleNotifierV1 {
|
||||||
req: GetIdleNotification,
|
req: GetIdleNotification,
|
||||||
_slf: &Rc<Self>,
|
_slf: &Rc<Self>,
|
||||||
) -> Result<(), Self::Error> {
|
) -> Result<(), Self::Error> {
|
||||||
let seat = self.client.lookup(req.seat)?;
|
self.create_notification(req.id, req.timeout, req.seat, true)
|
||||||
let notification = Rc::new(ExtIdleNotificationV1 {
|
}
|
||||||
id: req.id,
|
|
||||||
client: self.client.clone(),
|
fn get_input_idle_notification(
|
||||||
tracker: Default::default(),
|
&self,
|
||||||
resume: Default::default(),
|
req: GetInputIdleNotification,
|
||||||
task: Cell::new(None),
|
_slf: &Rc<Self>,
|
||||||
seat: seat.global.clone(),
|
) -> Result<(), Self::Error> {
|
||||||
duration_usec: (req.timeout as u64).max(1000).saturating_mul(1000),
|
self.create_notification(req.id, req.timeout, req.seat, false)
|
||||||
version: self.version,
|
|
||||||
});
|
|
||||||
track!(self.client, notification);
|
|
||||||
self.client.add_client_obj(¬ification)?;
|
|
||||||
let future = self
|
|
||||||
.client
|
|
||||||
.state
|
|
||||||
.eng
|
|
||||||
.spawn("idle notifier", run(notification.clone()));
|
|
||||||
notification.task.set(Some(future));
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn run(n: Rc<ExtIdleNotificationV1>) {
|
async fn run(n: Rc<ExtIdleNotificationV1>, skip_if_inhibited: bool) {
|
||||||
loop {
|
loop {
|
||||||
let now = n.client.state.now_usec();
|
let now = n.client.state.now_usec();
|
||||||
let elapsed = now.saturating_sub(n.seat.last_input());
|
let elapsed = now.saturating_sub(n.seat.last_input());
|
||||||
|
|
@ -98,10 +117,18 @@ async fn run(n: Rc<ExtIdleNotificationV1>) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
n.send_idled();
|
let idle = &n.client.state.idle;
|
||||||
n.seat.add_idle_notification(&n);
|
let send_idle = !skip_if_inhibited || idle.inhibitors.is_empty();
|
||||||
|
if send_idle {
|
||||||
|
n.send_idled();
|
||||||
|
n.seat.add_idle_notification(&n);
|
||||||
|
} else {
|
||||||
|
idle.add_inhibited_notification(&n);
|
||||||
|
}
|
||||||
n.resume.triggered().await;
|
n.resume.triggered().await;
|
||||||
n.send_resumed();
|
if send_idle {
|
||||||
|
n.send_resumed();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -118,7 +145,7 @@ impl Global for ExtIdleNotifierV1Global {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn version(&self) -> u32 {
|
fn version(&self) -> u32 {
|
||||||
1
|
2
|
||||||
}
|
}
|
||||||
|
|
||||||
fn required_caps(&self) -> ClientCaps {
|
fn required_caps(&self) -> ClientCaps {
|
||||||
|
|
|
||||||
26
src/state.rs
26
src/state.rs
|
|
@ -34,6 +34,7 @@ use {
|
||||||
globals::{Globals, GlobalsError, RemovableWaylandGlobal, WaylandGlobal},
|
globals::{Globals, GlobalsError, RemovableWaylandGlobal, WaylandGlobal},
|
||||||
ifs::{
|
ifs::{
|
||||||
ext_foreign_toplevel_list_v1::ExtForeignToplevelListV1,
|
ext_foreign_toplevel_list_v1::ExtForeignToplevelListV1,
|
||||||
|
ext_idle_notification_v1::ExtIdleNotificationV1,
|
||||||
ext_session_lock_v1::ExtSessionLockV1,
|
ext_session_lock_v1::ExtSessionLockV1,
|
||||||
ipc::{
|
ipc::{
|
||||||
data_control::DataControlDeviceIds, x_data_device::XIpcDeviceIds, DataOfferIds,
|
data_control::DataControlDeviceIds, x_data_device::XIpcDeviceIds, DataOfferIds,
|
||||||
|
|
@ -94,8 +95,8 @@ use {
|
||||||
},
|
},
|
||||||
wheel::Wheel,
|
wheel::Wheel,
|
||||||
wire::{
|
wire::{
|
||||||
ExtForeignToplevelListV1Id, JayRenderCtxId, JaySeatEventsId, JayWorkspaceWatcherId,
|
ExtForeignToplevelListV1Id, ExtIdleNotificationV1Id, JayRenderCtxId, JaySeatEventsId,
|
||||||
ZwpLinuxDmabufFeedbackV1Id,
|
JayWorkspaceWatcherId, ZwpLinuxDmabufFeedbackV1Id,
|
||||||
},
|
},
|
||||||
xkbcommon::{KeyboardStateIds, XkbContext, XkbKeymap, XkbState},
|
xkbcommon::{KeyboardStateIds, XkbContext, XkbKeymap, XkbState},
|
||||||
xwayland::{self, XWaylandEvent},
|
xwayland::{self, XWaylandEvent},
|
||||||
|
|
@ -264,6 +265,8 @@ pub struct IdleState {
|
||||||
pub inhibitors: CopyHashMap<IdleInhibitorId, Rc<ZwpIdleInhibitorV1>>,
|
pub inhibitors: CopyHashMap<IdleInhibitorId, Rc<ZwpIdleInhibitorV1>>,
|
||||||
pub inhibitors_changed: Cell<bool>,
|
pub inhibitors_changed: Cell<bool>,
|
||||||
pub backend_idle: Cell<bool>,
|
pub backend_idle: Cell<bool>,
|
||||||
|
pub inhibited_idle_notifications:
|
||||||
|
CopyHashMap<(ClientId, ExtIdleNotificationV1Id), Rc<ExtIdleNotificationV1>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl IdleState {
|
impl IdleState {
|
||||||
|
|
@ -283,6 +286,25 @@ impl IdleState {
|
||||||
self.inhibitors.remove(&inhibitor.inhibit_id);
|
self.inhibitors.remove(&inhibitor.inhibit_id);
|
||||||
self.inhibitors_changed.set(true);
|
self.inhibitors_changed.set(true);
|
||||||
self.change.trigger();
|
self.change.trigger();
|
||||||
|
if self.inhibitors.is_empty() {
|
||||||
|
self.resume_inhibited_notifications();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn resume_inhibited_notifications(&self) {
|
||||||
|
for notification in self.inhibited_idle_notifications.lock().drain_values() {
|
||||||
|
notification.resume.trigger();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn add_inhibited_notification(&self, n: &Rc<ExtIdleNotificationV1>) {
|
||||||
|
self.inhibited_idle_notifications
|
||||||
|
.set((n.client.id, n.id), n.clone());
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn remove_inhibited_notification(&self, n: &ExtIdleNotificationV1) {
|
||||||
|
self.inhibited_idle_notifications
|
||||||
|
.remove(&(n.client.id, n.id));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,3 +8,9 @@ request get_idle_notification {
|
||||||
timeout: u32,
|
timeout: u32,
|
||||||
seat: id(wl_seat),
|
seat: id(wl_seat),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
request get_input_idle_notification {
|
||||||
|
id: id(ext_idle_notification_v1),
|
||||||
|
timeout: u32,
|
||||||
|
seat: id(wl_seat),
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue