1
0
Fork 0
forked from wry/wry

autocommit 2022-04-17 18:51:15 CEST

This commit is contained in:
Julian Orth 2022-04-17 18:51:15 +02:00
parent affab05b94
commit c11d299fb8
2 changed files with 10 additions and 13 deletions

View file

@ -49,6 +49,8 @@ use {
thiserror::Error,
zwp_idle_inhibitor_v1::ZwpIdleInhibitorV1,
};
use crate::utils::copyhashmap::CopyHashMap;
use crate::wire::ZwpIdleInhibitorV1Id;
#[allow(dead_code)]
const INVALID_SCALE: u32 = 0;
@ -105,7 +107,7 @@ pub struct WlSurface {
cursors: SmallMap<SeatId, Rc<CursorSurface>, 1>,
pub dnd_icons: SmallMap<SeatId, Rc<WlSeatGlobal>, 1>,
pub tracker: Tracker<Self>,
idle_inhibitor: CloneCell<Option<Rc<ZwpIdleInhibitorV1>>>,
idle_inhibitors: CopyHashMap<ZwpIdleInhibitorV1Id, Rc<ZwpIdleInhibitorV1>>,
}
impl Debug for WlSurface {
@ -222,7 +224,7 @@ impl WlSurface {
cursors: Default::default(),
dnd_icons: Default::default(),
tracker: Default::default(),
idle_inhibitor: Default::default(),
idle_inhibitors: Default::default(),
}
}
@ -389,7 +391,7 @@ impl WlSurface {
self.frame_requests.borrow_mut().clear();
self.toplevel.set(None);
self.client.remove_obj(self)?;
self.idle_inhibitor.take();
self.idle_inhibitors.clear();
Ok(())
}
@ -627,7 +629,7 @@ impl Object for WlSurface {
mem::take(self.frame_requests.borrow_mut().deref_mut());
self.buffer.set(None);
self.toplevel.set(None);
self.idle_inhibitor.take();
self.idle_inhibitors.clear();
}
}
@ -644,7 +646,7 @@ impl SizedNode for WlSurface {
}
fn destroy_node(&self, _detach: bool) {
if let Some(inhibitor) = self.idle_inhibitor.get() {
for (_, inhibitor) in self.idle_inhibitors.lock().drain() {
inhibitor.deactivate();
}
let children = self.children.borrow();
@ -691,7 +693,7 @@ impl SizedNode for WlSurface {
fn set_visible(&self, visible: bool) {
self.visible.set(visible);
if let Some(inhibitor) = self.idle_inhibitor.get() {
for inhibitor in self.idle_inhibitors.lock().values() {
if visible {
inhibitor.activate();
} else {

View file

@ -25,17 +25,14 @@ impl ZwpIdleInhibitorV1 {
fn destroy(&self, parser: MsgParser<'_, '_>) -> Result<(), ZwpIdleInhibitorV1Error> {
let _req: Destroy = self.client.parse(self, parser)?;
self.client.remove_obj(self)?;
if self.surface.idle_inhibitor.take().is_some() {
if self.surface.idle_inhibitors.remove(&self.id).is_some() {
self.deactivate();
}
Ok(())
}
pub fn install(self: &Rc<Self>) -> Result<(), ZwpIdleInhibitorV1Error> {
if self.surface.idle_inhibitor.get().is_some() {
return Err(ZwpIdleInhibitorV1Error::MultipleInhibitors(self.surface.id));
}
self.surface.idle_inhibitor.set(Some(self.clone()));
self.surface.idle_inhibitors.set(self.id, self.clone());
if self.surface.visible.get() {
self.activate();
}
@ -75,8 +72,6 @@ pub enum ZwpIdleInhibitorV1Error {
MsgParserError(#[source] Box<MsgParserError>),
#[error(transparent)]
ClientError(Box<ClientError>),
#[error("The surface {0} already has an inhibitor attached")]
MultipleInhibitors(WlSurfaceId),
}
efrom!(ZwpIdleInhibitorV1Error, ClientError);
efrom!(ZwpIdleInhibitorV1Error, MsgParserError);