@@ -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