Tweaks to video driver handling

- Use a separate `gldriver6` file for configuring Qt6 so we don't
pick up old settings, or cause problems when switching back and forth.
- Default to OpenGL/auto instead of software, as that was what we
were using throughout the beta period.
- Try to detect driver failure on startup. Untested.
- Hide the selector in the preferences again, as if Anki is unable
to automatically switch drivers, the user could change the setting
and then not be able to get back into Anki.
This commit is contained in:
Damien Elmes 2022-04-06 11:34:57 +10:00
parent b0a2884f19
commit f2bffaa185
3 changed files with 17 additions and 4 deletions

View file

@ -34,7 +34,7 @@ import locale
import os
import tempfile
import traceback
from typing import Any, Callable, Optional, cast
from typing import TYPE_CHECKING, Any, Callable, Optional, cast
import anki.lang
from anki._backend import RustBackend
@ -46,6 +46,9 @@ from aqt import gui_hooks
from aqt.qt import *
from aqt.utils import TR, tr
if TYPE_CHECKING:
import aqt.profiles
# compat aliases
anki.version = _version # type: ignore
anki.Collection = Collection # type: ignore
@ -394,7 +397,12 @@ def setupGL(pm: aqt.profiles.ProfileManager) -> None:
context += f"{ctx.function}"
if context:
context = f"'{context}'"
if "Failed to create OpenGL context" in msg:
if (
"Failed to create OpenGL context" in msg
# Based on the message Qt6 shows to the user; have not tested whether
# we can actually capture this or not.
or "Failed to initialize graphics backend" in msg
):
QMessageBox.critical(
None,
tr.qt_misc_error(),

View file

@ -290,6 +290,7 @@ class Preferences(QDialog):
self.form.video_driver.setCurrentIndex(
self.video_drivers.index(self.mw.pm.video_driver())
)
self.form.video_driver.setVisible(qtmajor == 5)
def update_video_driver(self) -> None:
new_driver = self.video_drivers[self.form.video_driver.currentIndex()]

View file

@ -38,7 +38,7 @@ class VideoDriver(Enum):
@staticmethod
def default_for_platform() -> VideoDriver:
if is_mac:
if is_mac or qtmajor > 5:
return VideoDriver.OpenGL
else:
return VideoDriver.Software
@ -479,7 +479,11 @@ create table if not exists profiles
######################################################################
def _gldriver_path(self) -> str:
return os.path.join(self.base, "gldriver")
if qtmajor < 6:
fname = "gldriver"
else:
fname = "gldriver6"
return os.path.join(self.base, fname)
def video_driver(self) -> VideoDriver:
path = self._gldriver_path()