Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions data/icons/system-suspend-disabled.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions data/quick-settings.gresource.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<gresource prefix="/org/elementary/wingpanel/icons">
<file alias="scalable/status/dark-mode-symbolic.svg" compressed="true" preprocess="xml-stripblanks">icons/dark-mode.svg</file>
<file alias="scalable/status/system-suspend-symbolic.svg" compressed="true" preprocess="xml-stripblanks">icons/system-suspend.svg</file>
<file alias="scalable/status/system-suspend-disabled-symbolic.svg" compressed="true" preprocess="xml-stripblanks">icons/system-suspend-disabled.svg</file>
<file alias="scalable/status/quick-settings-symbolic.svg" compressed="true" preprocess="xml-stripblanks">icons/quick-settings.svg</file>
<file alias="scalable/status/quick-settings-rotation-allowed-symbolic.svg" compressed="true" preprocess="xml-stripblanks">icons/rotation-allowed.svg</file>
<file alias="scalable/status/quick-settings-rotation-locked-symbolic.svg" compressed="true" preprocess="xml-stripblanks">icons/rotation-locked.svg</file>
Expand Down
1 change: 1 addition & 0 deletions po/POTFILES
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ src/Services/UserManager.vala
src/Widgets/CurrentUser.vala
src/Widgets/DarkModeToggle.vala
src/Widgets/EndSessionDialog.vala
src/Widgets/PreventSleepToggle.vala
src/Widgets/RotationToggle.vala
src/Widgets/SessionBox.vala
src/Widgets/SettingsToggle.vala
Expand Down
32 changes: 1 addition & 31 deletions src/PopoverWidget.vala
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ public class QuickSettings.PopoverWidget : Gtk.Box {
private UserList accounts_view;
private Gtk.Button current_user_button;

private uint suspend_cookie = 0;
private uint idle_cookie = 0;

public PopoverWidget (Wingpanel.IndicatorManager.ServerType server_type) {
Object (server_type: server_type);
}
Expand All @@ -41,10 +38,7 @@ public class QuickSettings.PopoverWidget : Gtk.Box {
settings_uri = "settings://input/keyboard/behavior"
};

var prevent_sleep_toggle = new SettingsToggle (
new ThemedIcon ("weather-clear-night"),
_("Prevent Sleep")
);
var prevent_sleep_toggle = new PreventSleepToggle ();

var toggle_box = new Gtk.FlowBox () {
column_spacing = 6,
Expand Down Expand Up @@ -149,30 +143,6 @@ public class QuickSettings.PopoverWidget : Gtk.Box {
}
});

prevent_sleep_toggle.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"
);
} else if (!_prevent_sleep_toggle.active && suspend_cookie > 0 && idle_cookie > 0) {
application.uninhibit (suspend_cookie);
application.uninhibit (idle_cookie);

suspend_cookie = 0;
idle_cookie = 0;
}
});

current_user_button.clicked.connect (() => {
stack.visible_child = accounts_view;
});
Expand Down
48 changes: 48 additions & 0 deletions src/Widgets/PreventSleepToggle.vala
Original file line number Diff line number Diff line change
@@ -0,0 +1,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;
}
});
}
}
1 change: 1 addition & 0 deletions src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ sources = [
'Widgets' / 'CurrentUser.vala',
'Widgets' / 'DarkModeToggle.vala',
'Widgets' / 'EndSessionDialog.vala',
'Widgets' / 'PreventSleepToggle.vala',
'Widgets' / 'RotationToggle.vala',
'Widgets' / 'SettingsToggle.vala',
'Widgets' / 'SessionBox.vala',
Expand Down