diff --git a/qt/aqt/__init__.py b/qt/aqt/__init__.py index bbff3e54e..06fb7bc8c 100644 --- a/qt/aqt/__init__.py +++ b/qt/aqt/__init__.py @@ -523,16 +523,23 @@ def _run(argv: Optional[list[str]] = None, exec: bool = True) -> Optional[AnkiAp profiler = cProfile.Profile() profiler.enable() - if ( - getattr(sys, "frozen", False) - and (os.getenv("QT_QPA_PLATFORM") == "wayland" or os.getenv("WAYLAND_DISPLAY")) - and not os.getenv("ANKI_WAYLAND") - ): - if not os.getenv("DISPLAY"): - print( - "Trying to use X11, but it is not available. Falling back to Wayland, which has some bugs:" - ) - print("https://github.com/ankitects/anki/issues/1767") + packaged = getattr(sys, "frozen", False) + x11_available = os.getenv("DISPLAY") + wayland_configured = qtmajor > 5 and ( + os.getenv("QT_QPA_PLATFORM") == "wayland" or os.getenv("WAYLAND_DISPLAY") + ) + wayland_forced = os.getenv("ANKI_WAYLAND") + + if packaged and wayland_configured: + if wayland_forced or not x11_available: + # Work around broken fractional scaling in Wayland + # https://bugreports.qt.io/browse/QTBUG-113574 + os.environ["QT_SCALE_FACTOR_ROUNDING_POLICY"] = "RoundPreferFloor" + if not x11_available: + print( + "Trying to use X11, but it is not available. Falling back to Wayland, which has some bugs:" + ) + print("https://github.com/ankitects/anki/issues/1767") else: # users need to opt in to wayland support, given the issues it has print("Wayland support is disabled by default due to bugs:") @@ -576,11 +583,6 @@ def _run(argv: Optional[list[str]] = None, exec: bool = True) -> Optional[AnkiAp if os.environ.get("ANKI_SOFTWAREOPENGL"): QCoreApplication.setAttribute(Qt.ApplicationAttribute.AA_UseSoftwareOpenGL) - # Work around broken fractional scaling in Wayland - # https://bugreports.qt.io/browse/QTBUG-113574 - if is_lin and qtmajor > 5: - os.environ["QT_SCALE_FACTOR_ROUNDING_POLICY"] = "RoundPreferFloor" - # 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.