Skip to content

Commit 4aa7d14

Browse files
lenemterzeebokdanirabbit
authored
Register EndSessionDialog on start (#138)
Co-authored-by: Ryan Kornheisl <ryan@skarva.tech> Co-authored-by: Danielle Foré <danielle@elementary.io>
1 parent 87c8ab4 commit 4aa7d14

4 files changed

Lines changed: 54 additions & 61 deletions

File tree

data/quick-settings.metainfo.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
</description>
4141
<issues>
4242
<issue url="https://github.com/elementary/quick-settings/issues/45">End Session Dialog should pull visual focus</issue>
43+
<issue url="https://github.com/elementary/quick-settings/issues/135">Ctrl+Alt+Del not available before opening Quick Settings for the first time</issue>
4344
</issues>
4445
</release>
4546

src/DBus/EndSessionDialogServer.vala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public class QuickSettings.EndSessionDialogServer : Object {
3030
}
3131

3232
[DBus (visible = false)]
33-
public signal void show_dialog (uint type, uint32 triggering_event_timestamp);
33+
public signal void show_dialog (uint type);
3434

3535
public signal void confirmed_logout ();
3636
public signal void confirmed_reboot ();
@@ -47,6 +47,6 @@ public class QuickSettings.EndSessionDialogServer : Object {
4747
throw new DBusError.NOT_SUPPORTED ("Hibernate, suspend and hybrid sleep are not supported actions yet");
4848
}
4949

50-
show_dialog (type, timestamp);
50+
show_dialog (type);
5151
}
5252
}

