Skip to content

Commit b883c45

Browse files
lenemterdanirabbit
andauthored
Fix card switching (#832)
Co-authored-by: Danielle Foré <danielle@elementary.io>
1 parent fdec4bb commit b883c45

2 files changed

Lines changed: 24 additions & 30 deletions

File tree

src/Cards/UserCard.vala

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@
88
public class Greeter.UserCard : Greeter.BaseCard {
99
public signal void go_left ();
1010
public signal void go_right ();
11-
public signal void focus_requested ();
1211

1312
public LightDM.User lightdm_user { get; construct; }
1413
public bool show_input { get; set; default = false; }
1514
public bool is_24h { get; set; default = true; }
15+
// TODO: In Gtk4 remove this gesture and move it to MainWindow
16+
public Gtk.GestureMultiPress click_gesture { get; private set; }
1617

1718
private Act.User act_user;
1819
private Pantheon.AccountsService greeter_act;
1920
private Pantheon.SettingsDaemon.AccountsService settings_act;
2021

21-
private Gtk.GestureMultiPress click_gesture;
2222
private Gtk.Revealer form_revealer;
2323
private Gtk.Stack login_stack;
2424
private Greeter.PasswordEntry password_entry;
@@ -202,12 +202,6 @@ public class Greeter.UserCard : Greeter.BaseCard {
202202
});
203203

204204
click_gesture = new Gtk.GestureMultiPress (this);
205-
click_gesture.pressed.connect ((n_press, x, y) => {
206-
if (!show_input) {
207-
focus_requested ();
208-
password_entry.grab_focus ();
209-
}
210-
});
211205

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

src/MainWindow.vala

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class Greeter.MainWindow : Gtk.ApplicationWindow {
1818
private Greeter.DateTimeWidget datetime_widget;
1919
private unowned LightDM.UserList lightdm_user_list;
2020

21-
private int current_user_card_index = 0;
21+
private int current_user_card_index = -1;
2222
private unowned Greeter.BaseCard? current_card = null;
2323

2424
private bool installer_mode = false;
@@ -180,13 +180,7 @@ public class Greeter.MainWindow : Gtk.ApplicationWindow {
180180
return Gdk.EVENT_PROPAGATE;
181181
});
182182

183-
carousel.page_changed.connect ((index) => {
184-
var children = carousel.get_children ();
185-
186-
if (children.nth_data (index) is Greeter.UserCard) {
187-
current_user_card_index = (int) index;
188-
}
189-
});
183+
carousel.page_changed.connect (handle_page_changed);
190184

191185
load_users.begin (() => {
192186
/* A significant delay is required in order for the window and card to be focused at
@@ -367,15 +361,15 @@ public class Greeter.MainWindow : Gtk.ApplicationWindow {
367361
bool user_selected = false;
368362
user_cards.head.foreach ((card) => {
369363
if (card.lightdm_user.name == user_to_select) {
370-
switch_to_card (card);
364+
carousel.scroll_to (card);
371365
user_selected = true;
372366
}
373367
});
374368

375369
if (!user_selected) {
376370
unowned var user_card = user_cards.peek_head ();
377371
user_card.show_input = true;
378-
switch_to_card (user_card);
372+
carousel.scroll_to (user_card);
379373
}
380374
} else {
381375
datetime_revealer.reveal_child = false;
@@ -408,21 +402,23 @@ public class Greeter.MainWindow : Gtk.ApplicationWindow {
408402
private void add_card (LightDM.User lightdm_user) {
409403
var user_card = new Greeter.UserCard (lightdm_user);
410404
user_card.show_all ();
405+
user_card.do_connect.connect (do_connect);
406+
user_card.click_gesture.pressed.connect ((gesture, n_press, x, y) => {
407+
assert (gesture.widget is UserCard);
411408

412-
carousel.add (user_card);
413-
414-
user_card.focus_requested.connect (() => {
415-
switch_to_card (user_card);
409+
var _user_card = (UserCard) gesture.widget;
410+
if (!_user_card.show_input) {
411+
carousel.scroll_to (_user_card);
412+
_user_card.grab_focus ();
413+
}
416414
});
417-
418415
user_card.go_left.connect (() => {
419416
if (Gtk.StateFlags.DIR_LTR in get_state_flags ()) {
420417
go_previous ();
421418
} else {
422419
go_next ();
423420
}
424421
});
425-
426422
user_card.go_right.connect (() => {
427423
if (Gtk.StateFlags.DIR_LTR in get_state_flags ()) {
428424
go_next ();
@@ -431,26 +427,30 @@ public class Greeter.MainWindow : Gtk.ApplicationWindow {
431427
}
432428
});
433429

434-
user_card.do_connect.connect (do_connect);
430+
carousel.add (user_card);
435431

436432
card_size_group.add_widget (user_card);
437433
user_cards.push_tail (user_card);
438434
}
439435

440-
private void switch_to_card (Greeter.UserCard user_card) {
441-
if (!carousel.interactive) {
436+
private void handle_page_changed (uint index) {
437+
if (index == current_user_card_index) {
438+
return;
439+
}
440+
441+
unowned var user_card = user_cards.peek_nth (index);
442+
if (user_card == null) {
442443
return;
443444
}
444445

445446
if (current_card != null && current_card is UserCard) {
446447
((UserCard) current_card).show_input = false;
447448
}
448449

449-
datetime_widget.is_24h = user_card.is_24h;
450-
450+
current_user_card_index = (int) index;
451451
current_card = user_card;
452452

453-
carousel.scroll_to (user_card);
453+
datetime_widget.is_24h = user_card.is_24h;
454454

455455
user_card.set_settings ();
456456
user_card.show_input = true;

0 commit comments

Comments
 (0)