From e23360bb88e5d6c1c2c20d187965a8eec3520926 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Tue, 11 Nov 2014 22:42:45 +0100 Subject: [PATCH] Don't open a new window if only commands are sent via IPC. Fixes #237. --- qutebrowser/app.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/qutebrowser/app.py b/qutebrowser/app.py index d00449be5..a570e854a 100644 --- a/qutebrowser/app.py +++ b/qutebrowser/app.py @@ -210,19 +210,23 @@ class Application(QApplication): self._open_startpage() self._open_quickstart() - def _get_window(self, via_ipc, args_empty): + def _get_window(self, via_ipc, force_window=False, force_tab=False): """Helper function for process_args to get a window id. Args: via_ipc: Whether the request was made via IPC. - args_empty: Whether there are no arguments. + force_window: Whether to force opening in a window. + force_tab: Whether to force opening in a tab. """ + if force_window and force_tab: + raise ValueError("force_window and force_tab are mutually " + "exclusive!") if not via_ipc: # Initial main window return 0 window_to_raise = None open_target = config.get('general', 'new-instance-open-target') - if open_target == 'window' or args_empty: + if (open_target == 'window' or force_window) and not force_tab: win_id = mainwindow.MainWindow.spawn() window = objreg.get('main-window', scope='window', window=win_id) window_to_raise = window @@ -256,18 +260,23 @@ class Application(QApplication): args: A list of arguments to process. via_ipc: Whether the arguments were transmitted over IPC. """ - win_id = self._get_window(via_ipc, not args) if ipc and not args: + win_id = self._get_window(via_ipc, force_window=True) self._open_startpage(win_id) + return + win_id = None for cmd in args: if cmd.startswith(':'): + if win_id is None: + win_id = self._get_window(via_ipc, force_tab=True) log.init.debug("Startup cmd {}".format(cmd)) commandrunner = runners.CommandRunner(win_id) commandrunner.run_safely_init(cmd.lstrip(':')) elif not cmd: log.init.debug("Empty argument") - win_id = mainwindow.MainWindow.spawn() + win_id = self._get_window(via_ipc, force_window=True) else: + win_id = self._get_window(via_ipc) tabbed_browser = objreg.get('tabbed-browser', scope='window', window=win_id) log.init.debug("Startup URL {}".format(cmd)) @@ -743,7 +752,7 @@ class Application(QApplication): @pyqtSlot(QUrl) def open_desktopservices_url(self, url): """Handler to open an URL via QDesktopServices.""" - win_id = self._get_window(True, False) + win_id = self._get_window(via_ipc=True, force_window=False) tabbed_browser = objreg.get('tabbed-browser', scope='window', window=win_id) tabbed_browser.tabopen(url)