From ab6bfe61b8c60339923ded81205a22aa845f5231 Mon Sep 17 00:00:00 2001 From: Anton S Date: Sun, 1 Oct 2017 00:35:03 +0300 Subject: [PATCH 01/17] [osx] first step to become default browser --- qutebrowser/app.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/qutebrowser/app.py b/qutebrowser/app.py index d2efb21e5..343f8df54 100644 --- a/qutebrowser/app.py +++ b/qutebrowser/app.py @@ -806,6 +806,18 @@ class Application(QApplication): self.launch_time = datetime.datetime.now() self.focusObjectChanged.connect(self.on_focus_object_changed) + def event(self, e): + if e.type() != QEvent.FileOpen: + return super(QApplication, self).event(e) + + url = e.url() + log.misc.info("Got FileOpen event: %s" % url) + tabbed_browser = objreg.get('tabbed-browser', scope='window', + window='last-focused') + tabbed_browser.tabopen(url, related=False) + return True + + @pyqtSlot(QObject) def on_focus_object_changed(self, obj): """Log when the focus object changed.""" From a576fae89351851e582549c6817907357a8900ac Mon Sep 17 00:00:00 2001 From: Anton S Date: Mon, 2 Oct 2017 01:04:12 +0300 Subject: [PATCH 02/17] [osx] declare URLs support in Info.plist --- scripts/dev/build_release.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/scripts/dev/build_release.py b/scripts/dev/build_release.py index 1e2bd5b6d..612599932 100755 --- a/scripts/dev/build_release.py +++ b/scripts/dev/build_release.py @@ -26,6 +26,7 @@ import sys import glob import os.path import shutil +import plistlib import subprocess import argparse import tarfile @@ -123,6 +124,19 @@ def patch_mac_app(): os.symlink(os.path.join(os.pardir, os.pardir, os.pardir, 'Contents', 'MacOS', lib), os.path.join(dest, lib)) + # Patch Info.plist to declare URLs support + plist_path = os.path.join(app_path, 'Contents', 'Info.plist') + with open(plist_path, "rb") as f: + plist_data = plistlib.load(f) + plist_data['CFBundleURLTypes'] = [{ + "CFBundleURLName": "http(s) URL", + "CFBundleURLSchemes": ["http", "https"] + }, { + "CFBundleURLName": "local file URL", + "CFBundleURLSchemes": ["file"] + }] + with open(plist_path, "wb") as f: + plistlib.dump(plist_data, f) def build_mac(): From 68481bc98948a2bdb583bddd6e292ff41be8a1bb Mon Sep 17 00:00:00 2001 From: Anton S Date: Wed, 4 Oct 2017 00:02:03 +0300 Subject: [PATCH 03/17] [osx] declare html files support as well --- scripts/dev/build_release.py | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/scripts/dev/build_release.py b/scripts/dev/build_release.py index 612599932..bb6f45a42 100755 --- a/scripts/dev/build_release.py +++ b/scripts/dev/build_release.py @@ -128,15 +128,32 @@ def patch_mac_app(): plist_path = os.path.join(app_path, 'Contents', 'Info.plist') with open(plist_path, "rb") as f: plist_data = plistlib.load(f) - plist_data['CFBundleURLTypes'] = [{ + plist_data.update(INFO_PLIST_UPDATES) + with open(plist_path, "wb") as f: + plistlib.dump(plist_data, f) + + +INFO_PLIST_UPDATES = { + 'CFBundleURLTypes': [{ "CFBundleURLName": "http(s) URL", "CFBundleURLSchemes": ["http", "https"] }, { "CFBundleURLName": "local file URL", "CFBundleURLSchemes": ["file"] + }], + 'CFBundleDocumentTypes': [{ + "CFBundleTypeExtensions": ["html", "htm"], + "CFBundleTypeMIMETypes": ["text/html"], + "CFBundleTypeName": "HTML document", + "CFBundleTypeOSTypes": ["HTML"], + "CFBundleTypeRole": "Viewer", + }, { + "CFBundleTypeExtensions": ["xhtml"], + "CFBundleTypeMIMETypes": ["text/xhtml"], + "CFBundleTypeName": "XHTML document", + "CFBundleTypeRole": "Viewer", }] - with open(plist_path, "wb") as f: - plistlib.dump(plist_data, f) +} def build_mac(): From 5350b948ea3b11f55899d9be0847a9bb710ea113 Mon Sep 17 00:00:00 2001 From: Anton S Date: Thu, 5 Oct 2017 01:08:50 +0300 Subject: [PATCH 04/17] [review] gather plist params in one place --- misc/qutebrowser.spec | 4 ---- scripts/dev/build_release.py | 4 +++- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/misc/qutebrowser.spec b/misc/qutebrowser.spec index bcbd67405..c3da992af 100644 --- a/misc/qutebrowser.spec +++ b/misc/qutebrowser.spec @@ -71,9 +71,5 @@ coll = COLLECT(exe, app = BUNDLE(coll, name='qutebrowser.app', icon=icon, - info_plist={ - 'NSHighResolutionCapable': 'True', - 'NSSupportsAutomaticGraphicsSwitching': 'True', - }, # https://github.com/pyinstaller/pyinstaller/blob/b78bfe530cdc2904f65ce098bdf2de08c9037abb/PyInstaller/hooks/hook-PyQt5.QtWebEngineWidgets.py#L24 bundle_identifier='org.qt-project.Qt.QtWebEngineCore') diff --git a/scripts/dev/build_release.py b/scripts/dev/build_release.py index bb6f45a42..c8c291885 100755 --- a/scripts/dev/build_release.py +++ b/scripts/dev/build_release.py @@ -124,7 +124,7 @@ def patch_mac_app(): os.symlink(os.path.join(os.pardir, os.pardir, os.pardir, 'Contents', 'MacOS', lib), os.path.join(dest, lib)) - # Patch Info.plist to declare URLs support + # Patch Info.plist - pyinstaller's options are too limiting plist_path = os.path.join(app_path, 'Contents', 'Info.plist') with open(plist_path, "rb") as f: plist_data = plistlib.load(f) @@ -134,6 +134,8 @@ def patch_mac_app(): INFO_PLIST_UPDATES = { + 'NSSupportsAutomaticGraphicsSwitching': True, + 'NSHighResolutionCapable': True, 'CFBundleURLTypes': [{ "CFBundleURLName": "http(s) URL", "CFBundleURLSchemes": ["http", "https"] From 0f1444125fb26be7dbbf265e0085c8df54398ed4 Mon Sep 17 00:00:00 2001 From: Anton S Date: Thu, 5 Oct 2017 01:13:53 +0300 Subject: [PATCH 05/17] [osx] proper plist to show up in browsers list (by The-Compiler) --- scripts/dev/build_release.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/dev/build_release.py b/scripts/dev/build_release.py index c8c291885..319bce3d9 100755 --- a/scripts/dev/build_release.py +++ b/scripts/dev/build_release.py @@ -134,6 +134,8 @@ def patch_mac_app(): INFO_PLIST_UPDATES = { + 'CFBundleVersion': qutebrowser.__version__, + 'CFBundleShortVersionString': qutebrowser.__version__, 'NSSupportsAutomaticGraphicsSwitching': True, 'NSHighResolutionCapable': True, 'CFBundleURLTypes': [{ From 91c6847e5991bd4d7524614b598d83a66f0ecb94 Mon Sep 17 00:00:00 2001 From: Anton S Date: Thu, 5 Oct 2017 01:49:13 +0300 Subject: [PATCH 06/17] [review] style fixes --- qutebrowser/app.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/qutebrowser/app.py b/qutebrowser/app.py index 343f8df54..288606226 100644 --- a/qutebrowser/app.py +++ b/qutebrowser/app.py @@ -808,10 +808,10 @@ class Application(QApplication): def event(self, e): if e.type() != QEvent.FileOpen: - return super(QApplication, self).event(e) + return super().event(e) url = e.url() - log.misc.info("Got FileOpen event: %s" % url) + log.misc.info("Got FileOpen event: {}".format(url.toDisplayString())) tabbed_browser = objreg.get('tabbed-browser', scope='window', window='last-focused') tabbed_browser.tabopen(url, related=False) From 6b7cecc84083775f558772beb76be542e119b62b Mon Sep 17 00:00:00 2001 From: Anton S Date: Mon, 9 Oct 2017 03:08:08 +0300 Subject: [PATCH 07/17] separated window raising into it's own function --- qutebrowser/mainwindow/mainwindow.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/qutebrowser/mainwindow/mainwindow.py b/qutebrowser/mainwindow/mainwindow.py index 373a9030a..28bd0ef72 100644 --- a/qutebrowser/mainwindow/mainwindow.py +++ b/qutebrowser/mainwindow/mainwindow.py @@ -71,29 +71,33 @@ def get_window(via_ipc, force_window=False, force_tab=False, open_target = 'tab-silent' window = None - raise_window = False + should_raise = False # Try to find the existing tab target if opening in a tab if open_target != 'window': window = get_target_window() - raise_window = open_target not in ['tab-silent', 'tab-bg-silent'] + should_raise = open_target not in ['tab-silent', 'tab-bg-silent'] # Otherwise, or if no window was found, create a new one if window is None: window = MainWindow(private=None) window.show() - raise_window = True + should_raise = True - if raise_window: - window.setWindowState(window.windowState() & ~Qt.WindowMinimized) - window.setWindowState(window.windowState() | Qt.WindowActive) - window.raise_() - window.activateWindow() - QApplication.instance().alert(window) + if should_raise: + raise_window(window) return window.win_id +def raise_window(window): + window.setWindowState(window.windowState() & ~Qt.WindowMinimized) + window.setWindowState(window.windowState() | Qt.WindowActive) + window.raise_() + window.activateWindow() + QApplication.instance().alert(window) + + def get_target_window(): """Get the target window for new tabs, or None if none exist.""" try: From 5301a4249590837a08b95e40e348187cbcd58bd1 Mon Sep 17 00:00:00 2001 From: Anton S Date: Mon, 9 Oct 2017 03:10:13 +0300 Subject: [PATCH 08/17] raise last focused window if requested --- qutebrowser/app.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/qutebrowser/app.py b/qutebrowser/app.py index 288606226..855b971a8 100644 --- a/qutebrowser/app.py +++ b/qutebrowser/app.py @@ -51,7 +51,7 @@ import tokenize from PyQt5.QtWidgets import QApplication, QWidget from PyQt5.QtGui import QDesktopServices, QPixmap, QIcon, QWindow from PyQt5.QtCore import (pyqtSlot, qInstallMessageHandler, QTimer, QUrl, - QObject, QEvent, pyqtSignal) + QObject, QEvent, pyqtSignal, Qt) try: import hunter except ImportError: @@ -805,6 +805,15 @@ class Application(QApplication): self.launch_time = datetime.datetime.now() self.focusObjectChanged.connect(self.on_focus_object_changed) + self.applicationStateChanged.connect(self.on_app_state_changed) + + @pyqtSlot(Qt.ApplicationState) + def on_app_state_changed(self, state): + if state != Qt.ApplicationActive: + return + + window = objreg.last_focused_window() + mainwindow.raise_window(window) def event(self, e): if e.type() != QEvent.FileOpen: From 552d0414228284feff37d1d56352ddcb5de2da7f Mon Sep 17 00:00:00 2001 From: Anton S Date: Tue, 10 Oct 2017 01:30:14 +0300 Subject: [PATCH 09/17] reused some code from process args --- qutebrowser/app.py | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/qutebrowser/app.py b/qutebrowser/app.py index 855b971a8..1ea415dfb 100644 --- a/qutebrowser/app.py +++ b/qutebrowser/app.py @@ -288,22 +288,32 @@ def process_pos_args(args, via_ipc=False, cwd=None, target_arg=None): if via_ipc and target_arg and target_arg != 'auto': open_target = target_arg else: - open_target = config.val.new_instance_open_target - win_id = mainwindow.get_window(via_ipc, force_target=open_target) - tabbed_browser = objreg.get('tabbed-browser', scope='window', - window=win_id) - log.init.debug("Startup URL {}".format(cmd)) + open_target = None if not cwd: # could also be an empty string due to the PyQt signal cwd = None try: url = urlutils.fuzzy_url(cmd, cwd, relative=True) + win_id = open_url(url, target=open_target) except urlutils.InvalidUrlError as e: message.error("Error in startup argument '{}': {}".format( cmd, e)) - else: - background = open_target in ['tab-bg', 'tab-bg-silent'] - tabbed_browser.tabopen(url, background=background, - related=False) + + +def open_url(url, target=None): + """Open an URLs in new window/tab + + Args: + url: An URL to open + target: same as new_instance_open_target (used as a default) + """ + target = target or config.val.new_instance_open_target + background = target in ['tab-bg', 'tab-bg-silent'] + win_id = mainwindow.get_window(True, force_target=target) + tabbed_browser = objreg.get('tabbed-browser', scope='window', + window=win_id) + log.init.debug("About to open URL {}".format(url)) + tabbed_browser.tabopen(url, background=background, related=False) + return win_id def _open_startpage(win_id=None): From 00f0e519a964c97ae07408d9d5f817b798b7547e Mon Sep 17 00:00:00 2001 From: Anton S Date: Tue, 10 Oct 2017 01:30:58 +0300 Subject: [PATCH 10/17] added option to suppress window raising --- qutebrowser/app.py | 5 +++-- qutebrowser/mainwindow/mainwindow.py | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/qutebrowser/app.py b/qutebrowser/app.py index 1ea415dfb..618fad6b5 100644 --- a/qutebrowser/app.py +++ b/qutebrowser/app.py @@ -299,7 +299,7 @@ def process_pos_args(args, via_ipc=False, cwd=None, target_arg=None): cmd, e)) -def open_url(url, target=None): +def open_url(url, target=None, force_raise=None): """Open an URLs in new window/tab Args: @@ -308,7 +308,8 @@ def open_url(url, target=None): """ target = target or config.val.new_instance_open_target background = target in ['tab-bg', 'tab-bg-silent'] - win_id = mainwindow.get_window(True, force_target=target) + win_id = mainwindow.get_window(True, force_target=target, + force_raise=force_raise) tabbed_browser = objreg.get('tabbed-browser', scope='window', window=win_id) log.init.debug("About to open URL {}".format(url)) diff --git a/qutebrowser/mainwindow/mainwindow.py b/qutebrowser/mainwindow/mainwindow.py index 28bd0ef72..4fd6abc86 100644 --- a/qutebrowser/mainwindow/mainwindow.py +++ b/qutebrowser/mainwindow/mainwindow.py @@ -43,7 +43,7 @@ win_id_gen = itertools.count(0) def get_window(via_ipc, force_window=False, force_tab=False, - force_target=None): + force_target=None, force_raise=None): """Helper function for app.py to get a window id. Args: @@ -84,7 +84,7 @@ def get_window(via_ipc, force_window=False, force_tab=False, window.show() should_raise = True - if should_raise: + if (force_raise is True) or (force_raise is None and should_raise): raise_window(window) return window.win_id From 14da05f7b1bba9f47a8f06d53c239fb0963e4335 Mon Sep 17 00:00:00 2001 From: Anton S Date: Tue, 10 Oct 2017 01:31:31 +0300 Subject: [PATCH 11/17] use open_url to handle FileOpen event --- qutebrowser/app.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/qutebrowser/app.py b/qutebrowser/app.py index 618fad6b5..c9f54e7c6 100644 --- a/qutebrowser/app.py +++ b/qutebrowser/app.py @@ -832,9 +832,7 @@ class Application(QApplication): url = e.url() log.misc.info("Got FileOpen event: {}".format(url.toDisplayString())) - tabbed_browser = objreg.get('tabbed-browser', scope='window', - window='last-focused') - tabbed_browser.tabopen(url, related=False) + open_url(url, force_raise=False) return True From 40185385cf4ebac9c1afe57a993f67c9bd9db875 Mon Sep 17 00:00:00 2001 From: Anton S Date: Tue, 10 Oct 2017 01:37:39 +0300 Subject: [PATCH 12/17] moved methods to restore initial order --- qutebrowser/app.py | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/qutebrowser/app.py b/qutebrowser/app.py index c9f54e7c6..afb5be14c 100644 --- a/qutebrowser/app.py +++ b/qutebrowser/app.py @@ -818,6 +818,14 @@ class Application(QApplication): self.focusObjectChanged.connect(self.on_focus_object_changed) self.applicationStateChanged.connect(self.on_app_state_changed) + @pyqtSlot(QObject) + def on_focus_object_changed(self, obj): + """Log when the focus object changed.""" + output = repr(obj) + if self._last_focus_object != output: + log.misc.debug("Focus object changed: {}".format(output)) + self._last_focus_object = output + @pyqtSlot(Qt.ApplicationState) def on_app_state_changed(self, state): if state != Qt.ApplicationActive: @@ -827,23 +835,13 @@ class Application(QApplication): mainwindow.raise_window(window) def event(self, e): - if e.type() != QEvent.FileOpen: + if e.type() == QEvent.FileOpen: + open_url(e.url(), force_raise=False) + else: return super().event(e) - url = e.url() - log.misc.info("Got FileOpen event: {}".format(url.toDisplayString())) - open_url(url, force_raise=False) return True - - @pyqtSlot(QObject) - def on_focus_object_changed(self, obj): - """Log when the focus object changed.""" - output = repr(obj) - if self._last_focus_object != output: - log.misc.debug("Focus object changed: {}".format(output)) - self._last_focus_object = output - def __repr__(self): return utils.get_repr(self) From e537826ff5c057fe57ca1e4ebb0a1b4ef7756462 Mon Sep 17 00:00:00 2001 From: Anton S Date: Tue, 10 Oct 2017 01:46:49 +0300 Subject: [PATCH 13/17] fixed docstring, converted list to set --- qutebrowser/app.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/qutebrowser/app.py b/qutebrowser/app.py index afb5be14c..c5c2de235 100644 --- a/qutebrowser/app.py +++ b/qutebrowser/app.py @@ -300,14 +300,14 @@ def process_pos_args(args, via_ipc=False, cwd=None, target_arg=None): def open_url(url, target=None, force_raise=None): - """Open an URLs in new window/tab + """Open an URL in new window/tab Args: url: An URL to open target: same as new_instance_open_target (used as a default) """ target = target or config.val.new_instance_open_target - background = target in ['tab-bg', 'tab-bg-silent'] + background = target in {'tab-bg', 'tab-bg-silent'} win_id = mainwindow.get_window(True, force_target=target, force_raise=force_raise) tabbed_browser = objreg.get('tabbed-browser', scope='window', From e1f5da3eff50c44462562f900314125f9494a173 Mon Sep 17 00:00:00 2001 From: Anton S Date: Tue, 10 Oct 2017 14:13:49 +0300 Subject: [PATCH 14/17] [review] docstrings, url logging, etc. --- qutebrowser/app.py | 12 ++++++++++-- qutebrowser/mainwindow/mainwindow.py | 7 +++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/qutebrowser/app.py b/qutebrowser/app.py index c5c2de235..937324afd 100644 --- a/qutebrowser/app.py +++ b/qutebrowser/app.py @@ -293,10 +293,11 @@ def process_pos_args(args, via_ipc=False, cwd=None, target_arg=None): cwd = None try: url = urlutils.fuzzy_url(cmd, cwd, relative=True) - win_id = open_url(url, target=open_target) except urlutils.InvalidUrlError as e: message.error("Error in startup argument '{}': {}".format( cmd, e)) + else: + win_id = open_url(url, target=open_target) def open_url(url, target=None, force_raise=None): @@ -305,6 +306,13 @@ def open_url(url, target=None, force_raise=None): Args: url: An URL to open target: same as new_instance_open_target (used as a default) + force_raise: control target window raising: + * None - obey new_instance_open_target + * True - always raise + * False - never raise + + Return: + ID of a window that was used to open URL """ target = target or config.val.new_instance_open_target background = target in {'tab-bg', 'tab-bg-silent'} @@ -312,7 +320,7 @@ def open_url(url, target=None, force_raise=None): force_raise=force_raise) tabbed_browser = objreg.get('tabbed-browser', scope='window', window=win_id) - log.init.debug("About to open URL {}".format(url)) + log.init.debug("About to open URL: {}".format(url.toDisplayString())) tabbed_browser.tabopen(url, background=background, related=False) return win_id diff --git a/qutebrowser/mainwindow/mainwindow.py b/qutebrowser/mainwindow/mainwindow.py index 4fd6abc86..2eccf67c7 100644 --- a/qutebrowser/mainwindow/mainwindow.py +++ b/qutebrowser/mainwindow/mainwindow.py @@ -51,6 +51,13 @@ def get_window(via_ipc, force_window=False, force_tab=False, force_window: Whether to force opening in a window. force_tab: Whether to force opening in a tab. force_target: Override the new_instance_open_target config + force_raise: control target window raising: + * None - obey new_instance_open_target + * True - always raise + * False - never raise + + Return: + ID of a window that was used to open URL """ if force_window and force_tab: raise ValueError("force_window and force_tab are mutually exclusive!") From ba1a7a8de8ca8c3f6838ff5a82eb686571bf8706 Mon Sep 17 00:00:00 2001 From: Anton S Date: Tue, 10 Oct 2017 23:02:10 +0300 Subject: [PATCH 15/17] [review] force_raise -> no_raise --- qutebrowser/app.py | 12 ++++-------- qutebrowser/mainwindow/mainwindow.py | 9 +++------ 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/qutebrowser/app.py b/qutebrowser/app.py index 937324afd..2520d5b7b 100644 --- a/qutebrowser/app.py +++ b/qutebrowser/app.py @@ -300,24 +300,20 @@ def process_pos_args(args, via_ipc=False, cwd=None, target_arg=None): win_id = open_url(url, target=open_target) -def open_url(url, target=None, force_raise=None): +def open_url(url, target=None, no_raise=False): """Open an URL in new window/tab Args: url: An URL to open target: same as new_instance_open_target (used as a default) - force_raise: control target window raising: - * None - obey new_instance_open_target - * True - always raise - * False - never raise + no_raise: suppress target window raising Return: ID of a window that was used to open URL """ target = target or config.val.new_instance_open_target background = target in {'tab-bg', 'tab-bg-silent'} - win_id = mainwindow.get_window(True, force_target=target, - force_raise=force_raise) + win_id = mainwindow.get_window(True, force_target=target, no_raise=no_raise) tabbed_browser = objreg.get('tabbed-browser', scope='window', window=win_id) log.init.debug("About to open URL: {}".format(url.toDisplayString())) @@ -844,7 +840,7 @@ class Application(QApplication): def event(self, e): if e.type() == QEvent.FileOpen: - open_url(e.url(), force_raise=False) + open_url(e.url(), no_raise=True) else: return super().event(e) diff --git a/qutebrowser/mainwindow/mainwindow.py b/qutebrowser/mainwindow/mainwindow.py index 2eccf67c7..669a03327 100644 --- a/qutebrowser/mainwindow/mainwindow.py +++ b/qutebrowser/mainwindow/mainwindow.py @@ -43,7 +43,7 @@ win_id_gen = itertools.count(0) def get_window(via_ipc, force_window=False, force_tab=False, - force_target=None, force_raise=None): + force_target=None, no_raise=False): """Helper function for app.py to get a window id. Args: @@ -51,10 +51,7 @@ def get_window(via_ipc, force_window=False, force_tab=False, force_window: Whether to force opening in a window. force_tab: Whether to force opening in a tab. force_target: Override the new_instance_open_target config - force_raise: control target window raising: - * None - obey new_instance_open_target - * True - always raise - * False - never raise + no_raise: suppress target window raising Return: ID of a window that was used to open URL @@ -91,7 +88,7 @@ def get_window(via_ipc, force_window=False, force_tab=False, window.show() should_raise = True - if (force_raise is True) or (force_raise is None and should_raise): + if should_raise and not no_raise: raise_window(window) return window.win_id From 085304a1de698c082e46af095b7f1a4bd2faceb7 Mon Sep 17 00:00:00 2001 From: Anton S Date: Wed, 11 Oct 2017 00:28:20 +0300 Subject: [PATCH 16/17] [review] removed ApplicationActivate handler due to bugs --- qutebrowser/app.py | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/qutebrowser/app.py b/qutebrowser/app.py index 2520d5b7b..50ee19154 100644 --- a/qutebrowser/app.py +++ b/qutebrowser/app.py @@ -51,7 +51,7 @@ import tokenize from PyQt5.QtWidgets import QApplication, QWidget from PyQt5.QtGui import QDesktopServices, QPixmap, QIcon, QWindow from PyQt5.QtCore import (pyqtSlot, qInstallMessageHandler, QTimer, QUrl, - QObject, QEvent, pyqtSignal, Qt) + QObject, QEvent, pyqtSignal) try: import hunter except ImportError: @@ -820,7 +820,6 @@ class Application(QApplication): self.launch_time = datetime.datetime.now() self.focusObjectChanged.connect(self.on_focus_object_changed) - self.applicationStateChanged.connect(self.on_app_state_changed) @pyqtSlot(QObject) def on_focus_object_changed(self, obj): @@ -830,14 +829,6 @@ class Application(QApplication): log.misc.debug("Focus object changed: {}".format(output)) self._last_focus_object = output - @pyqtSlot(Qt.ApplicationState) - def on_app_state_changed(self, state): - if state != Qt.ApplicationActive: - return - - window = objreg.last_focused_window() - mainwindow.raise_window(window) - def event(self, e): if e.type() == QEvent.FileOpen: open_url(e.url(), no_raise=True) From fadc8f1e0b77ccb4ed5d55a894a518e1ea813194 Mon Sep 17 00:00:00 2001 From: Anton S Date: Wed, 11 Oct 2017 00:45:22 +0300 Subject: [PATCH 17/17] [review] convey via_ipc from process_pos_args to get_window --- qutebrowser/app.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/qutebrowser/app.py b/qutebrowser/app.py index 50ee19154..3567bdc35 100644 --- a/qutebrowser/app.py +++ b/qutebrowser/app.py @@ -297,23 +297,25 @@ def process_pos_args(args, via_ipc=False, cwd=None, target_arg=None): message.error("Error in startup argument '{}': {}".format( cmd, e)) else: - win_id = open_url(url, target=open_target) + win_id = open_url(url, target=open_target, via_ipc=via_ipc) -def open_url(url, target=None, no_raise=False): +def open_url(url, target=None, no_raise=False, via_ipc=True): """Open an URL in new window/tab Args: url: An URL to open target: same as new_instance_open_target (used as a default) no_raise: suppress target window raising + via_ipc: Whether the arguments were transmitted over IPC. Return: ID of a window that was used to open URL """ target = target or config.val.new_instance_open_target background = target in {'tab-bg', 'tab-bg-silent'} - win_id = mainwindow.get_window(True, force_target=target, no_raise=no_raise) + win_id = mainwindow.get_window(via_ipc, force_target=target, + no_raise=no_raise) tabbed_browser = objreg.get('tabbed-browser', scope='window', window=win_id) log.init.debug("About to open URL: {}".format(url.toDisplayString()))