ipc: Fix opening of new empty window.

This commit is contained in:
Florian Bruhin 2014-10-14 10:10:24 +02:00
parent 2e2070ef6e
commit cfc5e80d3e

View File

@ -230,12 +230,23 @@ class Application(QApplication):
self._open_startpage() self._open_startpage()
self._open_quickstart() self._open_quickstart()
def _get_window(self, via_ipc): def _get_window(self, via_ipc, args):
"""Helper function for process_args to get a window id.""" """Helper function for process_args to get a window id.
Args:
via_ipc: Whether the request was made via IPC.
args: The argument list.
"""
if not via_ipc: if not via_ipc:
# Initial main window
return 0 return 0
window_to_raise = None
open_target = config.get('general', 'new-instance-open-target') open_target = config.get('general', 'new-instance-open-target')
if open_target in ('tab', 'tab-silent'): if open_target == 'window' or not args:
win_id = mainwindow.MainWindow.spawn()
window = objreg.get('main-window', scope='window', window=win_id)
window_to_raise = window
else:
try: try:
window = objreg.get('last-main-window') window = objreg.get('last-main-window')
except KeyError: except KeyError:
@ -243,16 +254,16 @@ class Application(QApplication):
# window. # window.
log.ipc.error("No main window found!") log.ipc.error("No main window found!")
return None return None
else: win_id = window.win_id
if open_target != 'tab-silent': if open_target != 'tab-silent':
window.setWindowState(window.windowState() & window_to_raise = window
~Qt.WindowMinimized | if window_to_raise is not None:
Qt.WindowActive) window_to_raise.setWindowState(window.windowState() &
window.raise_() ~Qt.WindowMinimized |
window.activateWindow() Qt.WindowActive)
return window.win_id window_to_raise.raise_()
else: window_to_raise.activateWindow()
return mainwindow.MainWindow.spawn() return win_id
def process_args(self, args, via_ipc=False): def process_args(self, args, via_ipc=False):
"""Process commandline args. """Process commandline args.
@ -263,9 +274,11 @@ class Application(QApplication):
args: A list of arguments to process. args: A list of arguments to process.
via_ipc: Whether the arguments were transmitted over IPC. via_ipc: Whether the arguments were transmitted over IPC.
""" """
win_id = self._get_window(via_ipc) win_id = self._get_window(via_ipc, args)
if win_id is None: if win_id is None:
return return
if ipc and not args:
self._open_startpage(win_id)
for cmd in args: for cmd in args:
if cmd.startswith(':'): if cmd.startswith(':'):
log.init.debug("Startup cmd {}".format(cmd)) log.init.debug("Startup cmd {}".format(cmd))
@ -286,11 +299,22 @@ class Application(QApplication):
else: else:
tabbed_browser.tabopen(url) tabbed_browser.tabopen(url)
def _open_startpage(self): def _open_startpage(self, win_id=None):
"""Open startpage in windows which are still empty.""" """Open startpage.
for win_id in objreg.window_registry:
The startpage is never opened if the given windows are not empty.
Args:
win_id: If None, open startpage in all empty windows.
If set, open the startpage in the given window.
"""
if win_id is not None:
window_ids = [win_id]
else:
window_ids = objreg.window_registry
for cur_win_id in window_ids:
tabbed_browser = objreg.get('tabbed-browser', scope='window', tabbed_browser = objreg.get('tabbed-browser', scope='window',
window=win_id) window=cur_win_id)
if tabbed_browser.count() == 0: if tabbed_browser.count() == 0:
log.init.debug("Opening startpage") log.init.debug("Opening startpage")
for urlstr in config.get('general', 'startpage'): for urlstr in config.get('general', 'startpage'):