From 23de7d533136107d114928096e25fb48fff5d7c7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Philipp=20H=C3=B6rist?= <forenjunkie@chello.at>
Date: Tue, 26 Dec 2017 21:43:33 +0100
Subject: [PATCH] Use higher level API to focus windows

set_active_tab() already calls present(), no need to call it afterwards
again
---
 gajim/gui_interface.py        |  3 +--
 gajim/remote_control.py       | 10 +++++-----
 gajim/roster_window.py        |  2 --
 plugins/dbus_plugin/plugin.py |  6 +++---
 4 files changed, 9 insertions(+), 12 deletions(-)

diff --git a/gajim/gui_interface.py b/gajim/gui_interface.py
index 71f849c797..23c56298e4 100644
--- a/gajim/gui_interface.py
+++ b/gajim/gui_interface.py
@@ -1767,7 +1767,7 @@ class Interface:
             self.roster.draw_contact(jid, account)
         if w:
             w.set_active_tab(ctrl)
-            w.window.get_window().focus(Gtk.get_current_event_time())
+            w.window.present()
             # Using isinstance here because we want to catch all derived types
             if isinstance(ctrl, ChatControlBase):
                 tv = ctrl.conv_textview
@@ -2145,7 +2145,6 @@ class Interface:
         # For JEP-0172
         if added_to_roster:
             ctrl.user_nick = app.nicks[account]
-        GLib.idle_add(mw.window.grab_focus)
 
         return ctrl
 
diff --git a/gajim/remote_control.py b/gajim/remote_control.py
index b1eff73508..de4d049796 100644
--- a/gajim/remote_control.py
+++ b/gajim/remote_control.py
@@ -519,7 +519,7 @@ class SignalObject(dbus.service.Object):
             win = app.interface.msg_win_mgr.get_window(jid,
                     connected_account).window
             if win.get_property('visible'):
-                win.window.focus(Gtk.get_current_event_time())
+                win.window.present()
             return DBUS_BOOLEAN(True)
         return DBUS_BOOLEAN(False)
 
@@ -658,9 +658,9 @@ class SignalObject(dbus.service.Object):
             win.present()
             # preserve the 'steal focus preservation'
             if self._is_first():
-                win.window.focus(Gtk.get_current_event_time())
+                win.window.present()
             else:
-                win.window.focus(int(time()))
+                win.window.present_with_time(int(time()))
 
     @dbus.service.method(INTERFACE, in_signature='', out_signature='')
     def show_roster(self):
@@ -671,9 +671,9 @@ class SignalObject(dbus.service.Object):
         win.present()
         # preserve the 'steal focus preservation'
         if self._is_first():
-            win.window.focus(Gtk.get_current_event_time())
+            win.window.present()
         else:
-            win.window.focus(int(time()))
+            win.window.present_with_time(int(time()))
 
     @dbus.service.method(INTERFACE, in_signature='', out_signature='')
     def toggle_ipython(self):
diff --git a/gajim/roster_window.py b/gajim/roster_window.py
index 7edaa55ab0..dffc7d378f 100644
--- a/gajim/roster_window.py
+++ b/gajim/roster_window.py
@@ -3131,7 +3131,6 @@ class RosterWindow:
             if gc_control:
                 mw = app.interface.msg_win_mgr.get_window(jid, account)
                 mw.set_active_tab(gc_control)
-                mw.window.get_window().focus(Gtk.get_current_event_time())
             return
         ctrl = app.interface.minimized_controls[account][jid]
         mw = app.interface.msg_win_mgr.get_window(jid, account)
@@ -3145,7 +3144,6 @@ class RosterWindow:
         ctrl.on_groupchat_maximize()
         mw.new_tab(ctrl)
         mw.set_active_tab(ctrl)
-        mw.window.get_window().focus(Gtk.get_current_event_time())
         self.remove_groupchat(jid, account)
 
     def on_edit_account(self, widget, account):
diff --git a/plugins/dbus_plugin/plugin.py b/plugins/dbus_plugin/plugin.py
index 5c86cfb38b..2d20301a24 100644
--- a/plugins/dbus_plugin/plugin.py
+++ b/plugins/dbus_plugin/plugin.py
@@ -367,7 +367,7 @@ if dbus_support.supported:
                     win = gajim.interface.msg_win_mgr.get_window(jid,
                             connected_account).window
                     if win.get_property('visible'):
-                        win.window.focus()
+                        win.window.present()
                     return DBUS_BOOLEAN(True)
                 return DBUS_BOOLEAN(False)
 
@@ -455,9 +455,9 @@ if dbus_support.supported:
                     win.present()
                     # preserve the 'steal focus preservation'
                     if self._is_first():
-                        win.window.focus()
+                        win.window.present()
                     else:
-                        win.window.focus(long(time()))
+                        win.window.present_with_time(long(time()))
 
             @dbus.service.method(INTERFACE, in_signature='', out_signature='')
             def toggle_ipython(self):
-- 
GitLab