src/Indicator.vala

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
public class QuickSettings.Indicator : Wingpanel.Indicator {
77
public Wingpanel.IndicatorManager.ServerType server_type { get; construct; }
88

9+
private EndSessionDialog? current_dialog;
910
private PopoverWidget? popover_widget;
1011

1112
public Indicator (Wingpanel.IndicatorManager.ServerType server_type) {
@@ -23,6 +24,55 @@ public class QuickSettings.Indicator : Wingpanel.Indicator {
2324
// Prevent a race that skips automatic resource loading
2425
// https://github.com/elementary/wingpanel-indicator-bluetooth/issues/203
2526
Gtk.IconTheme.get_default ().add_resource_path ("/org/elementary/wingpanel/icons");
27+
28+
EndSessionDialogServer.init ();
29+
EndSessionDialogServer.get_default ().show_dialog.connect (
30+
(type) => show_dialog ((EndSessionDialogType) type)
31+
);
32+
}
33+
34+
private void show_dialog (EndSessionDialogType type) {
35+
((Gtk.Popover?) popover_widget?.get_ancestor (typeof (Gtk.Popover)))?.popdown ();
36+
37+
if (current_dialog != null) {
38+
if (current_dialog.dialog_type != type) {
39+
current_dialog.destroy ();
40+
} else {
41+
return;
42+
}
43+
}
44+
45+
unowned var server = EndSessionDialogServer.get_default ();
46+
47+
current_dialog = new EndSessionDialog (type);
48+
current_dialog.destroy.connect (() => {
49+
server.closed ();
50+
current_dialog = null;
51+
});
52+
53+
current_dialog.cancelled.connect (() => server.canceled ());
54+
current_dialog.logout.connect (() => server.confirmed_logout ());
55+
current_dialog.shutdown.connect (() => {
56+
try {
57+
// See https://www.freedesktop.org/software/systemd/man/latest/org.freedesktop.login1.html for flags values
58+
// #define SD_LOGIND_ROOT_CHECK_INHIBITORS (UINT64_C(1) << 0) == 1
59+
Login1Manager.get_default ().proxy.power_off_with_flags (1);
60+
} catch (Error e) {
61+
warning ("Unable to shutdown: %s", e.message);
62+
}
63+
});
64+
65+
current_dialog.reboot.connect (() => {
66+
try {
67+
// See https://www.freedesktop.org/software/systemd/man/latest/org.freedesktop.login1.html for flags values
68+
// #define SD_LOGIND_KEXEC_REBOOT (UINT64_C(1) << 1) == 2
69+
Login1Manager.get_default ().proxy.reboot_with_flags (2);
70+
} catch (Error e) {
71+
warning ("Unable to reboot: %s", e.message);
72+
}
73+
});
74+
75+
current_dialog.present ();
2676
}
2777

2878
public override Gtk.Widget get_display_widget () {

src/Widgets/SessionBox.vala

Lines changed: 1 addition & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
public class QuickSettings.SessionBox : Gtk.Box {
77
public Wingpanel.IndicatorManager.ServerType server_type { get; construct; }
88

9-
private EndSessionDialog? current_dialog = null;
109
private Gtk.Popover? popover;
1110

1211
public SessionBox (Wingpanel.IndicatorManager.ServerType server_type) {
@@ -65,7 +64,7 @@ public class QuickSettings.SessionBox : Gtk.Box {
6564

6665
shutdown_button.clicked.connect (() => {
6766
popover.popdown ();
68-
show_dialog (EndSessionDialogType.RESTART);
67+
EndSessionDialogServer.get_default ().show_dialog (EndSessionDialogType.RESTART);
6968
});
7069

7170
suspend_button.clicked.connect (() => {
@@ -90,11 +89,6 @@ public class QuickSettings.SessionBox : Gtk.Box {
9089
);
9190
});
9291

93-
EndSessionDialogServer.init ();
94-
EndSessionDialogServer.get_default ().show_dialog.connect (
95-
(type, timestamp) => show_dialog ((EndSessionDialogType) type)
96-
);
97-
9892
settings_button.clicked.connect (() => {
9993
popover.popdown ();
10094

@@ -114,56 +108,4 @@ public class QuickSettings.SessionBox : Gtk.Box {
114108
return null;
115109
}
116110
}
117-
118-
private void show_dialog (EndSessionDialogType type) {
119-
popover.popdown ();
120-
121-
if (current_dialog != null) {
122-
if (current_dialog.dialog_type != type) {
123-
current_dialog.destroy ();
124-
} else {
125-
return;
126-
}
127-
}
128-
129-
unowned var server = EndSessionDialogServer.get_default ();
130-
131-
current_dialog = new EndSessionDialog (type) {
132-
transient_for = (Gtk.Window) get_toplevel ()
133-
};
134-
current_dialog.destroy.connect (() => {
135-
server.closed ();
136-
current_dialog = null;
137-
});
138-
139-
current_dialog.cancelled.connect (() => {
140-
server.canceled ();
141-
});
142-
143-
current_dialog.logout.connect (() => {
144-
server.confirmed_logout ();
145-
});
146-
147-
current_dialog.shutdown.connect (() => {
148-
try {
149-
// See https://www.freedesktop.org/software/systemd/man/latest/org.freedesktop.login1.html for flags values
150-
// #define SD_LOGIND_ROOT_CHECK_INHIBITORS (UINT64_C(1) << 0) == 1
151-
Login1Manager.get_default ().proxy.power_off_with_flags (1);
152-
} catch (Error e) {
153-
warning ("Unable to shutdown: %s", e.message);
154-
}
155-
});
156-
157-
current_dialog.reboot.connect (() => {
158-
try {
159-
// See https://www.freedesktop.org/software/systemd/man/latest/org.freedesktop.login1.html for flags values
160-
// #define SD_LOGIND_KEXEC_REBOOT (UINT64_C(1) << 1) == 2
161-
Login1Manager.get_default ().proxy.reboot_with_flags (2);
162-
} catch (Error e) {
163-
warning ("Unable to reboot: %s", e.message);
164-
}
165-
});
166-
167-
current_dialog.present ();
168-
}
169111
}

0 commit comments

Comments
 (0)