[gnome-music/wip/jfelder/gtk4-v3: 3/3] searchheaderbar: Ensure that the entry gets the first key press
- From: Jean Felder <jfelder src gnome org>
- To: commits-list gnome org
- Cc: 
- Subject: [gnome-music/wip/jfelder/gtk4-v3: 3/3] searchheaderbar: Ensure that the entry gets the first key press
- Date: Fri, 11 Feb 2022 20:28:18 +0000 (UTC)
commit 738014b77ef84278b535d6a9e0ca2109161eb578
Author: Jean Felder <jfelder src gnome org>
Date:   Fri Feb 11 21:16:33 2022 +0100
    searchheaderbar: Ensure that the entry gets the first key press
 gnomemusic/widgets/searchheaderbar.py | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
---
diff --git a/gnomemusic/widgets/searchheaderbar.py b/gnomemusic/widgets/searchheaderbar.py
index 0e539e0eb..5194cb64a 100644
--- a/gnomemusic/widgets/searchheaderbar.py
+++ b/gnomemusic/widgets/searchheaderbar.py
@@ -22,12 +22,17 @@
 # code, but you are not obligated to do so.  If you do not wish to do so,
 # delete this exception statement from your version.
 
+from __future__ import annotations
+
 from enum import IntEnum
+import typing
 
 from gi.repository import Adw, GObject, Gtk
 
 from gnomemusic.search import Search
 from gnomemusic.widgets.headerbar import HeaderBar, SelectionBarMenuButton
+if typing.TYPE_CHECKING:
+    from gnomemusic.application import Application
 
 
 @Gtk.Template(resource_path="/org/gnome/Music/ui/SearchHeaderBar.ui")
@@ -101,6 +106,16 @@ class SearchHeaderBar(Adw.Bin):
 
         self._entry.connect("search-changed", self._search_entry_changed)
 
+        self._win_id = application.connect(
+            "notify::window", self._on_window_ready)
+
+    def _on_window_ready(
+            self, application: Application,
+            value: GObject.ParamSpecObject) -> None:
+        self._entry.set_key_capture_widget(application.props.window)
+        application.disconnect(self._win_id)
+        self._win_id = 0
+
     @GObject.Property(type=bool, default=False)
     def selection_mode(self):
         """Selection mode
[
Date Prev][
Date Next]   [
Thread Prev][
Thread Next]   
[
Thread Index]
[
Date Index]
[
Author Index]