diff --git a/qutebrowser/config/configdata.py b/qutebrowser/config/configdata.py index 11ebe5415..8d003a182 100644 --- a/qutebrowser/config/configdata.py +++ b/qutebrowser/config/configdata.py @@ -227,6 +227,16 @@ def data(readonly=False): "How to open links in an existing instance if a new one is " "launched."), + ('new-instance-open-target.window', + SettingValue(typ.String( + valid_values=typ.ValidValues( + ('last-opened', "Open new tabs in the last" + "opened window."), + ('last-focused', "Open new tabs in the most" + "recently focused window.") + )), 'last-focused'), + "Which window to choose when opening links as new tabs."), + ('log-javascript-console', SettingValue(typ.String( valid_values=typ.ValidValues( diff --git a/qutebrowser/mainwindow/mainwindow.py b/qutebrowser/mainwindow/mainwindow.py index b44a5b782..a53c4f702 100644 --- a/qutebrowser/mainwindow/mainwindow.py +++ b/qutebrowser/mainwindow/mainwindow.py @@ -69,7 +69,11 @@ def get_window(via_ipc, force_window=False, force_tab=False, window_to_raise = window else: try: - window = objreg.last_window() + win_mode = config.get('general', 'new-instance-open-target.window') + if win_mode == 'last-focused': + window = objreg.last_focused_window() + elif win_mode == 'last-opened': + window = objreg.last_window() except objreg.NoWindow: # There is no window left, so we open a new one window = MainWindow() diff --git a/qutebrowser/utils/objreg.py b/qutebrowser/utils/objreg.py index 0dc6ec68c..d347b7756 100644 --- a/qutebrowser/utils/objreg.py +++ b/qutebrowser/utils/objreg.py @@ -178,10 +178,7 @@ def _get_window_registry(window): app = get('app') win = app.activeWindow() elif window == 'last-focused': - try: - win = get('last-focused-main-window') - except KeyError: - win = last_window() + win = last_focused_window() else: win = window_registry[window] except (KeyError, NoWindow): @@ -276,6 +273,14 @@ def dump_objects(): return lines +def last_focused_window(): + """Get the last focused window, or the last window if none.""" + try: + return get('last-focused-main-window') + except KeyError: + return last_window() + + def last_window(): """Get the last opened window object.""" if not window_registry: diff --git a/tests/end2end/fixtures/quteprocess.py b/tests/end2end/fixtures/quteprocess.py index 493b3fb6c..b379b42a5 100644 --- a/tests/end2end/fixtures/quteprocess.py +++ b/tests/end2end/fixtures/quteprocess.py @@ -330,6 +330,7 @@ class QuteProc(testprocess.Process): settings = [ ('ui', 'message-timeout', '0'), ('general', 'auto-save-interval', '0'), + ('general', 'new-instance-open-target.window', 'last-opened') ] if not self._webengine: settings.append(('network', 'ssl-strict', 'false'))