state: deduplicate inhibitor code
This commit is contained in:
parent
603ed6852f
commit
48852f45ff
2 changed files with 11 additions and 6 deletions
|
|
@ -43,11 +43,13 @@ impl ZwpIdleInhibitorV1 {
|
|||
}
|
||||
|
||||
pub fn activate(self: &Rc<Self>) {
|
||||
self.client.state.idle.add_inhibitor(self);
|
||||
let state = &self.client.state;
|
||||
state.idle.add_inhibitor(self);
|
||||
}
|
||||
|
||||
pub fn deactivate(&self) {
|
||||
self.client.state.idle.remove_inhibitor(self);
|
||||
let state = &self.client.state;
|
||||
state.idle.remove_inhibitor(self);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
11
src/state.rs
11
src/state.rs
|
|
@ -356,19 +356,22 @@ impl IdleState {
|
|||
|
||||
pub fn add_inhibitor(&self, inhibitor: &Rc<ZwpIdleInhibitorV1>) {
|
||||
self.inhibitors.set(inhibitor.inhibit_id, inhibitor.clone());
|
||||
self.inhibitors_changed.set(true);
|
||||
self.change.trigger();
|
||||
self.inhibitors_changed();
|
||||
}
|
||||
|
||||
pub fn remove_inhibitor(&self, inhibitor: &ZwpIdleInhibitorV1) {
|
||||
self.inhibitors.remove(&inhibitor.inhibit_id);
|
||||
self.inhibitors_changed.set(true);
|
||||
self.change.trigger();
|
||||
self.inhibitors_changed();
|
||||
if self.inhibitors.is_empty() {
|
||||
self.resume_inhibited_notifications();
|
||||
}
|
||||
}
|
||||
|
||||
fn inhibitors_changed(&self) {
|
||||
self.inhibitors_changed.set(true);
|
||||
self.change.trigger();
|
||||
}
|
||||
|
||||
fn resume_inhibited_notifications(&self) {
|
||||
for notification in self.inhibited_idle_notifications.lock().drain_values() {
|
||||
notification.resume.trigger();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue