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>) {
|
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) {
|
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>) {
|
pub fn add_inhibitor(&self, inhibitor: &Rc<ZwpIdleInhibitorV1>) {
|
||||||
self.inhibitors.set(inhibitor.inhibit_id, inhibitor.clone());
|
self.inhibitors.set(inhibitor.inhibit_id, inhibitor.clone());
|
||||||
self.inhibitors_changed.set(true);
|
self.inhibitors_changed();
|
||||||
self.change.trigger();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn remove_inhibitor(&self, inhibitor: &ZwpIdleInhibitorV1) {
|
pub fn remove_inhibitor(&self, inhibitor: &ZwpIdleInhibitorV1) {
|
||||||
self.inhibitors.remove(&inhibitor.inhibit_id);
|
self.inhibitors.remove(&inhibitor.inhibit_id);
|
||||||
self.inhibitors_changed.set(true);
|
self.inhibitors_changed();
|
||||||
self.change.trigger();
|
|
||||||
if self.inhibitors.is_empty() {
|
if self.inhibitors.is_empty() {
|
||||||
self.resume_inhibited_notifications();
|
self.resume_inhibited_notifications();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn inhibitors_changed(&self) {
|
||||||
|
self.inhibitors_changed.set(true);
|
||||||
|
self.change.trigger();
|
||||||
|
}
|
||||||
|
|
||||||
fn resume_inhibited_notifications(&self) {
|
fn resume_inhibited_notifications(&self) {
|
||||||
for notification in self.inhibited_idle_notifications.lock().drain_values() {
|
for notification in self.inhibited_idle_notifications.lock().drain_values() {
|
||||||
notification.resume.trigger();
|
notification.resume.trigger();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue