mirror of
https://github.com/ankitects/anki.git
synced 2026-10-02 05:24:38 +08:00
cd096774bc4f1f301ac44f407901ab241d1e2b62
## Linked issue (required) Fixes #5700 ## Summary / motivation (required) Since #5637, `setupGL()` runs after `AnkiApp` is constructed. Some of what it sets is only read by Qt at startup (`AA_UseSoftwareOpenGL` on macOS, `QT_OPENGL` on Windows), so safe mode and the Software driver are no longer fully applied. This calls `setupGL()` before creating the app again, where it was before #5637. Safe mode is decided at that point, from `--safemode` or from Shift. Since Qt can only detect Shift once the app exists, `shift_held_before_app()` checks it with platform APIs: `CGEventSourceFlagsState()` on macOS and `GetAsyncKeyState(VK_SHIFT)` on Windows. If Qt still detects Shift after the app is created but the check above didn't (e.g. on Linux, where it isn't implemented), `setupGL()` is called again with the Software driver. On Linux the settings it makes still take effect at that point, so that path keeps working as it does today. Happy to drop that fallback if you'd prefer. ## Steps to reproduce (required, use N/A if not applicable) 1. On macOS, run `/Applications/Anki.app/Contents/MacOS/anki --safemode` from a terminal 2. The console shows `Qt warning: Attribute Qt::AA_UseSoftwareOpenGL must be set before QCoreApplication is created.` ## How to test (required) ### Checklist (minimum) - [ ] I ran `./ninja check` or an equivalent relevant check locally. - [x] I added or updated tests when the change is non-trivial or behavior changed. ### Details - `qt/tests/test_startup_video_driver.py` runs `_run()` with a stand-in for `AnkiApp` and checks that `setupGL()` is called with the expected driver (profile driver, or Software with `--safemode` or Shift held) before the app is constructed. Fails on main, passes with this change. - Launched the source tree on macOS with a temporary base folder, with `--safemode`: the warning above appears on main and is gone with this change. With Shift held, `shift_held_before_app()` returns True and the warning doesn't appear either. - On Windows 11, checked the `GetAsyncKeyState(VK_SHIFT)` call used here: it returns False before Shift is pressed and True while it's held. I haven't tested a full Anki launch on Windows. - ruff check/format pass on the changed files. I haven't been able to run the full `just check` locally yet, so I'm relying on CI for the rest. ## Before / after behavior (optional) Before: `--safemode` and the Software driver don't set `AA_UseSoftwareOpenGL` (macOS) / `QT_OPENGL` (Windows) in time. After: they're applied before the app is created. ## Risk / compatibility / migration (optional) This touches the same startup block as #5686, so whichever lands second will need a small rebase. I'll take care of it if this one goes second. ## UI evidence (required for visual changes; otherwise N/A) N/A ## Scope - [x] This PR is focused on one change (no unrelated edits). --------- Co-authored-by: Abdo <abdo@abdnh.net>
Anki
This repo contains the source code for the computer version of Anki.
About
Anki is a spaced repetition program. Please see the website to learn more.
Getting Started
Contributing
Want to contribute to Anki? Check out the Contribution Guidelines.
For more information on building and developing, please see Development.
Contributors
The following people have contributed to Anki: CONTRIBUTORS
Anki Betas
If you'd like to try development builds of Anki but don't feel comfortable building the code, please see Anki betas.
License
Anki's license: LICENSE
Languages
Rust
37.5%
Python
22.9%
MDX
19.5%
TypeScript
9.5%
Svelte
8.9%
Other
1.3%