Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
8 changes: 6 additions & 2 deletions src/Cards/BaseCard.vala
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
/*
* SPDX-License-Identifier: GPL-2.0-or-later
* SPDX-FileCopyrightText: 2018-2025 elementary, Inc. (https://elementary.io)
* SPDX-FileCopyrightText: 2018-2026 elementary, Inc. (https://elementary.io)
*
* Authors: Corentin Noël <corentin@elementary.io>
*/

public abstract class Greeter.BaseCard : Gtk.Bin {
public signal void do_connect (string? credential = null);
public signal void start_authentication (string username);
public signal void provide_credential (string credential);
public signal void go_left ();
public signal void go_right ();

Expand Down Expand Up @@ -34,5 +35,8 @@ public abstract class Greeter.BaseCard : Gtk.Bin {
return base.focus (direction);
}

public virtual void on_selected () {}
public virtual void on_deselected () {}

public abstract void wrong_credentials ();
}
8 changes: 3 additions & 5 deletions src/Cards/ManualCard.vala
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
/*
* Copyright 2018-2023 elementary, Inc. (https://elementary.io)
* Copyright 2018-2026 elementary, Inc. (https://elementary.io)
* SPDX-License-Identifier: GPL-2.0-or-later
*/

public class Greeter.ManualCard : Greeter.BaseCard {
public signal void do_connect_username (string username);

private Greeter.PasswordEntry password_entry;
private Gtk.Entry username_entry;
private Gtk.Box main_box;
Expand Down Expand Up @@ -70,7 +68,7 @@ public class Greeter.ManualCard : Greeter.BaseCard {

username_entry.focus_out_event.connect (() => {
if (username_entry.text != "") {
do_connect_username (username_entry.text);
start_authentication (username_entry.text);
}
});

Expand All @@ -83,7 +81,7 @@ public class Greeter.ManualCard : Greeter.BaseCard {
}

connecting = true;
do_connect (password_entry.text);
provide_credential (password_entry.text);
}

public override void wrong_credentials () {
Expand Down
40 changes: 19 additions & 21 deletions src/Cards/UserCard.vala
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ public class Greeter.UserCard : Greeter.BaseCard {
* and lacks some fields from Act.User such as `password_mode`.
*/
public Act.User user { get; construct; }
public bool show_input { get; set; default = false; }
public bool is_24h { get; set; default = true; }
// TODO: In Gtk4 remove this gesture and move it to MainWindow
public Gtk.GestureMultiPress click_gesture { get; private set; }
Expand Down Expand Up @@ -98,11 +97,9 @@ public class Greeter.UserCard : Greeter.BaseCard {

form_revealer = new Gtk.Revealer () {
margin_bottom = 12,
reveal_child = true,
transition_type = SLIDE_DOWN,
child = login_stack
};
bind_property ("show-input", form_revealer, "reveal-child", SYNC_CREATE);

main_box = new Gtk.Box (Gtk.Orientation.VERTICAL, 0) {
margin_bottom = 48
Expand All @@ -113,8 +110,6 @@ public class Greeter.UserCard : Greeter.BaseCard {
main_box.get_style_context ().add_class (Granite.STYLE_CLASS_CARD);
main_box.get_style_context ().add_class (Granite.STYLE_CLASS_ROUNDED);

update_collapsed_class ();

var avatar = new Hdy.Avatar (64, user.real_name, true) {
margin_top = 6,
margin_bottom = 6,
Expand Down Expand Up @@ -146,6 +141,8 @@ public class Greeter.UserCard : Greeter.BaseCard {

child = card_overlay;

on_deselected ();

user.changed.connect (update_is_locked_ui);
notify["need-password"].connect (update_is_locked_ui);
update_is_locked_ui ();
Expand All @@ -155,8 +152,6 @@ public class Greeter.UserCard : Greeter.BaseCard {

click_gesture = new Gtk.GestureMultiPress (this);

notify["show-input"].connect (update_collapsed_class);

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

Expand Down Expand Up @@ -287,22 +282,10 @@ public class Greeter.UserCard : Greeter.BaseCard {
}

connecting = true;
if (need_password) {
do_connect (password_entry.text);
} else {
do_connect ();
}
provide_credential (need_password ? password_entry.text : "");
}

private void update_collapsed_class () {
if (show_input) {
main_box.get_style_context ().remove_class ("collapsed");
} else {
main_box.get_style_context ().add_class ("collapsed");
}
}

public void set_settings () {
private void set_settings () {
set_keyboard_layouts ();
set_mouse_touchpad_settings ();
set_interface_settings ();
Expand Down Expand Up @@ -443,6 +426,21 @@ public class Greeter.UserCard : Greeter.BaseCard {
SettingsPortal.get_default ().prefers_color_scheme = greeter_act.prefers_color_scheme;
}

public override void on_selected () {
form_revealer.reveal_child = true;
main_box.get_style_context ().remove_class ("collapsed");

set_settings ();
grab_focus ();

start_authentication (user.user_name);
}

public override void on_deselected () {
form_revealer.reveal_child = false;
main_box.get_style_context ().add_class ("collapsed");
}

public override void wrong_credentials () {
password_entry.get_style_context ().add_class (Gtk.STYLE_CLASS_ERROR);
main_box.get_style_context ().add_class ("shake");
Expand Down
82 changes: 20 additions & 62 deletions src/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -91,26 +91,12 @@ public class Greeter.MainWindow : Gtk.ApplicationWindow {
child = main_box;

manual_login_button.toggled.connect (() => {
if (manual_login_button.active) {
if (lightdm_greeter.in_authentication) {
try {
lightdm_greeter.cancel_authentication ();
} catch (Error e) {
critical (e.message);
}
}
cancel_authentication ();

if (manual_login_button.active) {
manual_login_stack.visible_child = manual_card;
current_card = manual_card;
} else {
if (lightdm_greeter.in_authentication) {
try {
lightdm_greeter.cancel_authentication ();
} catch (Error e) {
critical (e.message);
}
}

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

Expand Down Expand Up @@ -146,8 +132,8 @@ public class Greeter.MainWindow : Gtk.ApplicationWindow {
user_manager.notify["is-loaded"].connect (() => load_users.begin (show_greeter_window));
}

manual_card.do_connect_username.connect (do_connect_username);
manual_card.do_connect.connect (do_connect);
manual_card.start_authentication.connect (do_connect_username);
manual_card.provide_credential.connect (do_connect);

key_controller = new Gtk.EventControllerKey (this) {
propagation_phase = CAPTURE
Expand Down Expand Up @@ -358,7 +344,7 @@ public class Greeter.MainWindow : Gtk.ApplicationWindow {
unowned string? select_user = lightdm_greeter.select_user_hint;
var user_to_select = select_user != null ? select_user : gsettings.get_string ("last-user");

bool user_selected = false;
var user_selected = false;
user_cards.head.foreach ((card) => {
if (card.user.user_name == user_to_select) {
carousel.scroll_to (card);
Expand All @@ -367,9 +353,7 @@ public class Greeter.MainWindow : Gtk.ApplicationWindow {
});

if (!user_selected) {
unowned var user_card = user_cards.peek_head ();
user_card.show_input = true;
carousel.scroll_to (user_card);
carousel.scroll_to (user_cards.peek_head ());
}
} else {
datetime_revealer.reveal_child = false;
Expand Down Expand Up @@ -402,16 +386,9 @@ public class Greeter.MainWindow : Gtk.ApplicationWindow {
private void add_card (Act.User user) {
var user_card = new Greeter.UserCard (user);
user_card.show_all ();
user_card.do_connect.connect (do_connect);
user_card.click_gesture.pressed.connect ((gesture, n_press, x, y) => {
assert (gesture.widget is UserCard);

var _user_card = (UserCard) gesture.widget;
if (!_user_card.show_input) {
carousel.scroll_to (_user_card);
_user_card.grab_focus ();
}
});
user_card.start_authentication.connect (do_connect_username);
user_card.provide_credential.connect (do_connect);
user_card.click_gesture.pressed.connect ((gesture, n_press, x, y) => carousel.scroll_to (gesture.widget));
user_card.go_left.connect (() => {
if (Gtk.StateFlags.DIR_LTR in get_state_flags ()) {
go_previous ();
Expand All @@ -434,51 +411,35 @@ public class Greeter.MainWindow : Gtk.ApplicationWindow {
}

private void handle_page_changed (uint index) {
if (index == current_user_card_index) {
return;
}
cancel_authentication ();

unowned var user_card = user_cards.peek_nth (index);
if (user_card == null) {
return;
}

if (current_card != null && current_card is UserCard) {
((UserCard) current_card).show_input = false;
}
current_card?.on_deselected ();

current_user_card_index = (int) index;
current_card = user_card;

datetime_widget.is_24h = user_card.is_24h;

user_card.set_settings ();
user_card.show_input = true;
user_card.grab_focus ();
user_card.on_selected ();
}

private void cancel_authentication () {
if (lightdm_greeter.in_authentication) {
try {
lightdm_greeter.cancel_authentication ();
} catch (Error e) {
critical (e.message);
}
}

try {
lightdm_greeter.authenticate (user_card.user.user_name);
} catch (Error e) {
critical (e.message);
}
}

private void do_connect_username (string username) {
if (lightdm_greeter.in_authentication) {
try {
lightdm_greeter.cancel_authentication ();
} catch (Error e) {
critical (e.message);
}
}
cancel_authentication ();

try {
lightdm_greeter.authenticate (username);
Expand All @@ -487,17 +448,14 @@ public class Greeter.MainWindow : Gtk.ApplicationWindow {
}
}

private void do_connect (string? credential) {
if (credential != null) {
try {
lightdm_greeter.respond (credential);
} catch (Error e) {
critical (e.message);
}
private void do_connect (string credential) {
try {
lightdm_greeter.respond (credential);
} catch (Error e) {
critical (e.message);
}

carousel.interactive = false;
carousel.scroll_to (current_card);
}

private void go_previous () {
Expand Down