Browse Source

session-view: Fix focus behavior when selected item in sidebar changed

Make sure to always focus a widget in the visible page if possible.
af/unable-to-decryt-styling
Kévin Commaille 12 months ago
parent
commit
ed66251c10
No known key found for this signature in database
GPG Key ID: C971D9DBC9D678D
  1. 9
      src/session/view/content/explore/mod.rs
  2. 7
      src/session/view/content/invite.rs
  3. 4
      src/session/view/content/mod.rs
  4. 18
      src/session/view/content/room_history/message_toolbar/mod.rs
  5. 19
      src/session/view/content/room_history/mod.rs
  6. 2
      src/session/view/content/room_history/mod.ui
  7. 7
      src/session/view/content/room_history/title.rs
  8. 7
      src/session/view/session_view.rs
  9. 14
      src/session/view/sidebar/mod.rs
  10. 2
      src/session/view/sidebar/mod.ui

9
src/session/view/content/explore/mod.rs

@ -108,7 +108,12 @@ mod imp {
}
}
impl WidgetImpl for Explore {}
impl WidgetImpl for Explore {
fn grab_focus(&self) -> bool {
self.search_entry.grab_focus()
}
}
impl BinImpl for Explore {}
impl Explore {
@ -173,8 +178,6 @@ impl Explore {
if let Some(public_room_list) = &*imp.public_room_list.borrow() {
public_room_list.init();
}
self.imp().search_entry.grab_focus();
}
/// The header bar of the explorer.

7
src/session/view/content/invite.rs

@ -113,7 +113,12 @@ mod imp {
}
}
impl WidgetImpl for Invite {}
impl WidgetImpl for Invite {
fn grab_focus(&self) -> bool {
self.accept_button.grab_focus()
}
}
impl BinImpl for Invite {}
impl Invite {

4
src/session/view/content/mod.rs

@ -208,6 +208,10 @@ mod imp {
self.update_visible_child();
self.obj().notify_item();
if let Some(page) = self.stack.visible_child() {
page.grab_focus();
}
}
/// Update the visible child according to the current item.

18
src/session/view/content/room_history/message_toolbar/mod.rs

@ -74,7 +74,7 @@ mod imp {
#[template_child]
main_stack: TemplateChild<gtk::Stack>,
#[template_child]
message_entry: TemplateChild<sourceview::View>,
pub(super) message_entry: TemplateChild<sourceview::View>,
#[template_child]
send_button: TemplateChild<gtk::Button>,
#[template_child]
@ -163,7 +163,20 @@ mod imp {
}
}
impl WidgetImpl for MessageToolbar {}
impl WidgetImpl for MessageToolbar {
fn grab_focus(&self) -> bool {
if self
.main_stack
.visible_child_name()
.is_none_or(|name| name == "disabled")
{
return false;
}
self.message_entry.grab_focus()
}
}
impl BinImpl for MessageToolbar {}
#[gtk::template_callbacks]
@ -201,7 +214,6 @@ mod imp {
self.timeline.set(timeline);
self.send_message_permission_updated();
self.message_entry.grab_focus();
obj.notify_timeline();
self.update_current_composer_state(old_timeline);

19
src/session/view/content/room_history/mod.rs

@ -63,6 +63,8 @@ mod imp {
#[template_child]
pub(super) header_bar: TemplateChild<adw::HeaderBar>,
#[template_child]
room_title: TemplateChild<RoomHistoryTitle>,
#[template_child]
room_menu: TemplateChild<gtk::MenuButton>,
#[template_child]
listview: TemplateChild<gtk::ListView>,
@ -122,7 +124,6 @@ mod imp {
type ParentType = adw::Bin;
fn class_init(klass: &mut Self::Class) {
RoomHistoryTitle::ensure_type();
ItemRow::ensure_type();
VerificationInfoBar::ensure_type();
@ -237,7 +238,16 @@ mod imp {
}
}
impl WidgetImpl for RoomHistory {}
impl WidgetImpl for RoomHistory {
fn grab_focus(&self) -> bool {
if self.message_toolbar.grab_focus() {
true
} else {
self.room_title.grab_focus()
}
}
}
impl BinImpl for RoomHistory {}
#[gtk::template_callbacks]
@ -477,8 +487,7 @@ mod imp {
self.update_tombstoned_banner();
self.update_invite_action();
let obj = self.obj();
obj.notify_timeline();
self.obj().notify_timeline();
}
/// The room of the current timeline, if any.
@ -1034,7 +1043,7 @@ impl RoomHistory {
}
/// The message toolbar of the room history.
fn message_toolbar(&self) -> &MessageToolbar {
pub(super) fn message_toolbar(&self) -> &MessageToolbar {
&self.imp().message_toolbar
}

2
src/session/view/content/room_history/mod.ui

@ -135,7 +135,7 @@
<object class="AdwHeaderBar" id="header_bar">
<property name="centering-policy">strict</property>
<child type="title">
<object class="RoomHistoryTitle">
<object class="RoomHistoryTitle" id="room_title">
<binding name="room">
<lookup name="room">
<lookup name="timeline">ContentRoomHistory</lookup>

7
src/session/view/content/room_history/title.rs

@ -49,7 +49,12 @@ mod imp {
#[glib::derived_properties]
impl ObjectImpl for RoomHistoryTitle {}
impl WidgetImpl for RoomHistoryTitle {}
impl WidgetImpl for RoomHistoryTitle {
fn grab_focus(&self) -> bool {
self.button.grab_focus()
}
}
impl BinImpl for RoomHistoryTitle {}
impl RoomHistoryTitle {

7
src/session/view/session_view.rs

@ -197,6 +197,13 @@ mod imp {
.list_model()
.is_some_and(|m| m.selection_model().selected_item().is_some());
imp.split_view.set_show_content(show_content);
// Only grab focus for the sidebar here. We handle the other case in
// `Content::set_item()` directly, because we need to grab focus only
// after the visible content changed.
if !show_content {
imp.sidebar.grab_focus();
}
}
),
);

14
src/session/view/sidebar/mod.rs

@ -45,6 +45,8 @@ mod imp {
#[template_child]
pub(super) header_bar: TemplateChild<adw::HeaderBar>,
#[template_child]
account_switcher_button: TemplateChild<AccountSwitcherButton>,
#[template_child]
security_banner: TemplateChild<adw::Banner>,
#[template_child]
scrolled_window: TemplateChild<gtk::ScrolledWindow>,
@ -79,7 +81,6 @@ mod imp {
type ParentType = adw::NavigationPage;
fn class_init(klass: &mut Self::Class) {
AccountSwitcherButton::ensure_type();
OfflineBanner::ensure_type();
Self::bind_template(klass);
@ -171,7 +172,16 @@ mod imp {
}
}
impl WidgetImpl for Sidebar {}
impl WidgetImpl for Sidebar {
fn grab_focus(&self) -> bool {
if self.listview.grab_focus() {
true
} else {
self.account_switcher_button.grab_focus()
}
}
}
impl NavigationPageImpl for Sidebar {}
#[gtk::template_callbacks]

2
src/session/view/sidebar/mod.ui

@ -99,7 +99,7 @@
<object class="AdwHeaderBar" id="header_bar">
<property name="show-title">False</property>
<child type="start">
<object class="AccountSwitcherButton">
<object class="AccountSwitcherButton" id="account_switcher_button">
<property name="valign">center</property>
</object>
</child>

Loading…
Cancel
Save