Louis VicatandAbdo cd096774bc fix: apply video driver settings before the Qt app is created (#5701)
## 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>
2026-10-01 06:44:51 +03:00
2026-07-06 23:16:36 +08:00
2025-10-27 19:27:50 +07:00
2026-09-10 15:10:22 +01:00
2026-09-02 12:41:04 +03:00
2026-09-22 12:20:42 -03:00
2026-03-31 08:26:59 -04:00
2025-06-29 14:38:35 +07:00
2026-09-22 12:20:43 -03:00
2026-09-02 12:41:04 +03:00
2026-08-07 15:57:00 +03:00
2026-05-11 13:04:24 -04:00
2024-03-31 09:16:31 +01:00

Anki

Build Status Documentation Coverage

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

S
Description
GitHub Trending: ankitects/anki
Readme
513 MiB
Languages
Rust 37.5%
Python 22.9%
MDX 19.5%
TypeScript 9.5%
Svelte 8.9%
Other 1.3%