From c531aa6995f45853806666a97b4dbc726690e9dd Mon Sep 17 00:00:00 2001 From: Luca Weiss Date: Wed, 23 Aug 2023 23:12:16 +0200 Subject: [PATCH] Don't call applyEffect with bogus parameter for Custom Effect Previously when the "Custom Effect" combobox item was added and selected, this callback was called but because there's no item data we kind of just by conincidence did the correct things but also called the callback with RazerEffect::Off which again, by conincidence didn't have any bad side effects. Still for predictable behavior, handle this case better and more explicitly. --- src/ledwidget.cpp | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/src/ledwidget.cpp b/src/ledwidget.cpp index 0e357cb..f2af4f4 100644 --- a/src/ledwidget.cpp +++ b/src/ledwidget.cpp @@ -163,10 +163,26 @@ void LedWidget::colorButtonClicked() void LedWidget::fxComboboxChanged(int index) { auto *sender = qobject_cast(QObject::sender()); - libopenrazer::RazerCapability capability = sender->itemData(index).value(); + libopenrazer::RazerCapability capability; + + /* In theory we could remove half of this special handling because + * .value<>() will give us a default RazerCapability anyways if it's + * missing. But to be explicit let's do it like this. */ + bool isCustomEffect = sender->itemText(index) == "Custom Effect"; + if (!isCustomEffect) { + QVariant itemData = sender->itemData(index); + if (!itemData.canConvert()) + throw new std::runtime_error("Expected to be able to convert itemData into RazerCapability"); + capability = itemData.value(); + } else { + /* We're fine with getting an empty RazerCapability as we do want to + * reset all the extra buttons etc. We just don't want to actually do + * more than UI work with this though. */ + capability = libopenrazer::RazerCapability(); + } // Remove "Custom Effect" entry when you switch away from it - only gets added by the Custom Editor button - if (sender->itemText(index) != "Custom Effect") + if (!isCustomEffect) sender->removeItem(sender->findText("Custom Effect")); // Show/hide the color buttons @@ -191,7 +207,10 @@ void LedWidget::fxComboboxChanged(int index) findChild("radiobutton2")->show(); } - applyEffectStandardLoc(capability.getIdentifier()); + /* Actually go apply the effect in all cases, except for Custom Effect + * because there we handle this in the CustomEditor class */ + if (!isCustomEffect) + applyEffectStandardLoc(capability.getIdentifier()); } openrazer::RGB LedWidget::getColorForButton(int num)