Repository navigation
Conversation
Rerunning the wizard rebuilt the zones from the saved positions but reset the zone placement form (LED counts, offset, thickness, stand width, margins, invert order, skip corners) to defaults. Save these per display in the profile when the wizard finishes and load them back when it is started from existing settings. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
psieg
left a comment
There was a problem hiding this comment.
Thanks for the PR! Left a few comments on BottomLeds handling, unapplied edits / existing profiles, profile resets, and INI value loading.
Made with AI
| load(QStringLiteral("TopLeds"), settings.topLeds); | ||
| load(QStringLiteral("SideLeds"), settings.sideLeds); |
There was a problem hiding this comment.
BottomLeds (sbBottomLeds) is omitted from MonitorSettings, saveMonitorSettings(), loadStoredMonitorSettings(), and storeMonitorSettings(). Instead, onMonitor_currentIndexChanged() relies on sbTopLeds->setValue() / sbSideLeds->setValue() emitting valueChanged to recompute sbBottomLeds.
This breaks in several cases:
- No-op
setValue()whenTopLeds == 3andSideLeds == 2(matching.uidefaults, e.g. 7-LED Cassiopeia3/2/0, 9-LED Andromeda3/2/2, custom3/2/N, or legacy profiles withoutZonePlacement/*keys yet): neither spinbox emitsvalueChanged, leavingsbBottomLedsstuck at3. Clicking Apply after adjusting thickness or margins will then unexpectedly generate 3 bottom zones. - Switching displays in
cbMonitorSelectwhen two displays sharetopLedsandsideLeds(e.g. Display 14/2/2and Display 24/2/0):sbNumberOfLedsupdates with signals blocked, neithertopLedsnorsideLedschanges, andsbBottomLedsremains stale from the previous display. - Direct
sbBottomLeds/sbNumberOfLedsedits don't round-trip, sincesbBottomLedsis editable before clicking Apply andsbNumberOfLedscan add or remove zones independently.
Persisting BottomLeds explicitly and setting _ui->sbBottomLeds directly in onMonitor_currentIndexChanged() (with signals blocked on sbTopLeds/sbSideLeds while populating the form) avoids all of these cases.
| _transSettings->zonePlacementValues.clear(); | ||
| for (QMap<int, MonitorSettings>::const_iterator it = _screens.constBegin(); it != _screens.constEnd(); ++it) | ||
| storeMonitorSettings(it.value(), it.key()); |
There was a problem hiding this comment.
Two subtleties around when values are captured and persisted:
- Asymmetric handling of unapplied edits:
saveMonitorSettings()only runs on preset buttons or Apply, exceptonTopLeds_valueChanged()andonSideLeds_valueChanged()mutate_screens[currentIndex].topLeds/.sideLedsimmediately even if Apply is never clicked (whereas edits toThickness,StandWidth, margins,Offset,InvertOrder, andSkipCornerswithout clicking Apply are discarded). - Existing pre-PR profiles: If a user with an existing profile (no
ZonePlacement/*keys yet) steps throughZonePlacementPageuntouched (e.g., only changing device settings or white balance),validatePage()still writes the.uidefaults (TopLeds=3,SideLeds=2,Thickness=15,StandWidth=33, ...) into the profile INI even though the existing zones weren't built with them.
| for (QVariantMap::const_iterator it = _transSettings->zonePlacementValues.constBegin(); | ||
| it != _transSettings->zonePlacementValues.constEnd(); ++it) | ||
| Settings::setValue(it.key(), it.value()); |
There was a problem hiding this comment.
Clicking "Reset to default" on a profile calls Settings::resetDefaults() -> Settings::initCurrentProfile(true), which resets LED positions, sizes, coefficients, and other profile options. Because ZonePlacement/* is written directly via Settings::setValue() without Settings knowing about the [ZonePlacement] group, stale ZonePlacement/Display*/* keys will remain in the profile .ini file after a reset.
| auto load = [screenIdx](const QString& name, auto& field) { | ||
| const QVariant value = Settings::value(zonePlacementKey(screenIdx, name)); | ||
| if (value.isValid()) | ||
| field = value.value<std::remove_reference_t<decltype(field)>>(); | ||
| }; |
There was a problem hiding this comment.
A few edge cases when loading and applying stored values:
QVariant::isValid()vs. conversion failure:QSettings::IniFormatreads INI entries back asQVariant(QString). An empty or malformed value (e.g.Thickness=orThickness=abc) still hasvalue.isValid() == true, andvalue.value<int>()/value.value<double>()silently evaluates to0without checking conversion success (toInt(&ok)/toDouble(&ok)), clobbering non-zero defaults (Thickness = 15,StandWidth = 33).- Unclamped values: Loaded values aren't clamped to widget bounds (e.g.,
sbThicknessis1..50, margins are0.0..40.0), so_screens[idx]can retain and re-save an out-of-range value like0while the spinbox clamps its display to1%. - Minor ordering note: In
onMonitor_currentIndexChanged()(now also called on init at line 120),resetNewAreaRect()runs beforedoubleSpinBox_*Marginare populated fromsettings, soscreenRect()uses0%on init or the previous monitor's margins when switching displays (and lines 108/117 ininitializePage()are also duplicated when_isInitFromSettingsis true).
psieg
left a comment
There was a problem hiding this comment.
One more note on multi-monitor screen enumeration order and reusing the screen-matching logic from the grabbing rework.
Made with AI
| static QString zonePlacementKey(const int screenIdx, const QString& name) | ||
| { | ||
| return QStringLiteral("ZonePlacement/Display%1/%2").arg(QString::number(screenIdx + 1), name); | ||
| } |
There was a problem hiding this comment.
Multi-monitor screen enumeration order:
Keying ZonePlacement/Display%1/* by screenIdx (QGuiApplication::screens() enumeration order) decouples the saved form values from the [LED_i] zones on the same page, which are matched to screens geometrically via settings.screen->geometry().contains(areaGeometry.center()) (and screenRect() also re-queries QGuiApplication::screens().value(currentIndex) instead of using settings.screen->geometry()). If OS/driver display enumeration order changes across runs (e.g., primary monitor toggle, DisplayPort reconnect order, or connector scan order), Display1/Display2 form values swap monitors while the GrabWidget zones stay with their physical screen geometry.
How the grabbing rework solved this:
In commit 8ac5d0a4 / PR #644, GrabManager, GrabberBase::screenOfWidget(), GrabWidget::deviceFrameGeometry(), and Settings::migrateProfileCoordinates() dropped QGuiApplication::screens() list indices in favor of:
- Keying in-memory per-screen state by
const QScreen*rather than index. - Matching across runs/APIs by virtual-desktop
QRect/ center containment (geom.contains(center)) and display/output identity (QScreen::name(), etc.).
Applying that same pattern here:
- Treat
Display1..Nas saved screen records storingGeometry(plus fallback identity such asSerialNumberandName), and match them 1-to-1 againstQGuiApplication::screens()on load (saved.geometry == screen->geometry(), thenscreen->geometry().contains(saved.geometry.center()), thenserialNumber()/name()). This guarantees whicheverQScreenreceives the savedGrabWidgets also receives the matchingZonePlacementvalues. - In
screenRect(), read_screens[_ui->cbMonitorSelect->currentIndex()].screen->geometry()directly instead of re-indexingQGuiApplication::screens(). - Clear the
[ZonePlacement]group before writing current screens so stale entries from unplugged monitors don't linger and false-match byNamelater.
Sharing & reuse:
It may be worth extracting a small shared screen-lookup helper (e.g., ScreenUtils in Software/src/) so ZonePlacementPage, GlobalColorCoefPage, GrabManager, GrabWidget, and Settings can share:
QScreen*matching by logical geometry/center + fallback identity (serialNumber()/name())- Deterministic spatial sorting of
QGuiApplication::screens()for consistentDisplay 1/Display 2numbering across both wizard pages (ZonePlacementPageandGlobalColorCoefPage) - The Windows
HMONITOR->MONITORINFOEX::szDevice->QScreen*lookup currently duplicated betweenGrabWidget::deviceFrameGeometry()andSettings::migrateProfileCoordinates()
(GrabberBase::screenOfWidget() can stay separate since it operates on ScreenInfo / native capture handles and physical rects, and [ZonePlacement] persistence belongs in Settings so resetDefaults() can clear it too.)
Rerunning the wizard rebuilt the zones from the saved positions but reset the zone placement form (LED counts, offset, thickness, stand width, margins, invert order, skip corners) to defaults. Save these per display in the profile when the wizard finishes and load them back when it is started from existing settings.
Not tested in real hardware yet.