Browse Source

login: use default widget for logging on enter press

Expose the login button in login.ui to retrieve it by the default_widget function in login.
Set the login  button as the default widget when the visible child in main_stack is login,
and connect the function to the visible_child change signal to update the default widget.

fix: https://gitlab.gnome.org/GNOME/fractal/-/issues/788
merge-requests/1327/merge
giusdp 5 years ago committed by Julian Sparber
parent
commit
ca64f47c4d
  1. 2
      data/resources/ui/login.ui
  2. 6
      src/login.rs
  3. 16
      src/window.rs

2
data/resources/ui/login.ui

@ -12,7 +12,7 @@
</object>
</property>
<child type="end">
<object class="GtkButton">
<object class="GtkButton" id="next_button">
<property name="action_name">login.next</property>
<property name="child">
<object class="GtkStack" id="next_stack">

6
src/login.rs

@ -17,6 +17,8 @@ mod imp {
#[derive(Debug, Default, CompositeTemplate)]
#[template(resource = "/org/gnome/FractalNext/login.ui")]
pub struct Login {
#[template_child]
pub next_button: TemplateChild<gtk::Button>,
#[template_child]
pub next_stack: TemplateChild<gtk::Stack>,
#[template_child]
@ -186,6 +188,10 @@ impl Login {
})
.unwrap()
}
pub fn default_widget(&self) -> gtk::Widget {
imp::Login::from_instance(&self).next_button.get().upcast()
}
}
fn build_homeserver_url(server: &str) -> Result<Url, ParseError> {

16
src/window.rs

@ -65,6 +65,11 @@ mod imp {
self.login.connect_new_session(
clone!(@weak obj => move |_login, session| obj.add_session(session)),
);
self.main_stack.connect_visible_child_notify(
clone!(@weak obj => move |_| obj.set_default_by_child()),
);
obj.set_default_by_child();
}
}
@ -148,4 +153,15 @@ impl Window {
self.set_default_size(width, height);
self.set_property("maximized", &is_maximized).unwrap();
}
/// Change the default widget of the window based on the visible child
/// If the login screen is visible, its login button becomes the default widget
fn set_default_by_child(&self) {
let priv_ = imp::Window::from_instance(self);
if priv_.main_stack.visible_child() == Some(priv_.login.get().upcast()) {
self.set_default_widget(Some(&priv_.login.default_widget()));
} else {
self.set_default_widget(gtk::NONE_WIDGET);
}
}
}

Loading…
Cancel
Save