Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
lenemter committed Jan 28, 2024
1 parent 7111c22 commit aa970bb
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 91 deletions.
11 changes: 0 additions & 11 deletions src/Cards/UserCard.vala
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ public class Greeter.UserCard : Greeter.BaseCard {

public LightDM.User lightdm_user { get; construct; }
public bool show_input { get; set; default = false; }
public double reveal_ratio { get; private set; default = 0.0; }
public bool is_24h { get; set; default = true; }

public int prefers_accent_color { get; set; default = 6; }
Expand Down Expand Up @@ -236,20 +235,10 @@ public class Greeter.UserCard : Greeter.BaseCard {
}
});

// This makes all the animations synchonous
form_revealer.size_allocate.connect ((alloc) => {
var total_height = form_box.get_allocated_height () + form_box.margin_top + form_box.margin_bottom;
reveal_ratio = (double)alloc.height / (double)total_height;
});

notify["show-input"].connect (() => {
update_collapsed_class ();
});

notify["child-revealed"].connect (() => {
reveal_ratio = child_revealed ? 1.0 : 0.0;
});

password_entry.activate.connect (on_login);
login_button.clicked.connect (on_login);

Expand Down
133 changes: 53 additions & 80 deletions src/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,17 @@ public class Greeter.MainWindow : Gtk.ApplicationWindow {

private GLib.Queue<unowned Greeter.UserCard> user_cards;
private Gtk.SizeGroup card_size_group;
private int index_delta = 0;
private Hdy.Carousel carousel;
private LightDM.Greeter lightdm_greeter;
private Greeter.Settings settings;
private Gtk.Button guest_login_button;
private Gtk.ToggleButton manual_login_button;
private Greeter.DateTimeWidget datetime_widget;
private unowned Greeter.BaseCard current_card;
private unowned LightDM.UserList lightdm_user_list;

private int current_user_card_index = 0;
private unowned Greeter.BaseCard? current_card = null;

private bool installer_mode = false;

private const uint[] NAVIGATION_KEYS = {
Expand Down Expand Up @@ -125,7 +126,8 @@ public class Greeter.MainWindow : Gtk.ApplicationWindow {
}

manual_login_stack.visible_child = carousel;
current_card = user_cards.peek_nth (index_delta);
current_card = user_cards.peek_nth (current_user_card_index);

try {
lightdm_greeter.authenticate (((UserCard) current_card).lightdm_user.name);
} catch (Error e) {
Expand All @@ -142,23 +144,10 @@ public class Greeter.MainWindow : Gtk.ApplicationWindow {
}
});

GLib.ActionEntry entries[] = {
GLib.ActionEntry () {
name = "previous",
activate = go_previous
},
GLib.ActionEntry () {
name = "next",
activate = go_next
}
};

card_size_group = new Gtk.SizeGroup (Gtk.SizeGroupMode.HORIZONTAL);
card_size_group.add_widget (extra_login_grid);
card_size_group.add_widget (manual_card);

add_action_entries (entries, this);

lightdm_greeter = new LightDM.Greeter ();
lightdm_greeter.show_message.connect (show_message);
lightdm_greeter.show_prompt.connect (show_prompt);
Expand Down Expand Up @@ -194,47 +183,48 @@ public class Greeter.MainWindow : Gtk.ApplicationWindow {
manual_card.do_connect.connect (do_connect);

key_press_event.connect ((event) => {
if (!(event.keyval in NAVIGATION_KEYS)) {
// Don't focus if it is a modifier or if search_box is already focused
unowned var current_focus = get_focus ();
if ((event.is_modifier == 0) && (current_focus == null || !current_focus.is_ancestor (current_card))) {
current_card.grab_focus ();
}

return Gdk.EVENT_PROPAGATE;
}

// arrow key is being used to navigate
if (event.keyval in NAVIGATION_KEYS) {
if (current_card is UserCard) {
weak Gtk.Widget? current_focus = get_focus ();
if (current_focus is Gtk.Entry && current_focus.is_ancestor (current_card)) {
if (((Gtk.Entry) current_focus).text == "") {
if (event.keyval == Gdk.Key.Left) {
if (get_style_context ().direction == Gtk.TextDirection.RTL) {
activate_action ("next", null);
} else {
activate_action ("previous", null);
}
return true;
} else if (event.keyval == Gdk.Key.Right) {
if (get_style_context ().direction == Gtk.TextDirection.RTL) {
activate_action ("previous", null);
} else {
activate_action ("next", null);
}
return true;
if (current_card is UserCard) {
unowned var focused_entry = (Gtk.Entry) get_focus ();
if (focused_entry != null && focused_entry.is_ancestor (current_card)) {
if (focused_entry.text == "") {
if (event.keyval == Gdk.Key.Left) {
if (get_style_context ().direction == LTR) {
go_previous ();
} else {
go_next ();
}
return Gdk.EVENT_STOP;
} else if (event.keyval == Gdk.Key.Right) {
if (get_style_context ().direction == LTR) {
go_next ();
} else {
go_previous ();
}
return Gdk.EVENT_STOP;
}
}
}

return false;
}

// Don't focus if it is a modifier or if search_box is already focused
weak Gtk.Widget? current_focus = get_focus ();
if ((event.is_modifier == 0) && (current_focus == null || !current_focus.is_ancestor (current_card))) {
current_card.grab_focus ();
}

return false;
return Gdk.EVENT_PROPAGATE;
});

carousel.page_changed.connect ((index) => {
var children = carousel.get_children ();

if (children.nth_data (index) is Greeter.UserCard) {
current_user_card_index = (int) index;
switch_to_card ((Greeter.UserCard) children.nth_data (index));
}
});
Expand Down Expand Up @@ -471,7 +461,7 @@ public class Greeter.MainWindow : Gtk.ApplicationWindow {
}

if (!user_selected) {
unowned Greeter.UserCard user_card = (Greeter.UserCard) user_cards.peek_head ();
unowned var user_card = user_cards.peek_head ();
user_card.show_input = true;
switch_to_card (user_card);
}
Expand Down Expand Up @@ -517,18 +507,18 @@ public class Greeter.MainWindow : Gtk.ApplicationWindow {
});

user_card.go_left.connect (() => {
if (get_style_context ().direction == Gtk.TextDirection.RTL) {
activate_action ("next", null);
if (get_style_context ().direction == LTR) {
go_previous ();
} else {
activate_action ("previous", null);
go_next ();
}
});

user_card.go_right.connect (() => {
if (get_style_context ().direction == Gtk.TextDirection.RTL) {
activate_action ("previous", null);
if (get_style_context ().direction == LTR) {
go_next ();
} else {
activate_action ("next", null);
go_previous ();
}
});

Expand All @@ -538,33 +528,25 @@ public class Greeter.MainWindow : Gtk.ApplicationWindow {
user_cards.push_tail (user_card);
}

int next_delta = 0;
weak GLib.Binding? binding = null;
private unowned GLib.Binding? time_format_binding = null;
private void switch_to_card (Greeter.UserCard user_card) {
if (next_delta != index_delta) {
return;
if (current_card != null && current_card is UserCard) {
((UserCard) current_card).show_input = false;
}

current_card = user_card;
if (binding != null) {
binding.unbind ();
if (time_format_binding != null) {
time_format_binding.unbind ();
}
time_format_binding = user_card.bind_property ("is-24h", datetime_widget, "is-24h", GLib.BindingFlags.SYNC_CREATE);

user_card.set_settings ();

binding = user_card.bind_property ("is-24h", datetime_widget, "is-24h", GLib.BindingFlags.SYNC_CREATE);
next_delta = user_cards.index (user_card);
current_card = user_card;

carousel.scroll_to (user_card);

user_card.notify["reveal-ratio"].connect (notify_cb);
user_card.set_settings ();
user_card.show_input = true;
user_card.grab_focus ();

if (index_delta != next_delta) {
((Greeter.UserCard) user_cards.peek_nth (index_delta)).show_input = false;
}

if (user_card.lightdm_user.session != null) {
get_action_group ("session").activate_action ("select", new GLib.Variant.string (user_card.lightdm_user.session));
}
Expand All @@ -584,15 +566,6 @@ public class Greeter.MainWindow : Gtk.ApplicationWindow {
}
}

private void notify_cb (GLib.Object obj, GLib.ParamSpec spec) {
unowned var user_card = (Greeter.UserCard) obj;
if (user_card.reveal_ratio == 1.0) {
index_delta = next_delta;
user_card.notify["reveal-ratio"].disconnect (notify_cb);
return;
}
}

private void do_connect_username (string username) {
if (lightdm_greeter.in_authentication) {
try {
Expand All @@ -619,15 +592,15 @@ public class Greeter.MainWindow : Gtk.ApplicationWindow {
}
}

private void go_previous (GLib.SimpleAction action, GLib.Variant? parameter) {
unowned Greeter.UserCard? next_card = (Greeter.UserCard) user_cards.peek_nth (index_delta - 1);
private void go_previous () {
unowned Greeter.UserCard? next_card = user_cards.peek_nth (current_user_card_index - 1);
if (next_card != null) {
carousel.scroll_to (next_card);
}
}

private void go_next (GLib.SimpleAction action, GLib.Variant? parameter) {
unowned Greeter.UserCard? next_card = (Greeter.UserCard) user_cards.peek_nth (index_delta + 1);
private void go_next () {
unowned Greeter.UserCard? next_card = user_cards.peek_nth (current_user_card_index + 1);
if (next_card != null) {
carousel.scroll_to (next_card);
}
Expand Down

0 comments on commit aa970bb

Please sign in to comment.