diff options
author | Florian Bruhin <me@the-compiler.org> | 2022-08-23 18:26:05 +0200 |
---|---|---|
committer | Florian Bruhin <me@the-compiler.org> | 2022-08-23 18:31:42 +0200 |
commit | 1963caa7c77ec8fb985e46e29e1ff79e771ec655 (patch) | |
tree | 1179f304282e3443d7de21f8f8cab6006def08d0 | |
parent | bb19aea7c934604814da16c4ea7a26ed16e6e56a (diff) | |
download | qutebrowser-1963caa7c77ec8fb985e46e29e1ff79e771ec655.tar.gz qutebrowser-1963caa7c77ec8fb985e46e29e1ff79e771ec655.zip |
Make PyObjC/AppKit optional with Qt 6.3+
-rw-r--r-- | misc/requirements/requirements-qutebrowser.txt-raw | 2 | ||||
-rw-r--r-- | qutebrowser/mainwindow/mainwindow.py | 3 | ||||
-rw-r--r-- | qutebrowser/misc/earlyinit.py | 32 |
3 files changed, 26 insertions, 11 deletions
diff --git a/misc/requirements/requirements-qutebrowser.txt-raw b/misc/requirements/requirements-qutebrowser.txt-raw index c628f528a..34cf4abde 100644 --- a/misc/requirements/requirements-qutebrowser.txt-raw +++ b/misc/requirements/requirements-qutebrowser.txt-raw @@ -2,6 +2,8 @@ Jinja2 PyYAML ## Only used on macOS to make borderless windows resizable +# Not needed anymore with Qt 6.3, but we can't express that +# here, and it won't hurt either. pyobjc-core pyobjc-framework-Cocoa diff --git a/qutebrowser/mainwindow/mainwindow.py b/qutebrowser/mainwindow/mainwindow.py index fb764756d..e4cf8ced1 100644 --- a/qutebrowser/mainwindow/mainwindow.py +++ b/qutebrowser/mainwindow/mainwindow.py @@ -570,7 +570,8 @@ class MainWindow(QWidget): window_flags |= Qt.WindowType.CustomizeWindowHint | Qt.WindowType.NoDropShadowWindowHint self.setWindowFlags(window_flags) - if utils.is_mac and hidden: + if utils.is_mac and hidden and not qtutils.version_check('6.3', compiled=False): + # WORKAROUND for https://codereview.qt-project.org/c/qt/qtbase/+/371279 from ctypes import c_void_p # pylint: disable=import-error from objc import objc_object diff --git a/qutebrowser/misc/earlyinit.py b/qutebrowser/misc/earlyinit.py index 7165d5bdf..ef7814ab1 100644 --- a/qutebrowser/misc/earlyinit.py +++ b/qutebrowser/misc/earlyinit.py @@ -177,16 +177,21 @@ def qt_version(qversion=None, qt_version_str=None): return qversion +def get_qt_version(): + """Get the Qt version, or None if too old for QLibaryInfo.version().""" + try: + from qutebrowser.qt.core import QLibraryInfo + return QLibraryInfo.version().normalized() + except (ImportError, AttributeError): + return None + + def check_qt_version(): """Check if the Qt version is recent enough.""" from qutebrowser.qt.core import QT_VERSION, PYQT_VERSION, PYQT_VERSION_STR - try: - from qutebrowser.qt.core import QVersionNumber, QLibraryInfo - qt_ver = QLibraryInfo.version().normalized() - recent_qt_runtime = qt_ver >= QVersionNumber(5, 15) # type: ignore[operator] - except (ImportError, AttributeError): - # QVersionNumber was added in Qt 5.6, QLibraryInfo.version() in 5.8 - recent_qt_runtime = False + from qutebrowser.qt.core import QVersionNumber + qt_ver = get_qt_version() + recent_qt_runtime = qt_ver is not None and qt_ver >= QVersionNumber(5, 15) if QT_VERSION < 0x050F00 or PYQT_VERSION < 0x050F00 or not recent_qt_runtime: text = ("Fatal error: Qt >= 5.15.0 and PyQt >= 5.15.0 are required, " @@ -240,16 +245,23 @@ def check_libraries(): 'jinja2': _missing_str("jinja2"), 'yaml': _missing_str("PyYAML"), } + for subpkg in ['QtQml', 'QtOpenGL', 'QtDBus']: package = f'{machinery.PACKAGE}.{subpkg}' modules[package] = _missing_str(package) + if sys.version_info < (3, 9): # Backport required modules['importlib_resources'] = _missing_str("importlib_resources") + if sys.platform.startswith('darwin'): - # Used for resizable hide_decoration windows on macOS - modules['objc'] = _missing_str("pyobjc-core") - modules['AppKit'] = _missing_str("pyobjc-framework-Cocoa") + from qutebrowser.qt.core import QVersionNumber + qt_ver = get_qt_version() + if qt_ver is not None and qt_ver < QVersionNumber(6, 3): + # Used for resizable hide_decoration windows on macOS + modules['objc'] = _missing_str("pyobjc-core") + modules['AppKit'] = _missing_str("pyobjc-framework-Cocoa") + _check_modules(modules) |