running 'thg' from the command line does not focus existing workbench window on different monitor
Created originally on Bitbucket by cbillington (Chris Billington)
In Ubuntu 17.10, running gnome-shell, tested under both X and Wayland.
In the specific case where an existing workbench window is already on top (out of the windows on the monitor it is on), it does not get focus if you run 'thg' when a window on a different monitor has focus.
Steps to reproduce:
Run 'thg' from gnome-terminal in a directory that is a hg repo. run 'thg' again from gnome-terminal in the same directory, but this time with gnome-terminal on a separate monitor.
Result: the terminal stays focused, instead of thg workbench
Expected: thg workbench should gain focus.
In all other cases (workbench is not on top on the monitor it is on, or is minimised, or is on the same monitor as the terminal running the second 'thg' command), the workbench correctly gains focus.
I have tried to narrow this bug down and suspect tortoisehg, since there are other things it could be. Other apps that focus existing windows when you launch them, such as sublime text, do not exhibit this behaviour on my setup, so I think I have ruled out it being the window manager's fault.
The below minimal PyQt application, if you drag the window to a different monitor and move focus back to the first monitor, successfully can grab focus again using the same series of method calls, ending in
activateWindow(), as used by tortoisehg (
_handleNewConnection). Python 2, 3, PyQt4, PyQt5, same behaviour in all cases. So I think I have ruled it out being Qt's fault, but there must be some difference between how this test case and Tortoisehg are using Qt (even though this part is the same method calls) since there is a difference in behaviour.
This is not the worst bug ever, but I have keyboard shortcuts to launch tortoisehg and it's surprising when that doesn't have the effect of focusing the existing window.
#!python import sys from PyQt4.QtGui import QApplication, QMainWindow from PyQt4.QtCore import QTimer, Qt # from PyQt5.QtWidgets import QApplication, QMainWindow # from PyQt4.QtCore import QTimer, Qt app = QApplication(sys.argv) wb = QMainWindow() wb.setWindowTitle('Main window') wb.resize(400, 400) wb.show() def timeout(): wb.setWindowState(wb.windowState() & ~Qt.WindowMinimized | Qt.WindowActive) wb.show() wb.raise_() wb.activateWindow() wb.activateWindow() timer = QTimer() timer.timeout.connect(timeout) timer.start(5000) app.exec_()