diff --git a/data/quick-settings.metainfo.xml b/data/quick-settings.metainfo.xml index e1a40e9..a481cc0 100644 --- a/data/quick-settings.metainfo.xml +++ b/data/quick-settings.metainfo.xml @@ -40,6 +40,7 @@ End Session Dialog should pull visual focus + Ctrl+Alt+Del not available before opening Quick Settings for the first time diff --git a/src/DBus/EndSessionDialogServer.vala b/src/DBus/EndSessionDialogServer.vala index 34a6dc8..899c715 100644 --- a/src/DBus/EndSessionDialogServer.vala +++ b/src/DBus/EndSessionDialogServer.vala @@ -30,7 +30,7 @@ public class QuickSettings.EndSessionDialogServer : Object { } [DBus (visible = false)] - public signal void show_dialog (uint type, uint32 triggering_event_timestamp); + public signal void show_dialog (uint type); public signal void confirmed_logout (); public signal void confirmed_reboot (); @@ -47,6 +47,6 @@ public class QuickSettings.EndSessionDialogServer : Object { throw new DBusError.NOT_SUPPORTED ("Hibernate, suspend and hybrid sleep are not supported actions yet"); } - show_dialog (type, timestamp); + show_dialog (type); } } diff --git a/src/Indicator.vala b/src/Indicator.vala index 04642b1..39c175c 100644 --- a/src/Indicator.vala +++ b/src/Indicator.vala @@ -6,6 +6,7 @@ public class QuickSettings.Indicator : Wingpanel.Indicator { public Wingpanel.IndicatorManager.ServerType server_type { get; construct; } + private EndSessionDialog? current_dialog; private PopoverWidget? popover_widget; public Indicator (Wingpanel.IndicatorManager.ServerType server_type) { @@ -23,6 +24,55 @@ public class QuickSettings.Indicator : Wingpanel.Indicator { // Prevent a race that skips automatic resource loading // https://github.com/elementary/wingpanel-indicator-bluetooth/issues/203 Gtk.IconTheme.get_default ().add_resource_path ("/org/elementary/wingpanel/icons"); + + EndSessionDialogServer.init (); + EndSessionDialogServer.get_default ().show_dialog.connect ( + (type) => show_dialog ((EndSessionDialogType) type) + ); + } + + private void show_dialog (EndSessionDialogType type) { + ((Gtk.Popover?) popover_widget?.get_ancestor (typeof (Gtk.Popover)))?.popdown (); + + if (current_dialog != null) { + if (current_dialog.dialog_type != type) { + current_dialog.destroy (); + } else { + return; + } + } + + unowned var server = EndSessionDialogServer.get_default (); + + current_dialog = new EndSessionDialog (type); + current_dialog.destroy.connect (() => { + server.closed (); + current_dialog = null; + }); + + current_dialog.cancelled.connect (() => server.canceled ()); + current_dialog.logout.connect (() => server.confirmed_logout ()); + current_dialog.shutdown.connect (() => { + try { + // See https://www.freedesktop.org/software/systemd/man/latest/org.freedesktop.login1.html for flags values + // #define SD_LOGIND_ROOT_CHECK_INHIBITORS (UINT64_C(1) << 0) == 1 + Login1Manager.get_default ().proxy.power_off_with_flags (1); + } catch (Error e) { + warning ("Unable to shutdown: %s", e.message); + } + }); + + current_dialog.reboot.connect (() => { + try { + // See https://www.freedesktop.org/software/systemd/man/latest/org.freedesktop.login1.html for flags values + // #define SD_LOGIND_KEXEC_REBOOT (UINT64_C(1) << 1) == 2 + Login1Manager.get_default ().proxy.reboot_with_flags (2); + } catch (Error e) { + warning ("Unable to reboot: %s", e.message); + } + }); + + current_dialog.present (); } public override Gtk.Widget get_display_widget () { diff --git a/src/Widgets/SessionBox.vala b/src/Widgets/SessionBox.vala index a510547..1a404fc 100644 --- a/src/Widgets/SessionBox.vala +++ b/src/Widgets/SessionBox.vala @@ -6,7 +6,6 @@ public class QuickSettings.SessionBox : Gtk.Box { public Wingpanel.IndicatorManager.ServerType server_type { get; construct; } - private EndSessionDialog? current_dialog = null; private Gtk.Popover? popover; public SessionBox (Wingpanel.IndicatorManager.ServerType server_type) { @@ -65,7 +64,7 @@ public class QuickSettings.SessionBox : Gtk.Box { shutdown_button.clicked.connect (() => { popover.popdown (); - show_dialog (EndSessionDialogType.RESTART); + EndSessionDialogServer.get_default ().show_dialog (EndSessionDialogType.RESTART); }); suspend_button.clicked.connect (() => { @@ -90,11 +89,6 @@ public class QuickSettings.SessionBox : Gtk.Box { ); }); - EndSessionDialogServer.init (); - EndSessionDialogServer.get_default ().show_dialog.connect ( - (type, timestamp) => show_dialog ((EndSessionDialogType) type) - ); - settings_button.clicked.connect (() => { popover.popdown (); @@ -114,56 +108,4 @@ public class QuickSettings.SessionBox : Gtk.Box { return null; } } - - private void show_dialog (EndSessionDialogType type) { - popover.popdown (); - - if (current_dialog != null) { - if (current_dialog.dialog_type != type) { - current_dialog.destroy (); - } else { - return; - } - } - - unowned var server = EndSessionDialogServer.get_default (); - - current_dialog = new EndSessionDialog (type) { - transient_for = (Gtk.Window) get_toplevel () - }; - current_dialog.destroy.connect (() => { - server.closed (); - current_dialog = null; - }); - - current_dialog.cancelled.connect (() => { - server.canceled (); - }); - - current_dialog.logout.connect (() => { - server.confirmed_logout (); - }); - - current_dialog.shutdown.connect (() => { - try { - // See https://www.freedesktop.org/software/systemd/man/latest/org.freedesktop.login1.html for flags values - // #define SD_LOGIND_ROOT_CHECK_INHIBITORS (UINT64_C(1) << 0) == 1 - Login1Manager.get_default ().proxy.power_off_with_flags (1); - } catch (Error e) { - warning ("Unable to shutdown: %s", e.message); - } - }); - - current_dialog.reboot.connect (() => { - try { - // See https://www.freedesktop.org/software/systemd/man/latest/org.freedesktop.login1.html for flags values - // #define SD_LOGIND_KEXEC_REBOOT (UINT64_C(1) << 1) == 2 - Login1Manager.get_default ().proxy.reboot_with_flags (2); - } catch (Error e) { - warning ("Unable to reboot: %s", e.message); - } - }); - - current_dialog.present (); - } }