Automatically disable sandbox on Qt5 PyPi/packaged builds

This commit is contained in:
Damien Elmes 2023-11-16 10:25:40 +10:00
parent 469052700f
commit 0754a50b5b
2 changed files with 10 additions and 3 deletions

View file

@ -592,23 +592,29 @@ def _run(argv: Optional[list[str]] = None, exec: bool = True) -> Optional[AnkiAp
# apply user-provided scale factor
os.environ["QT_SCALE_FACTOR"] = str(pm.uiScale())
# opt in to full hidpi support?
# Opt-in to full HiDPI support?
if not os.environ.get("ANKI_NOHIGHDPI") and qtmajor == 5:
QCoreApplication.setAttribute(Qt.ApplicationAttribute.AA_EnableHighDpiScaling) # type: ignore
QCoreApplication.setAttribute(Qt.ApplicationAttribute.AA_UseHighDpiPixmaps) # type: ignore
os.environ["QT_ENABLE_HIGHDPI_SCALING"] = "1"
os.environ["QT_SCALE_FACTOR_ROUNDING_POLICY"] = "PassThrough"
# Opt into software rendering. Useful for buggy systems.
# Opt-in to software rendering?
if os.environ.get("ANKI_SOFTWAREOPENGL"):
QCoreApplication.setAttribute(Qt.ApplicationAttribute.AA_UseSoftwareOpenGL)
# fix an issue on Windows, where Ctrl+Alt shortcuts are triggered by AltGr,
# Fix an issue on Windows, where Ctrl+Alt shortcuts are triggered by AltGr,
# preventing users from typing things like "@" through AltGr+Q on a German
# keyboard.
if is_win and "QT_QPA_PLATFORM" not in os.environ:
os.environ["QT_QPA_PLATFORM"] = "windows:altgr"
# Disable sandbox on Qt5 PyPi/packaged builds, as it causes blank screens on modern
# glibc versions. We check for specific patch versions, because distros may have
# fixed the issue in their own Qt builds.
if is_lin and qtfullversion in ([5, 15, 2], [5, 14, 1]):
os.environ["QTWEBENGINE_DISABLE_SANDBOX"] = "1"
# create the app
QCoreApplication.setApplicationName("Anki")
QGuiApplication.setDesktopFileName("anki.desktop")

View file

@ -48,6 +48,7 @@ _version = QLibraryInfo.version()
qtmajor = _version.majorVersion()
qtminor = _version.minorVersion()
qtpoint = _version.microVersion()
qtfullversion = _version.segments()
if qtmajor < 5 or (qtmajor == 5 and qtminor < 14):
raise Exception("Anki does not support your Qt version.")