Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
4 changes: 2 additions & 2 deletions src/DBus/EndSessionDialogServer.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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 ();
Expand All @@ -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);
}
}
50 changes: 50 additions & 0 deletions src/Indicator.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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 () {
Expand Down
60 changes: 1 addition & 59 deletions src/Widgets/SessionBox.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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 (() => {
Expand All @@ -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 ();

Expand All @@ -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 ();
}
}