Only apply Wayland workaround in Wayland path

https://github.com/ankitects/anki/issues/1767#issuecomment-1562695240
This commit is contained in:
Damien Elmes 2023-05-29 19:07:54 +10:00
parent b618ab93a5
commit 93e1a6be22

View file

@ -523,16 +523,23 @@ def _run(argv: Optional[list[str]] = None, exec: bool = True) -> Optional[AnkiAp
profiler = cProfile.Profile() profiler = cProfile.Profile()
profiler.enable() profiler.enable()
if ( packaged = getattr(sys, "frozen", False)
getattr(sys, "frozen", False) x11_available = os.getenv("DISPLAY")
and (os.getenv("QT_QPA_PLATFORM") == "wayland" or os.getenv("WAYLAND_DISPLAY")) wayland_configured = qtmajor > 5 and (
and not os.getenv("ANKI_WAYLAND") os.getenv("QT_QPA_PLATFORM") == "wayland" or os.getenv("WAYLAND_DISPLAY")
): )
if not os.getenv("DISPLAY"): wayland_forced = os.getenv("ANKI_WAYLAND")
print(
"Trying to use X11, but it is not available. Falling back to Wayland, which has some bugs:" if packaged and wayland_configured:
) if wayland_forced or not x11_available:
print("https://github.com/ankitects/anki/issues/1767") # 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: else:
# users need to opt in to wayland support, given the issues it has # users need to opt in to wayland support, given the issues it has
print("Wayland support is disabled by default due to bugs:") 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"): if os.environ.get("ANKI_SOFTWAREOPENGL"):
QCoreApplication.setAttribute(Qt.ApplicationAttribute.AA_UseSoftwareOpenGL) 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, # 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 # preventing users from typing things like "@" through AltGr+Q on a German
# keyboard. # keyboard.