From 46a30614c3aba5468e6f63ec0c0aad1bd7a30c09 Mon Sep 17 00:00:00 2001 From: Zoey Ahmed Date: Mon, 29 Dec 2025 16:19:51 +0000 Subject: [PATCH] gamepad: Select collection on activate btn pressed --- cartridges/gamepads.py | 6 ++++++ cartridges/ui/window.py | 24 +++++++++++++++--------- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/cartridges/gamepads.py b/cartridges/gamepads.py index 76f462b..2e14eca 100644 --- a/cartridges/gamepads.py +++ b/cartridges/gamepads.py @@ -112,6 +112,12 @@ class Gamepad(GObject.Object): focus_widget.activate() return + if self._is_focused_on_sidebar(): + self.window.navigate_sidebar( + self.window.sidebar, item=self.window.sidebar.get_selected_item() + ) + return + self.window.grid.activate_action( "list.activate-item", GLib.Variant.new_uint32(self._get_current_position()), diff --git a/cartridges/ui/window.py b/cartridges/ui/window.py index 9dc6a7e..e4b8401 100644 --- a/cartridges/ui/window.py +++ b/cartridges/ui/window.py @@ -164,15 +164,12 @@ class Window(Adw.ApplicationWindow): self.toast_overlay.add_toast(toast) - @Gtk.Template.Callback() - def _show_sidebar_title(self, _obj, layout: str) -> bool: - right_window_controls = layout.replace("appmenu", "").startswith(":") - return right_window_controls and not sys.platform.startswith("darwin") - - @Gtk.Template.Callback() - def _navigate(self, sidebar: Adw.Sidebar, index: int): # pyright: ignore[reportAttributeAccessIssue] - item = sidebar.get_item(index) + def navigate_sidebar(self, sidebar: Adw.Sidebar, item: Adw.SidebarItem): # pyright: ignore[reportAttributeAccessIssue] + """Select given item in the sidebar. + Item should correspond to a collection, or the all game category/ + new collection buttons. + """ match item: case self.new_collection_item: self._add_collection() @@ -183,11 +180,20 @@ class Window(Adw.ApplicationWindow): self.collection = None if item is not self.new_collection_item: - self._selected_sidebar_item = index + self._selected_sidebar_item = sidebar.props.selected if self.split_view.props.collapsed: self.split_view.props.show_sidebar = False + @Gtk.Template.Callback() + def _show_sidebar_title(self, _obj, layout: str) -> bool: + right_window_controls = layout.replace("appmenu", "").startswith(":") + return right_window_controls and not sys.platform.startswith("darwin") + + @Gtk.Template.Callback() + def _navigate(self, sidebar: Adw.Sidebar, index: int): # pyright: ignore[reportAttributeAccessIssue] + self.navigate_sidebar(sidebar, sidebar.get_item(index)) + @Gtk.Template.Callback() def _update_selection(self, sidebar: Adw.Sidebar, *_args): # pyright: ignore[reportAttributeAccessIssue] if sidebar.props.selected_item is self.new_collection_item: