-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathPreventSleepToggle.vala
More file actions
48 lines (40 loc) · 1.66 KB
/
PreventSleepToggle.vala
File metadata and controls
48 lines (40 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*
* SPDX-License-Identifier: GPL-3.0-or-later
* SPDX-FileCopyrightText: 2025 elementary, Inc. (https://elementary.io)
*/
public class QuickSettings.PreventSleepToggle: SettingsToggle {
private uint suspend_cookie = 0;
private uint idle_cookie = 0;
public PreventSleepToggle () {
Object (
icon: new ThemedIcon ("system-suspend-symbolic"),
label: _("Prevent Sleep")
);
}
construct {
settings_uri = "settings://power";
notify["active"].connect ((obj, pspec) => {
var _prevent_sleep_toggle = (SettingsToggle) obj;
unowned var application = (Gtk.Application) GLib.Application.get_default ();
if (_prevent_sleep_toggle.active && suspend_cookie == 0 && idle_cookie == 0) {
suspend_cookie = application.inhibit (
(Gtk.Window) get_toplevel (),
Gtk.ApplicationInhibitFlags.SUSPEND,
"Prevent session from suspending"
);
idle_cookie = application.inhibit (
(Gtk.Window) get_toplevel (),
Gtk.ApplicationInhibitFlags.IDLE,
"Prevent session from idle"
);
icon = new ThemedIcon ("system-suspend-disabled-symbolic");
} else if (!_prevent_sleep_toggle.active && suspend_cookie > 0 && idle_cookie > 0) {
application.uninhibit (suspend_cookie);
application.uninhibit (idle_cookie);
icon = new ThemedIcon ("system-suspend-symbolic");
suspend_cookie = 0;
idle_cookie = 0;
}
});
}
}