Skip to content

Commit

Permalink
vkconfig3: Fix layer control env var handling
Browse files Browse the repository at this point in the history
Change-Id: I7b5daca6292b15741ac53cae51aabbd9a28c47b0
  • Loading branch information
christophe-lunarg committed Nov 11, 2024
1 parent 5f88fed commit e6d9ccf
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 37 deletions.
56 changes: 20 additions & 36 deletions vkconfig_core/layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,63 +86,48 @@ bool Layer::IsValid() const {
LayerControl Layer::GetActualControl() const {
if (this->type == LAYER_TYPE_IMPLICIT) {
if (!this->disable_env.empty()) {
if (this->disable_value.empty()) {
if (qEnvironmentVariableIsSet(this->disable_env.c_str())) {
return LAYER_CONTROL_OFF;
}
} else {
if (qgetenv(this->disable_env.c_str()).toStdString() == this->disable_value) {
return LAYER_CONTROL_OFF;
}
if (qEnvironmentVariableIsSet(this->disable_env.c_str())) {
return LAYER_CONTROL_OFF;
}
}

if (!this->enable_env.empty()) {
if (this->enable_value.empty()) {
if (qEnvironmentVariableIsSet(this->enable_env.c_str())) {
return LAYER_CONTROL_ON;
}
if (qgetenv(this->enable_env.c_str()).toStdString() == this->enable_value) {
return LAYER_CONTROL_ON;
} else {
if (qgetenv(this->enable_env.c_str()).toStdString() == this->enable_value) {
return LAYER_CONTROL_ON;
}
return LAYER_CONTROL_OFF; // Implicit layer which has an enable env must have it set to be enabled
}
}
}

return this->type == LAYER_TYPE_IMPLICIT ? LAYER_CONTROL_ON : LAYER_CONTROL_OFF;
return LAYER_CONTROL_ON; // Implicit layer
} else {
return LAYER_CONTROL_OFF; // Explicit layer
}
}

std::string Layer::GetActualControlTooltip() const {
if (this->type == LAYER_TYPE_IMPLICIT) {
if (!this->disable_env.empty()) {
const std::string& value = qgetenv(this->disable_env.c_str()).toStdString();
if (this->disable_value.empty()) {
if (qEnvironmentVariableIsSet(this->disable_env.c_str())) {
return format("'%s' is set", this->disable_env.c_str());
}
} else if (value == this->disable_value) {
if (qgetenv(this->disable_env.c_str()).toStdString() == this->disable_value) {
return format("'%s' is set to '%s'", this->disable_env.c_str(), value.c_str());
}
if (qEnvironmentVariableIsSet(this->disable_env.c_str())) {
return format("'%s' is set", this->disable_env.c_str());
}
}

if (!this->enable_env.empty()) {
const std::string& value = qgetenv(this->enable_env.c_str()).toStdString();
if (this->enable_value.empty()) {
if (qEnvironmentVariableIsSet(this->enable_env.c_str())) {
return format("'%s' is set", this->enable_env.c_str());
}
} else if (value == this->enable_value) {
if (qgetenv(this->enable_env.c_str()).toStdString() == this->enable_value) {
return format("'%s' is set to '%s'", this->enable_env.c_str(), value.c_str());
}
if (value == this->enable_value) {
return format("'%s' is set to '%s'.", this->enable_env.c_str(), value.c_str());
} else {
return format("Set '%s' to '%s' to enable '%s' by default.", this->enable_env.c_str(), this->enable_value.c_str(),
this->key.c_str());
}
}
}

return ::GetDescription(LAYER_CONTROL_AUTO);
return format("Set '%s' to disable '%s' by default.", this->disable_env.c_str(), this->key.c_str());
} else {
return ::GetDescription(LAYER_CONTROL_AUTO);
}
}

std::string Layer::FindPresetLabel(const SettingDataSet& settings) const {
Expand Down Expand Up @@ -338,7 +323,6 @@ bool Layer::Load(const Path& full_path_to_file, LayerType type, bool request_val
const QJsonObject& json_env_object = json_layer_object.value("disable_environment").toObject();
const QStringList keys = json_env_object.keys();
this->disable_env = keys[0].toStdString();
this->disable_value = ReadStringValue(json_env_object, this->disable_env.c_str());
}
if (json_layer_object.value("enable_environment") != QJsonValue::Undefined) {
const QJsonObject& json_env_object = json_layer_object.value("enable_environment").toObject();
Expand Down
1 change: 0 additions & 1 deletion vkconfig_core/layer.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ class Layer {
QJsonDocument profile;
std::string disable_env;
std::string enable_env;
std::string disable_value;
std::string enable_value;
bool is_32bits = false;
bool enabled = true;
Expand Down

0 comments on commit e6d9ccf

Please sign in to comment.