about summary refs log tree commit diff
diff options
context:
space:
mode:
authorSören Tempel <soeren+git@soeren-tempel.net>2021-05-30 10:59:21 +0200
committerSören Tempel <soeren+git@soeren-tempel.net>2021-05-30 10:59:21 +0200
commit6a9136beee57534022f46ff5586bd21288688066 (patch)
tree9590d70dc778958c5ae1859ba9f930b06c546289
parent30969bb6e6170dacf8cb3f54657801492a42640e (diff)
terminal: Restore focus to TermView after closing SearchBar
-rw-r--r--saneterm/terminal.py9
1 files changed, 9 insertions, 0 deletions
diff --git a/saneterm/terminal.py b/saneterm/terminal.py
index c25f596..9a254c1 100644
--- a/saneterm/terminal.py
+++ b/saneterm/terminal.py
@@ -82,6 +82,7 @@ class Terminal(Gtk.Window):
 
         self.connect("configure-event", self.update_size)
         self.connect("destroy", self.destroy)
+        self.connect_after("set-focus", self.focus)
 
         bindings = keys.Bindings(self.termview)
         for key, idx in keys.CTRL.items():
@@ -109,6 +110,14 @@ class Terminal(Gtk.Window):
                 (GObject.TYPE_LONG,))
         self.termview.connect("history-entry", self.history)
 
+    def focus(self, window, widget):
+        # If no widget is focused, focus the termview by default.
+        # This occurs, for instance, after closing the SearchBar.
+        #
+        # XXX: Is there a better way to do this?
+        if widget is None:
+            self.emit("set-focus", self.termview)
+
     def destroy(self, widget):
         self.hist.close()