gamepad: Implement return button action for sidebar

This commit is contained in:
Zoey Ahmed
2025-12-29 13:00:41 +00:00
parent b6d73e0efe
commit afa9b4ca84
3 changed files with 18 additions and 2 deletions

View File

@@ -136,7 +136,22 @@ class Gamepad(GObject.Object):
open_menu.grab_focus()
return
self.window.grid.grab_focus()
grid_visible = self.window.view_stack.props.visible_child_name == "grid"
if self._is_focused_on_top_bar():
focus_widget = self.window.grid if grid_visible else self.window.sidebar
# If the grid is not visible (i.e no search results or imports)
# the searchbar is focused as a fallback.
elif self._is_focused_on_sidebar():
focus_widget = (
self.window.grid if grid_visible else self.window.search_entry
)
else:
focus_widget = (
self.window.sidebar if grid_visible else self.window.search_entry
)
focus_widget.grab_focus()
self.window.props.focus_visible = True
def _navigate_to_game_position(self, new_pos: int):

View File

@@ -208,7 +208,7 @@ template $Window: Adw.ApplicationWindow {
}
content: Adw.ToastOverlay toast_overlay {
child: Adw.ViewStack {
child: Adw.ViewStack view_stack {
visible-child-name: bind $_if_else(
grid.model as <NoSelection>.n-items,
"grid",

View File

@@ -56,6 +56,7 @@ class Window(Adw.ApplicationWindow):
sort_button: Gtk.MenuButton = Gtk.Template.Child()
main_menu_button: Gtk.MenuButton = Gtk.Template.Child()
toast_overlay: Adw.ToastOverlay = Gtk.Template.Child()
view_stack: Adw.ViewStack = Gtk.Template.Child()
grid: Gtk.GridView = Gtk.Template.Child()
sorter: GameSorter = Gtk.Template.Child()
collection_filter: CollectionFilter = Gtk.Template.Child()