Commit 3507483
fix(ui): persist and clamp device-reported DPI through _handleDpiRead
When the engine read the device's current DPI on connect, the backend
overwrote ``settings.dpi`` in-memory but never called ``save_config`` --
so a DPI change made on the mouse hardware (via the on-device cycle
button, Logi Options+ briefly stealing the device, or another Mouser
session) was visible to the running session but reverted on the next
launch. The unsaved mutation also left ``engine.cfg`` and disk out of
sync, so any later setter (``setDpi`` itself, ``cycleDpiPreset``) wrote
the same stale value back.
Three concrete changes:
* Route the device-reported value through ``clamp_dpi`` against the
resolved connected device so the floor/ceiling stay device-aware.
The previous handler stored the raw HID value with no validation.
* Persist via ``save_config`` and propagate the new config into
``engine.cfg`` so subsequent ``_resolved_connected_device()`` reads
observe the same value.
* Skip the write entirely when the device-reported value matches the
current ``settings.dpi`` -- the handler used to emit ``settingsChanged``
on every poll, churning every QML binding that depends on the
``settings`` keypath.
No HID round-trip is added: this handler reacts to a value the device
already reports, so calling ``engine.set_dpi`` here would only echo it
back.
Tests
- ``test_persists_new_device_dpi_to_disk`` -- new value flushed via
``save_config``.
- ``test_clamps_overrange_dpi_to_device_max`` /
``test_clamps_underrange_dpi_to_device_min`` -- clamp covers both
ends of the range.
- ``test_no_change_skips_save`` -- redundant reads do not churn disk
or signals.
- ``test_syncs_engine_cached_config`` -- ``engine.cfg`` mirrors the
persisted value.
- ``test_emits_dpi_from_device_with_clamped_value`` -- the
``dpiFromDevice`` signal carries the clamped value, not the raw one.
Co-authored-by: Cursor <cursoragent@cursor.com>1 parent 44880fb commit 3507483
2 files changed
Lines changed: 99 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
| |||
1273 | 1274 | | |
1274 | 1275 | | |
1275 | 1276 | | |
| 1277 | + | |
| 1278 | + | |
| 1279 | + | |
| 1280 | + | |
| 1281 | + | |
| 1282 | + | |
| 1283 | + | |
| 1284 | + | |
| 1285 | + | |
| 1286 | + | |
| 1287 | + | |
| 1288 | + | |
| 1289 | + | |
| 1290 | + | |
| 1291 | + | |
| 1292 | + | |
| 1293 | + | |
| 1294 | + | |
| 1295 | + | |
| 1296 | + | |
| 1297 | + | |
| 1298 | + | |
| 1299 | + | |
| 1300 | + | |
| 1301 | + | |
| 1302 | + | |
| 1303 | + | |
| 1304 | + | |
| 1305 | + | |
| 1306 | + | |
| 1307 | + | |
| 1308 | + | |
| 1309 | + | |
| 1310 | + | |
| 1311 | + | |
| 1312 | + | |
| 1313 | + | |
| 1314 | + | |
| 1315 | + | |
| 1316 | + | |
| 1317 | + | |
| 1318 | + | |
| 1319 | + | |
| 1320 | + | |
| 1321 | + | |
| 1322 | + | |
| 1323 | + | |
| 1324 | + | |
| 1325 | + | |
| 1326 | + | |
| 1327 | + | |
| 1328 | + | |
| 1329 | + | |
| 1330 | + | |
| 1331 | + | |
| 1332 | + | |
| 1333 | + | |
| 1334 | + | |
| 1335 | + | |
| 1336 | + | |
| 1337 | + | |
| 1338 | + | |
| 1339 | + | |
| 1340 | + | |
| 1341 | + | |
| 1342 | + | |
| 1343 | + | |
| 1344 | + | |
| 1345 | + | |
| 1346 | + | |
| 1347 | + | |
| 1348 | + | |
| 1349 | + | |
| 1350 | + | |
1276 | 1351 | | |
1277 | 1352 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1640 | 1640 | | |
1641 | 1641 | | |
1642 | 1642 | | |
1643 | | - | |
1644 | | - | |
| 1643 | + | |
| 1644 | + | |
| 1645 | + | |
| 1646 | + | |
| 1647 | + | |
| 1648 | + | |
| 1649 | + | |
| 1650 | + | |
| 1651 | + | |
| 1652 | + | |
| 1653 | + | |
| 1654 | + | |
| 1655 | + | |
| 1656 | + | |
| 1657 | + | |
| 1658 | + | |
| 1659 | + | |
| 1660 | + | |
| 1661 | + | |
| 1662 | + | |
| 1663 | + | |
| 1664 | + | |
| 1665 | + | |
1645 | 1666 | | |
1646 | | - | |
| 1667 | + | |
1647 | 1668 | | |
1648 | 1669 | | |
1649 | 1670 | | |
| |||
0 commit comments