Skip to content

Commit

Permalink
MainWindow: use built-in action group for select-session (#766)
Browse files Browse the repository at this point in the history
  • Loading branch information
danirabbit authored Oct 18, 2024
1 parent 10ac491 commit 23d66f2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
13 changes: 5 additions & 8 deletions src/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ public class Greeter.MainWindow : Gtk.ApplicationWindow {
unowned GLib.List<LightDM.Session> sessions = LightDM.get_sessions ();
weak LightDM.Session? first_session = sessions.nth_data (0);
var selected_session = new GLib.Variant.string (first_session != null ? first_session.key : "");
var select_session_action = new GLib.SimpleAction.stateful ("select", GLib.VariantType.STRING, selected_session);
var select_session_action = new GLib.SimpleAction.stateful ("select-session", GLib.VariantType.STRING, selected_session);
var vardict = new GLib.VariantDict ();
sessions.foreach ((session) => {
vardict.insert_value (session.name, new GLib.Variant.string (session.key));
Expand All @@ -311,9 +311,7 @@ public class Greeter.MainWindow : Gtk.ApplicationWindow {
}
});

var action_group = new GLib.SimpleActionGroup ();
action_group.add_action (select_session_action);
insert_action_group ("session", action_group);
add_action (select_session_action);
}

private void show_message (string text, LightDM.MessageType type) {
Expand Down Expand Up @@ -372,9 +370,8 @@ public class Greeter.MainWindow : Gtk.ApplicationWindow {
settings.sleep_inactive_battery_type = user_card.sleep_inactive_battery_type;
}

var action_group = get_action_group ("session");
try {
unowned var session = action_group.get_action_state ("select").get_string ();
unowned var session = get_action_state ("select-session").get_string ();

// If the greeter is running on the install medium, check if the Installer has signalled
// that it wants the greeter to launch the live (demo) session by means of touching a file
Expand Down Expand Up @@ -427,7 +424,7 @@ public class Greeter.MainWindow : Gtk.ApplicationWindow {
lightdm_greeter.notify_property ("has-guest-account-hint");

if (lightdm_greeter.default_session_hint != null) {
get_action_group ("session").activate_action ("select", new GLib.Variant.string (lightdm_greeter.default_session_hint));
activate_action ("select-session", new GLib.Variant.string (lightdm_greeter.default_session_hint));
}

// Check if the installer is installed
Expand Down Expand Up @@ -547,7 +544,7 @@ public class Greeter.MainWindow : Gtk.ApplicationWindow {
user_card.grab_focus ();

if (user_card.lightdm_user.session != null) {
get_action_group ("session").activate_action ("select", new GLib.Variant.string (user_card.lightdm_user.session));
activate_action ("select-session", new GLib.Variant.string (user_card.lightdm_user.session));
}

if (lightdm_greeter.in_authentication) {
Expand Down
7 changes: 3 additions & 4 deletions src/Widgets/SessionButton.vala
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,14 @@ public class Greeter.SessionButton : Gtk.MenuButton {

// The session action is on the MainWindow toplevel, wait until it is accessible.
hierarchy_changed.connect ((previous_toplevel) => {
var main_window = get_ancestor (typeof (Greeter.MainWindow));
var main_window = (Gtk.ApplicationWindow) get_ancestor (typeof (Gtk.ApplicationWindow));
if (main_window != null) {
var session_action_group = main_window.get_action_group ("session");
var hint = session_action_group.get_action_state_hint ("select");
var hint = main_window.get_action_state_hint ("select-session");
var iter = hint.iterator ();
GLib.Variant? val = null;
string? key = null;
while (iter.next ("{sv}", out key, out val)) {
menu.append (key, Action.print_detailed_name ("session.select", val));
menu.append (key, Action.print_detailed_name ("win.select-session", val));
}

if (menu.get_n_items () == 0) {
Expand Down

0 comments on commit 23d66f2

Please sign in to comment.