From 6293fad2ebbb67c98180b8dd984bcff3bf26017c Mon Sep 17 00:00:00 2001 From: Niklas Haas Date: Wed, 10 Aug 2016 15:56:41 +0200 Subject: [PATCH 1/2] Add general->new-instance-open-target.window=last-visible I usually use my browser with a one-window-per-workspace flow. If I click on a URL anywhere, I personally would prefer it to go to the browser instance that's on the same workspace. To this end, the easiest way to accomplish this is to simply track when windows are made visible and register them as the last visible object. (To get finer control for when you have multiple windows on the same workspace, focus changes also update the last visible object - the implication being here that focusing something also means you're looking at it) Not all users may like this behavior, so I consider it strictly optional. --- qutebrowser/app.py | 3 +++ qutebrowser/config/configdata.py | 4 +++- qutebrowser/mainwindow/mainwindow.py | 17 +++++++++++++++++ qutebrowser/utils/objreg.py | 8 ++++++++ 4 files changed, 31 insertions(+), 1 deletion(-) diff --git a/qutebrowser/app.py b/qutebrowser/app.py index a25e3a4bb..70b256421 100644 --- a/qutebrowser/app.py +++ b/qutebrowser/app.py @@ -350,6 +350,9 @@ def on_focus_changed(_old, new): window = new.window() if isinstance(window, mainwindow.MainWindow): objreg.register('last-focused-main-window', window, update=True) + # A focused window must also be visible, and in this case we should + # consider it as the most recently looked-at window + objreg.register('last-visible-main-window', window, update=True) def open_desktopservices_url(url): diff --git a/qutebrowser/config/configdata.py b/qutebrowser/config/configdata.py index 7ed51142c..f35126b77 100644 --- a/qutebrowser/config/configdata.py +++ b/qutebrowser/config/configdata.py @@ -233,7 +233,9 @@ def data(readonly=False): ('last-opened', "Open new tabs in the last opened " "window."), ('last-focused', "Open new tabs in the most recently " - "focused window.") + "focused window."), + ('last-visible', "Open new tabs in the most recently " + "visible window.") )), 'last-focused'), "Which window to choose when opening links as new tabs."), diff --git a/qutebrowser/mainwindow/mainwindow.py b/qutebrowser/mainwindow/mainwindow.py index a53c4f702..496245b8c 100644 --- a/qutebrowser/mainwindow/mainwindow.py +++ b/qutebrowser/mainwindow/mainwindow.py @@ -74,6 +74,8 @@ def get_window(via_ipc, force_window=False, force_tab=False, window = objreg.last_focused_window() elif win_mode == 'last-opened': window = objreg.last_window() + elif win_mode == 'last-visible': + window = objreg.last_visible_window() except objreg.NoWindow: # There is no window left, so we open a new one window = MainWindow() @@ -458,8 +460,23 @@ class MainWindow(QWidget): self._downloadview.updateGeometry() self.tabbed_browser.tabBar().refresh() + def showEvent(self, e): + """Extend showEvent to register us as the last-visible-main-window. + + Args: + e: The QShowEvent + """ + super().showEvent(e) + objreg.register('last-visible-main-window', self, update=True) + def _do_close(self): """Helper function for closeEvent.""" + last_visible = objreg.get('last-visible-main-window') + if self is last_visible: + try: + objreg.delete('last-visible-main-window') + except KeyError: + pass objreg.get('session-manager').save_last_window_session() self._save_geometry() log.destroy.debug("Closing window {}".format(self.win_id)) diff --git a/qutebrowser/utils/objreg.py b/qutebrowser/utils/objreg.py index 0691be1ee..072c45b4d 100644 --- a/qutebrowser/utils/objreg.py +++ b/qutebrowser/utils/objreg.py @@ -280,6 +280,14 @@ def dump_objects(): return lines +def last_visible_window(): + """Get the last visible window, or the last focused window if none.""" + try: + return get('last-visible-main-window') + except KeyError: + return last_focused_window() + + def last_focused_window(): """Get the last focused window, or the last window if none.""" try: From 4205e1c95b52277054765a2bca3b5b21fcd142ec Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Wed, 10 Aug 2016 17:40:27 +0200 Subject: [PATCH 2/2] Update docs --- CHANGELOG.asciidoc | 2 ++ doc/help/settings.asciidoc | 1 + 2 files changed, 3 insertions(+) diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index 744cf8d8b..248eb50cc 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -58,6 +58,8 @@ Changed - With `new-instance-open-target` set to a tab option, the tab is now opened in the most recently focused (instead of the last opened) window. This can be configured with the new `new-instance-open-target.window` setting. + It can also be set to `last-visible` to show the pages in the most recently + visible window. - Word hints now are more clever about getting the element text from some elements. - Completions for `:help` and `:bind` now also show hidden commands - The `:buffer` completion now also filters using the first column (id). diff --git a/doc/help/settings.asciidoc b/doc/help/settings.asciidoc index 277954815..a04e27878 100644 --- a/doc/help/settings.asciidoc +++ b/doc/help/settings.asciidoc @@ -456,6 +456,7 @@ Valid values: * +last-opened+: Open new tabs in the last opened window. * +last-focused+: Open new tabs in the most recently focused window. + * +last-visible+: Open new tabs in the most recently visible window. Default: +pass:[last-focused]+