Skip to content

Commit c004c2c

Browse files
committed
Fade out on shutdown
1 parent e5666ea commit c004c2c

File tree

4 files changed

+71
-0
lines changed

4 files changed

+71
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/*
2+
* SPDX-License-Identifier: GPL-3.0-or-later
3+
* SPDX-FileCopyrightText: 2025 elementary, Inc. (https://elementary.io)
4+
*/
5+
6+
[DBus (name = "org.freedesktop.login1.Manager")]
7+
public interface Gala.LoginManager : Object {
8+
public signal void prepare_for_sleep (bool about_to_suspend);
9+
public signal void prepare_for_shutdown (bool about_to_shutdown);
10+
11+
public abstract GLib.ObjectPath get_session (string session_id) throws GLib.Error;
12+
public abstract UnixInputStream inhibit (string what, string who, string why, string mode) throws GLib.Error;
13+
}

src/ShutdownManager.vala

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* SPDX-License-Identifier: GPL-3.0-or-later
3+
* SPDX-FileCopyrightText: 2025 elementary, Inc. (https://elementary.io)
4+
*/
5+
6+
public class Gala.ShutdownManager : Object {
7+
public ScreenShield screen_shield { private get; construct; }
8+
9+
private LoginManager? login_manager;
10+
private UnixInputStream? inhibitor;
11+
12+
public ShutdownManager (ScreenShield screen_shield) {
13+
Object (screen_shield: screen_shield);
14+
}
15+
16+
construct {
17+
setup_dbus_interface.begin ();
18+
}
19+
20+
private async void setup_dbus_interface () {
21+
try {
22+
login_manager = yield Bus.get_proxy (BusType.SYSTEM, "org.freedesktop.login1", "/org/freedesktop/login1");
23+
inhibit_shutdown ();
24+
25+
login_manager.prepare_for_shutdown.connect ((about_to_shutdown) => {
26+
if (!about_to_shutdown) {
27+
return;
28+
}
29+
30+
screen_shield.activate (300, remove_inhibitor);
31+
});
32+
} catch (Error e) {
33+
warning ("Couldn't get login manager: %s", e.message);
34+
}
35+
}
36+
37+
private void inhibit_shutdown () requires (login_manager != null && inhibitor == null) {
38+
try {
39+
inhibitor = login_manager.inhibit ("shutdown", "Pantheon", "Pantheon needs to play shutdown animation", "delay");
40+
} catch (Error e) {
41+
warning ("Couldn't inhibit shutdown, no shutdown animation will be player: %s", e.message);
42+
}
43+
}
44+
45+
private void remove_inhibitor () requires (inhibitor != null) {
46+
try {
47+
inhibitor.close ();
48+
} catch (Error e) {
49+
warning ("Couldn't remove shutdown inhibitor: %s", e.message);
50+
}
51+
}
52+
}

src/WindowManager.vala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ namespace Gala {
7272

7373
public ScreenSaverManager? screensaver { get; private set; }
7474

75+
public ShutdownManager shutdown_manager { get; private set; }
76+
7577
private HotCornerManager? hot_corner_manager = null;
7678

7779
public WindowTracker? window_tracker { get; private set; }
@@ -285,6 +287,8 @@ namespace Gala {
285287
// is set to NONE when we are in locked mode
286288
screensaver.active_changed.connect (update_input_area);
287289

290+
shutdown_manager = new ShutdownManager (screen_shield);
291+
288292
FilterManager.init (this);
289293

290294
/*keybindings*/

src/meson.build

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ gala_bin_sources = files(
1414
'ScreenshotManager.vala',
1515
'SessionLocker.vala',
1616
'SessionManager.vala',
17+
'ShutdownManager.vala',
1718
'SuperScrollAction.vala',
1819
'WindowAttentionTracker.vala',
1920
'WindowListener.vala',
@@ -33,6 +34,7 @@ gala_bin_sources = files(
3334
'ColorFilters/ColorblindnessCorrectionEffect.vala',
3435
'ColorFilters/FilterManager.vala',
3536
'ColorFilters/MonochromeEffect.vala',
37+
'DBusInterfaces/LoginManager.vala',
3638
'Dialogs/AccessDialog.vala',
3739
'Dialogs/CloseDialog.vala',
3840
'Dialogs/InhibitShortcutsDialog.vala',

0 commit comments

Comments
 (0)