From 1b2ab928f0943fd046aafc7fbea7900d9c8cdf85 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Philipp=20H=C3=B6rist?= <forenjunkie@chello.at>
Date: Tue, 26 Dec 2017 21:55:06 +0100
Subject: [PATCH] Fix focus after destruction of StartChatDialog

On destroy() the window that was last focused gets the focus
again. if destroy() is called from the StartChat Dialog, the new
ChatControl is not yet focused, because present() seems to be asynchron,
at least on KDE, and takes time.
---
 gajim/dialogs.py        | 3 ++-
 gajim/message_window.py | 8 ++++++++
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/gajim/dialogs.py b/gajim/dialogs.py
index a0d2a27d79..e89a466287 100644
--- a/gajim/dialogs.py
+++ b/gajim/dialogs.py
@@ -2776,6 +2776,7 @@ class StartChatDialog(Gtk.ApplicationWindow):
         self.set_show_menubar(False)
         self.set_title(_('Start new Conversation'))
         self.set_default_size(-1, 400)
+        self.ready_to_destroy = False
 
         self.builder = gtkgui_helpers.get_gtk_builder(
             'start_chat_dialog.ui')
@@ -2891,7 +2892,7 @@ class StartChatDialog(Gtk.ApplicationWindow):
         else:
             app.interface.new_chat_from_jid(row.account, row.jid)
 
-        self.destroy()
+        self.ready_to_destroy = True
 
     def _on_search_changed(self, entry):
         search_text = entry.get_text()
diff --git a/gajim/message_window.py b/gajim/message_window.py
index c043a05c09..6a13b57bf4 100644
--- a/gajim/message_window.py
+++ b/gajim/message_window.py
@@ -204,6 +204,14 @@ class MessageWindow(object):
         gtkgui_helpers.resize_window(self.window, width, height)
 
     def _on_window_focus(self, widget, event):
+        # on destroy() the window that was last focused gets the focus
+        # again. if destroy() is called from the StartChat Dialog, this
+        # Window is not yet focused, because present() seems to be asynchron
+        # at least on KDE, and takes time.
+        if 'start_chat' in app.interface.instances:
+            if app.interface.instances['start_chat'].ready_to_destroy:
+                app.interface.instances['start_chat'].destroy()
+
         # window received focus, so if we had urgency REMOVE IT
         # NOTE: we do not have to read the message (it maybe in a bg tab)
         # to remove urgency hint so this functions does that
-- 
GitLab