diff --git a/vkconfig_core/configuration.cpp b/vkconfig_core/configuration.cpp index 7514de9af7..f084b7ce5d 100644 --- a/vkconfig_core/configuration.cpp +++ b/vkconfig_core/configuration.cpp @@ -44,7 +44,7 @@ static void AddApplicationEnabledParameters(std::vector& parameters) { bool found_applications_api = false; for (auto paramater : parameters) { - if (paramater.control != LAYER_CONTROL_APPLICATIONS_API) { + if (paramater.builtin != LAYER_BUILTIN_API) { continue; } @@ -54,16 +54,16 @@ static void AddApplicationEnabledParameters(std::vector& parameters) if (!found_applications_api) { Parameter applications_enabled_layers_api; - applications_enabled_layers_api.key = ::GetLabel(LAYER_CONTROL_APPLICATIONS_API); - applications_enabled_layers_api.control = LAYER_CONTROL_APPLICATIONS_API; + applications_enabled_layers_api.key = ::GetLabel(LAYER_BUILTIN_API); + applications_enabled_layers_api.builtin = LAYER_BUILTIN_API; + applications_enabled_layers_api.control = LAYER_CONTROL_DISCARD; // Until the Vulkan Loader is fixed applications_enabled_layers_api.overridden_rank = 998; - applications_enabled_layers_api.enabled = false; parameters.push_back(applications_enabled_layers_api); } bool found_applications_env = false; for (auto paramater : parameters) { - if (paramater.control != LAYER_CONTROL_APPLICATIONS_ENV) { + if (paramater.builtin != LAYER_BUILTIN_ENV) { continue; } @@ -73,10 +73,10 @@ static void AddApplicationEnabledParameters(std::vector& parameters) if (!found_applications_env) { Parameter applications_enabled_layers_env; - applications_enabled_layers_env.key = ::GetLabel(LAYER_CONTROL_APPLICATIONS_ENV); - applications_enabled_layers_env.control = LAYER_CONTROL_APPLICATIONS_ENV; + applications_enabled_layers_env.key = ::GetLabel(LAYER_BUILTIN_ENV); + applications_enabled_layers_env.builtin = LAYER_BUILTIN_ENV; + applications_enabled_layers_env.control = LAYER_CONTROL_DISCARD; // Until the Vulkan Loader is fixed applications_enabled_layers_env.overridden_rank = 999; - applications_enabled_layers_env.enabled = false; parameters.push_back(applications_enabled_layers_env); } } @@ -177,20 +177,35 @@ bool Configuration::Load(const Path& full_path, const LayerManager& layers) { const QJsonObject& json_layer_object = json_layers_array[layer_index].toObject(); Parameter parameter; - parameter.control = GetLayerControl(ReadStringValue(json_layer_object, "control").c_str()); - if (IsVisibleLayer(parameter.control)) { - parameter.key = ReadStringValue(json_layer_object, "name").c_str(); - } else { - parameter.key = ::GetLabel(parameter.control); + if (json_layer_object.value("name") != QJsonValue::Undefined) { + parameter.key = json_layer_object.value("name").toString().toStdString(); } - parameter.overridden_rank = ReadIntValue(json_layer_object, "rank"); - const std::string& version = ReadStringValue(json_layer_object, "version"); - parameter.api_version = version == "latest" ? Version::LATEST : Version(version.c_str()); - if (json_layer_object.value("manifest") != QJsonValue::Undefined) { - parameter.manifest = ReadString(json_layer_object, "manifest"); + if (json_layer_object.value("builtin") != QJsonValue::Undefined) { + parameter.builtin = ::GetLayerBuiltin(json_layer_object.value("builtin").toString().toStdString().c_str()); + parameter.key = ::GetLabel(parameter.builtin); + } + if (json_layer_object.value("control") != QJsonValue::Undefined) { + parameter.control = ::GetLayerControl(json_layer_object.value("control").toString().toStdString().c_str()); + } + if (json_layer_object.value("rank") != QJsonValue::Undefined) { + parameter.overridden_rank = json_layer_object.value("rank").toInt(); + } + if (json_layer_object.value("version") != QJsonValue::Undefined) { + const std::string& version = ReadStringValue(json_layer_object, "version"); + parameter.api_version = version == "latest" ? Version::LATEST : Version(version.c_str()); + } + + const Layer* layer = layers.Find(parameter.key, parameter.api_version); + + if (layer != nullptr) { + parameter.manifest = layer->manifest_path; } - if (json_layer_object.value("enabled") != QJsonValue::Undefined) { - parameter.enabled = ReadBoolValue(json_layer_object, "enabled"); + + if (json_layer_object.value("manifest") != QJsonValue::Undefined) { + std::string manifest_path = ReadString(json_layer_object, "manifest"); + if (layers.FindFromManifest(manifest_path) != nullptr) { + parameter.manifest = manifest_path; + } } const QJsonValue& json_platform_value = json_layer_object.value("platforms"); @@ -203,8 +218,6 @@ bool Configuration::Load(const Path& full_path, const LayerManager& layers) { parameter.setting_tree_state = json_layer_object.value("expanded_states").toVariant().toByteArray(); } - const Layer* layer = layers.Find(parameter.key, parameter.api_version); - if (layer != nullptr) { CollectDefaultSettingData(layer->settings, parameter.settings); } @@ -263,11 +276,15 @@ bool Configuration::Save(const Path& full_path, bool exporter) const { QJsonObject json_layer; json_layer.insert("name", parameter.key.c_str()); - json_layer.insert("rank", parameter.overridden_rank); + if (parameter.builtin != LAYER_BUILTIN_NONE) { + json_layer.insert("builtin", GetToken(parameter.builtin)); + } json_layer.insert("control", GetToken(parameter.control)); + json_layer.insert("rank", parameter.overridden_rank); json_layer.insert("version", parameter.api_version == Version::LATEST ? "latest" : parameter.api_version.str().c_str()); - json_layer.insert("manifest", parameter.manifest.RelativePath().c_str()); - json_layer.insert("enabled", parameter.enabled); + if (parameter.builtin == LAYER_BUILTIN_NONE) { + json_layer.insert("manifest", parameter.manifest.RelativePath().c_str()); + } SaveStringArray(json_layer, "platforms", GetPlatformTokens(parameter.platform_flags)); if (!exporter && !parameter.setting_tree_state.isEmpty()) { json_layer.insert("expanded_states", parameter.setting_tree_state.data()); @@ -400,7 +417,7 @@ bool Configuration::HasMissingLayer(const LayerManager& layers, std::vectorcontrol)) { + if (it->builtin != LAYER_BUILTIN_NONE) { continue; } diff --git a/vkconfig_core/configurations/3.0.0/Disable All Vulkan Layers.json b/vkconfig_core/configurations/3.0.0/Disable All Vulkan Layers.json index d063eb652d..125e75fce5 100644 --- a/vkconfig_core/configurations/3.0.0/Disable All Vulkan Layers.json +++ b/vkconfig_core/configurations/3.0.0/Disable All Vulkan Layers.json @@ -23,8 +23,7 @@ ], "layers": [ { - "control": "unordered_layer_location", - "enabled": false, + "builtin": "unordered_layer_location", "platforms": [ "WINDOWS", "LINUX", @@ -36,8 +35,7 @@ "version": "latest" }, { - "control": "application_enabled_layers", - "enabled": false, + "builtin": "application_enabled_layers", "platforms": [ "WINDOWS", "LINUX", diff --git a/vkconfig_core/configurator.cpp b/vkconfig_core/configurator.cpp index 29f05560be..03d8e03b6d 100644 --- a/vkconfig_core/configurator.cpp +++ b/vkconfig_core/configurator.cpp @@ -119,13 +119,15 @@ static QJsonObject CreateJsonSettingObject(const Configurator::LoaderSettings& l const Configurator::LoaderLayerSettings& layer = loader_settings.layers[j]; QJsonObject json_layer; - if (layer.control != LAYER_CONTROL_APPLICATIONS_API && layer.control != LAYER_CONTROL_APPLICATIONS_ENV) { + if (layer.builtin == LAYER_BUILTIN_NONE) { json_layer.insert("name", layer.key.c_str()); json_layer.insert("path", layer.path.c_str()); json_layer.insert("treat_as_implicit_manifest", layer.implicit); + json_layer.insert("control", ToLowerCase(::GetToken(layer.control)).c_str()); + } else { + json_layer.insert("control", ::GetToken(layer.builtin)); } - json_layer.insert("control", ToLowerCase(::GetToken(layer.control)).c_str()); json_layers.append(json_layer); } @@ -168,17 +170,19 @@ void Configurator::BuildLoaderSettings(const std::string& configuration_key, con LoaderLayerSettings loader_layer_settings; const Parameter& parameter = configuration->parameters[i]; - if (!parameter.enabled) { + if (!(parameter.platform_flags & (1 << VKC_PLATFORM))) { continue; } - if (!(parameter.platform_flags & (1 << VKC_PLATFORM))) { + if (parameter.control == LAYER_CONTROL_DISCARD) { continue; } - if (parameter.control == LAYER_CONTROL_APPLICATIONS_API || parameter.control == LAYER_CONTROL_APPLICATIONS_ENV) { - loader_layer_settings.control = parameter.control; - } else { + loader_layer_settings.key = parameter.key; + loader_layer_settings.builtin = parameter.builtin; + loader_layer_settings.control = parameter.control; + + if (parameter.builtin == LAYER_BUILTIN_NONE) { const Layer* layer = this->layers.Find(parameter.key, parameter.api_version); if (layer == nullptr) { continue; @@ -347,8 +351,7 @@ bool Configurator::WriteLayersSettings(OverrideArea override_area, const Path& l continue; } - if (parameter.control == LAYER_CONTROL_APPLICATIONS_API || parameter.control == LAYER_CONTROL_APPLICATIONS_ENV || - parameter.control == LAYER_CONTROL_OFF) { + if (parameter.control == LAYER_CONTROL_DISCARD || parameter.control == LAYER_CONTROL_OFF) { continue; } @@ -727,7 +730,7 @@ bool Configurator::HasActiveSettings() const { if (configuration != nullptr) { const Parameter* parameter = configuration->GetActiveParameter(); if (parameter != nullptr && configuration->override_layers) { - if (!IsVisibleLayer(parameter->control)) { + if (parameter->builtin != LAYER_BUILTIN_NONE) { return false; } else if (parameter->settings.empty()) { return false; diff --git a/vkconfig_core/configurator.h b/vkconfig_core/configurator.h index f769e93349..40d1cecdf3 100644 --- a/vkconfig_core/configurator.h +++ b/vkconfig_core/configurator.h @@ -48,6 +48,7 @@ class Configurator : public Serialize { std::string key; std::string path; LayerControl control = LAYER_CONTROL_AUTO; + LayerBuiltin builtin = LAYER_BUILTIN_NONE; bool implicit = false; }; diff --git a/vkconfig_core/layer.cpp b/vkconfig_core/layer.cpp index 3696a4b819..02d5249d63 100644 --- a/vkconfig_core/layer.cpp +++ b/vkconfig_core/layer.cpp @@ -83,6 +83,68 @@ bool Layer::IsValid() const { !implementation_version.empty(); } +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 (!this->enable_env.empty()) { + if (this->enable_value.empty()) { + if (qEnvironmentVariableIsSet(this->enable_env.c_str())) { + return LAYER_CONTROL_ON; + } + } else { + if (qgetenv(this->enable_env.c_str()).toStdString() == this->enable_value) { + return LAYER_CONTROL_ON; + } + } + } + } + + return this->type == LAYER_TYPE_IMPLICIT ? LAYER_CONTROL_ON : LAYER_CONTROL_OFF; +} + +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 (!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()); + } + } + } + } + + return ::GetDescription(LAYER_CONTROL_AUTO); +} + std::string Layer::FindPresetLabel(const SettingDataSet& settings) const { for (std::size_t i = 0, n = this->presets.size(); i < n; ++i) { if (HasPreset(settings, this->presets[i].settings)) return this->presets[i].label; @@ -276,13 +338,13 @@ 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()) == "1"; + 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(); const QStringList keys = json_env_object.keys(); this->enable_env = keys[0].toStdString(); - this->enable_value = ReadStringValue(json_env_object, this->enable_env.c_str()) == "1"; + this->enable_value = ReadStringValue(json_env_object, this->enable_env.c_str()); } const QJsonValue& json_features_value = json_layer_object.value("features"); diff --git a/vkconfig_core/layer.h b/vkconfig_core/layer.h index 4cf72beffa..3a45c60be6 100644 --- a/vkconfig_core/layer.h +++ b/vkconfig_core/layer.h @@ -26,6 +26,7 @@ #include "version.h" #include "path.h" #include "type_layer_type.h" +#include "type_layer_control.h" #include #include @@ -55,6 +56,9 @@ class Layer { bool IsValid() const; + LayerControl GetActualControl() const; + std::string GetActualControlTooltip() const; + std::string FindPresetLabel(const SettingDataSet& settings) const; SettingMeta* Instantiate(SettingMetaSet& meta_set, const std::string& key, const SettingType type); @@ -80,9 +84,9 @@ 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 disable_value; - bool enable_value; bool enabled = true; std::vector settings; diff --git a/vkconfig_core/layer_manager.cpp b/vkconfig_core/layer_manager.cpp index 35c6849ccc..fce9a722f3 100644 --- a/vkconfig_core/layer_manager.cpp +++ b/vkconfig_core/layer_manager.cpp @@ -30,11 +30,11 @@ std::vector GetImplicitLayerPaths() { #if VKC_ENV == VKC_ENV_WIN32 const std::vector &admin_registry_paths = - LoadRegistrySoftwareLayers("HKEY_LOCAL_MACHINE\\Software\\Khronos\\Vulkan\\ImplicitLayers"); + LoadRegistrySoftwareLayers("HKEY_LOCAL_MACHINE\\Software\\Khronos\\Vulkan\\ImplicitLayers", LAYER_TYPE_IMPLICIT); result.insert(result.begin(), admin_registry_paths.begin(), admin_registry_paths.end()); const std::vector &user_registry_paths = - LoadRegistrySoftwareLayers("HKEY_CURRENT_USER\\Software\\Khronos\\Vulkan\\ImplicitLayers"); + LoadRegistrySoftwareLayers("HKEY_CURRENT_USER\\Software\\Khronos\\Vulkan\\ImplicitLayers", LAYER_TYPE_IMPLICIT); result.insert(result.begin(), user_registry_paths.begin(), user_registry_paths.end()); // Search for drivers specific layers @@ -58,6 +58,7 @@ std::vector GetImplicitLayerPaths() { for (std::size_t i = 0, n = std::size(LAYERS_PATHS); i < n; ++i) { LayersPathInfo info; + info.type = LAYER_TYPE_IMPLICIT; info.path = LAYERS_PATHS[i]; result.push_back(info); } @@ -71,11 +72,11 @@ std::vector GetExplicitLayerPaths() { #if VKC_ENV == VKC_ENV_WIN32 const std::vector &admin_registry_paths = - LoadRegistrySoftwareLayers("HKEY_LOCAL_MACHINE\\Software\\Khronos\\Vulkan\\ExplicitLayers"); + LoadRegistrySoftwareLayers("HKEY_LOCAL_MACHINE\\Software\\Khronos\\Vulkan\\ExplicitLayers", LAYER_TYPE_EXPLICIT); result.insert(result.begin(), admin_registry_paths.begin(), admin_registry_paths.end()); const std::vector &user_registry_paths = - LoadRegistrySoftwareLayers("HKEY_CURRENT_USER\\Software\\Khronos\\Vulkan\\ExplicitLayers"); + LoadRegistrySoftwareLayers("HKEY_CURRENT_USER\\Software\\Khronos\\Vulkan\\ExplicitLayers", LAYER_TYPE_EXPLICIT); result.insert(result.begin(), user_registry_paths.begin(), user_registry_paths.end()); // Search for drivers specific layers @@ -99,6 +100,7 @@ std::vector GetExplicitLayerPaths() { for (std::size_t i = 0, n = std::size(LAYERS_PATHS); i < n; ++i) { LayersPathInfo info; + info.type = LAYER_TYPE_EXPLICIT; info.path = LAYERS_PATHS[i]; result.push_back(info); } @@ -327,11 +329,11 @@ void LayerManager::LoadAllInstalledLayers() { this->selected_layers.clear(); for (std::size_t group_index = 0, group_count = this->paths.size(); group_index < group_count; ++group_index) { - const LayerType layer_type = ::GetLayerType(static_cast(group_index)); + // const LayerType layer_type = ::GetLayerType(static_cast(group_index)); const std::vector &paths_group = this->paths[group_index]; for (std::size_t i = 0, n = paths_group.size(); i < n; ++i) { - this->LoadLayersFromPath(paths_group[i].path, layer_type); + this->LoadLayersFromPath(paths_group[i].path, paths_group[i].type); } } } diff --git a/vkconfig_core/parameter.h b/vkconfig_core/parameter.h index bc1e8fe86b..b5ea51fb48 100644 --- a/vkconfig_core/parameter.h +++ b/vkconfig_core/parameter.h @@ -23,6 +23,7 @@ #include "layer_manager.h" #include "setting.h" #include "type_layer_control.h" +#include "type_layer_builtin.h" #include @@ -46,6 +47,7 @@ struct Parameter { std::string key; LayerControl control = LAYER_CONTROL_AUTO; + LayerBuiltin builtin = LAYER_BUILTIN_NONE; int platform_flags = PLATFORM_DESKTOP_BIT; SettingDataSet settings; int overridden_rank = NO_RANK; @@ -53,7 +55,6 @@ struct Parameter { Path manifest; QByteArray setting_tree_state; // Recall editor tree state bool override_settings = true; - bool enabled = true; }; ParameterRank GetParameterOrdering(const LayerManager& layers, const Parameter& parameter); diff --git a/vkconfig_core/registry.cpp b/vkconfig_core/registry.cpp index 8622543c65..9cc430bcd8 100644 --- a/vkconfig_core/registry.cpp +++ b/vkconfig_core/registry.cpp @@ -104,6 +104,7 @@ static void LoadDeviceRegistry(DEVINST id, const QString &entry, std::vector LoadRegistrySystemLayers(const char *input_path) { return layers_paths; } -std::vector LoadRegistrySoftwareLayers(const char *path) { +std::vector LoadRegistrySoftwareLayers(const char *path, LayerType type) { std::vector result; QSettings settings(path, QSettings::NativeFormat); const QStringList &files = settings.allKeys(); @@ -211,6 +212,7 @@ std::vector LoadRegistrySoftwareLayers(const char *path) { Path path(files[i].toStdString()); LayersPathInfo info; + info.type = type; info.path = path.IsFile() ? path.AbsoluteDir() : path.AbsolutePath(); if (Found(result, info.path)) { diff --git a/vkconfig_core/registry.h b/vkconfig_core/registry.h index 090f2485da..1b7b2e81b6 100644 --- a/vkconfig_core/registry.h +++ b/vkconfig_core/registry.h @@ -35,6 +35,6 @@ void RemoveRegistryEntriesForLayers(QString override_file, QString settings_file std::vector LoadRegistrySystemLayers(const char* path); -std::vector LoadRegistrySoftwareLayers(const char* path); +std::vector LoadRegistrySoftwareLayers(const char* path, LayerType type); #endif // VKC_ENV == VKC_ENV_WIN32 diff --git a/vkconfig_core/test/test_configuration.cpp b/vkconfig_core/test/test_configuration.cpp index 8a28d4871d..2324e25e1e 100644 --- a/vkconfig_core/test/test_configuration.cpp +++ b/vkconfig_core/test/test_configuration.cpp @@ -204,12 +204,12 @@ TEST(test_configuration, create) { bool has_app_env = false; for (std::size_t i = 0, n = configuration.parameters.size(); i < n; ++i) { - if (configuration.parameters[i].control == LAYER_CONTROL_APPLICATIONS_API) { + if (configuration.parameters[i].builtin == LAYER_BUILTIN_API) { has_app_api = true; continue; } - if (configuration.parameters[i].control == LAYER_CONTROL_APPLICATIONS_ENV) { + if (configuration.parameters[i].builtin == LAYER_BUILTIN_ENV) { has_app_env = true; continue; } @@ -231,12 +231,12 @@ TEST(test_configuration, create_disabled) { bool has_app_env = false; for (std::size_t i = 0, n = configuration.parameters.size(); i < n; ++i) { - if (configuration.parameters[i].control == LAYER_CONTROL_APPLICATIONS_API) { + if (configuration.parameters[i].builtin == LAYER_BUILTIN_API) { has_app_api = true; continue; } - if (configuration.parameters[i].control == LAYER_CONTROL_APPLICATIONS_ENV) { + if (configuration.parameters[i].builtin == LAYER_BUILTIN_ENV) { has_app_env = true; continue; } diff --git a/vkconfig_core/test/test_type_layer_type.cpp b/vkconfig_core/test/test_type_layer_type.cpp index 67260367a0..ddf5ee8582 100644 --- a/vkconfig_core/test/test_type_layer_type.cpp +++ b/vkconfig_core/test/test_type_layer_type.cpp @@ -25,7 +25,7 @@ TEST(test_type_layer_type, convert_all) { for (int i = LAYER_TYPE_FIRST, n = LAYER_TYPE_COUNT; i < n; ++i) { const LayerType value = static_cast(i); - const char* string = GetToken(value); - EXPECT_EQ(value, GetLayerType(string)); + const char* string = ::GetToken(value); + EXPECT_EQ(value, ::GetLayerType(string)); } } diff --git a/vkconfig_core/type_layer_builtin.cpp b/vkconfig_core/type_layer_builtin.cpp new file mode 100644 index 0000000000..83c8ceac7c --- /dev/null +++ b/vkconfig_core/type_layer_builtin.cpp @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2020-2024 Valve Corporation + * Copyright (c) 2020-2024 LunarG, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: + * - Christophe Riccio + */ + +#include "type_layer_builtin.h" +#include "util.h" + +LayerBuiltin GetLayerBuiltin(const char* token) { + for (int i = LAYER_BUILTIN_FIRST, l = LAYER_BUILTIN_LAST; i <= l; ++i) { + const LayerBuiltin type = static_cast(i); + if (ToLowerCase(::GetToken(type)) == ToLowerCase(token)) { + return type; + } + } + + return LAYER_BUILTIN_NONE; +} + +const char* GetToken(LayerBuiltin builtin) { + static const char* TABLE[] = { + "N/A", // LAYER_BUILTIN_NONE + "application_enabled_layers", // LAYER_BUILTIN_API + "unordered_layer_location", // LAYER_BUILTIN_ENV + }; + static_assert(std::size(TABLE) == LAYER_BUILTIN_COUNT); + + return TABLE[builtin]; +} + +const char* GetLabel(LayerBuiltin builtin) { + static const char* TABLE[] = { + "N/A", // LAYER_BUILTIN_NONE + "Vulkan Layers from the Application Vulkan API", // LAYER_BUILTIN_API + "Vulkan Layers from the Application Environment Variables" // LAYER_BUILTIN_ENV + }; + static_assert(std::size(TABLE) == LAYER_BUILTIN_COUNT); + + return TABLE[builtin]; +} + +const char* GetDescription(LayerBuiltin builtin) { + static const char* + TABLE[] = + { + "N/A", // LAYER_BUILTIN_NONE + "Located and Enabled Layers using 'vkCreateInstance' by the Vulkan Application at launch", // LAYER_BUILTIN_API + "Located and Enabled Layers using 'VK_LOADER_LAYERS_ENABLE' Environment Variable by the Vulkan Application at " + "launch" // LAYER_BUILTIN_ENV + }; + static_assert(std::size(TABLE) == LAYER_BUILTIN_COUNT); + + return TABLE[builtin]; +} diff --git a/vkconfig_core/type_layer_builtin.h b/vkconfig_core/type_layer_builtin.h new file mode 100644 index 0000000000..b4f8379743 --- /dev/null +++ b/vkconfig_core/type_layer_builtin.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2020-2024 Valve Corporation + * Copyright (c) 2020-2024 LunarG, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: + * - Christophe Riccio + */ + +#pragma once + +enum LayerBuiltin { + LAYER_BUILTIN_NONE = 0, + LAYER_BUILTIN_API, + LAYER_BUILTIN_ENV, + + LAYER_BUILTIN_FIRST = LAYER_BUILTIN_NONE, + LAYER_BUILTIN_LAST = LAYER_BUILTIN_ENV, +}; + +enum { LAYER_BUILTIN_COUNT = LAYER_BUILTIN_LAST - LAYER_BUILTIN_FIRST + 1 }; + +LayerBuiltin GetLayerBuiltin(const char* token); +const char* GetToken(LayerBuiltin builtin); +const char* GetLabel(LayerBuiltin builtin); +const char* GetDescription(LayerBuiltin builtin); diff --git a/vkconfig_core/type_layer_control.cpp b/vkconfig_core/type_layer_control.cpp index c1f900ada0..4436208bcc 100644 --- a/vkconfig_core/type_layer_control.cpp +++ b/vkconfig_core/type_layer_control.cpp @@ -26,45 +26,15 @@ // These names are requied by the Vulkan Loader settings file const char* GetToken(LayerControl control) { - static const char* TOKENS[] = { - "Auto", // LAYER_CONTROL_AUTO - "Off", // LAYER_CONTROL_OFF - "On", // LAYER_CONTROL_ON - "application_enabled_layers", // LAYER_CONTROL_APPLICATIONS_API - "unordered_layer_location" // LAYER_CONTROL_APPLICATIONS_ENV + static const char* TABLE[] = { + "auto", // LAYER_CONTROL_AUTO + "on", // LAYER_CONTROL_ON + "off", // LAYER_CONTROL_OFF + "discard", // LAYER_CONTROL_DISCARD }; - static_assert(std::size(TOKENS) == LAYER_CONTROL_COUNT); + static_assert(std::size(TABLE) == LAYER_CONTROL_COUNT); - return TOKENS[control]; -} - -const char* GetLabel(LayerControl control) { - static const char* TOKENS[] = { - "N/A", // LAYER_CONTROL_AUTO - "N/A", // LAYER_CONTROL_OFF - "N/A", // LAYER_CONTROL_ON - "Vulkan Layers from the Application Vulkan API", // LAYER_CONTROL_APPLICATIONS_API - "Vulkan Layers from the Application Environment Variables" // LAYER_CONTROL_APPLICATIONS_ENV - }; - static_assert(std::size(TOKENS) == LAYER_CONTROL_COUNT); - - return TOKENS[control]; -} - -const char* GetDescription(LayerControl control) { - static const char* - TOKENS[] = - { - "Auto, let Vulkan applications or environment variables to enable or disable the layer", // LAYER_CONTROL_AUTO - "Force Off the layer, preventing its execution", // LAYER_CONTROL_OFF - "Force On the layer, insuring its execution", // LAYER_CONTROL_ON - "Located and Enabled Layers using 'vkCreateInstance' by the Vulkan Application at launch", // LAYER_CONTROL_APPLICATIONS_API - "Located and Enabled Layers using 'VK_LOADER_LAYERS_ENABLE' Environment Variable by the Vulkan Application at " - "launch" // LAYER_CONTROL_APPLICATIONS_ENV - }; - static_assert(std::size(TOKENS) == LAYER_CONTROL_COUNT); - - return TOKENS[control]; + return TABLE[control]; } LayerControl GetLayerControl(const char* token) { @@ -78,6 +48,27 @@ LayerControl GetLayerControl(const char* token) { return LAYER_CONTROL_AUTO; } -bool IsVisibleLayer(LayerControl control) { - return control >= LAYER_CONTROL_EXPLICIT_FIRST && control <= LAYER_CONTROL_EXPLICIT_LAST; +// These names are requied by the Vulkan Loader settings file +const char* GetLabel(LayerControl control) { + static const char* TABLE[] = { + "Auto", // LAYER_CONTROL_AUTO + "Enable", // LAYER_CONTROL_ON + "Disable", // LAYER_CONTROL_OFF + "Discard", // LAYER_CONTROL_DISCARD + }; + static_assert(std::size(TABLE) == LAYER_CONTROL_COUNT); + + return TABLE[control]; +} + +const char* GetDescription(LayerControl control) { + static const char* TOKENS[] = { + "Explicit layers are disabled by default and implicit layers are enabled by default.", // LAYER_CONTROL_AUTO + "Enable the layer, insuring its execution.", // LAYER_CONTROL_ON + "Disable the layer, preventing its execution.", // LAYER_CONTROL_OFF + "Discard the layer, don't notify the Vulkan Loader this layer exist.", // LAYER_CONTROL_DISCARD + }; + static_assert(std::size(TOKENS) == LAYER_CONTROL_COUNT); + + return TOKENS[control]; } diff --git a/vkconfig_core/type_layer_control.h b/vkconfig_core/type_layer_control.h index a45a7530cb..f429631218 100644 --- a/vkconfig_core/type_layer_control.h +++ b/vkconfig_core/type_layer_control.h @@ -22,29 +22,17 @@ enum LayerControl { LAYER_CONTROL_AUTO = 0, - LAYER_CONTROL_OFF, LAYER_CONTROL_ON, - LAYER_CONTROL_APPLICATIONS_API, - LAYER_CONTROL_APPLICATIONS_ENV, + LAYER_CONTROL_OFF, + LAYER_CONTROL_DISCARD, LAYER_CONTROL_FIRST = LAYER_CONTROL_AUTO, - LAYER_CONTROL_LAST = LAYER_CONTROL_APPLICATIONS_ENV, - - LAYER_CONTROL_EXPLICIT_FIRST = LAYER_CONTROL_AUTO, - LAYER_CONTROL_EXPLICIT_LAST = LAYER_CONTROL_ON, - - LAYER_CONTROL_IMPLICIT_FIRST = LAYER_CONTROL_AUTO, - LAYER_CONTROL_IMPLICIT_LAST = LAYER_CONTROL_OFF + LAYER_CONTROL_LAST = LAYER_CONTROL_DISCARD, }; enum { LAYER_CONTROL_COUNT = LAYER_CONTROL_LAST - LAYER_CONTROL_FIRST + 1 }; +LayerControl GetLayerControl(const char* token); const char* GetToken(LayerControl control); - const char* GetLabel(LayerControl control); - const char* GetDescription(LayerControl control); - -LayerControl GetLayerControl(const char* token); - -bool IsVisibleLayer(LayerControl control); diff --git a/vkconfig_core/type_layers_paths.cpp b/vkconfig_core/type_layers_paths.cpp index b9d1b46e8f..80260dda9f 100644 --- a/vkconfig_core/type_layers_paths.cpp +++ b/vkconfig_core/type_layers_paths.cpp @@ -22,14 +22,6 @@ #include -LayerType GetLayerType(LayersPaths Layers_paths_type) { - if (Layers_paths_type == LAYERS_PATHS_IMPLICIT) { - return LAYER_TYPE_IMPLICIT; - } else { - return LAYER_TYPE_EXPLICIT; - } -} - const char* GetLabel(LayersPaths Layers_paths_type) { static const char* TABLE[] = { "System Implicit Layers", // LAYERS_PATHS_IMPLICIT diff --git a/vkconfig_core/type_layers_paths.h b/vkconfig_core/type_layers_paths.h index 3cbe3b87e8..42f575777c 100644 --- a/vkconfig_core/type_layers_paths.h +++ b/vkconfig_core/type_layers_paths.h @@ -36,6 +36,4 @@ enum LayersPaths { enum { LAYERS_PATHS_COUNT = LAYERS_PATHS_LAST - LAYERS_PATHS_FIRST + 1 }; -LayerType GetLayerType(LayersPaths Layers_paths_type); - const char* GetLabel(LayersPaths Layers_paths_type); diff --git a/vkconfig_gui/tab.h b/vkconfig_gui/tab.h index 0cead4fad0..b00a2f8818 100644 --- a/vkconfig_gui/tab.h +++ b/vkconfig_gui/tab.h @@ -37,7 +37,7 @@ enum UpdateUIMode { UPDATE_REFRESH_UI, }; -struct Tab : public QObject { +class Tab : public QObject { Q_OBJECT public: diff --git a/vkconfig_gui/tab_about.h b/vkconfig_gui/tab_about.h index a9c442e195..be42762c84 100644 --- a/vkconfig_gui/tab_about.h +++ b/vkconfig_gui/tab_about.h @@ -22,7 +22,7 @@ #include "tab.h" -struct TabAbout : public Tab { +class TabAbout : public Tab { Q_OBJECT public: diff --git a/vkconfig_gui/tab_applications.h b/vkconfig_gui/tab_applications.h index 8d53dfcc2a..68534737c1 100644 --- a/vkconfig_gui/tab_applications.h +++ b/vkconfig_gui/tab_applications.h @@ -27,7 +27,7 @@ #include #include -struct TabApplications : public Tab { +class TabApplications : public Tab { Q_OBJECT public: diff --git a/vkconfig_gui/tab_configurations.cpp b/vkconfig_gui/tab_configurations.cpp index ea092f69c7..da4b5bc241 100644 --- a/vkconfig_gui/tab_configurations.cpp +++ b/vkconfig_gui/tab_configurations.cpp @@ -256,10 +256,6 @@ void TabConfigurations::UpdateUI_Layers(UpdateUIMode mode) { ConfigurationLayerWidget *layer_widget = new ConfigurationLayerWidget(this, parameter); - if (parameter.control == LAYER_CONTROL_APPLICATIONS_API || parameter.control == LAYER_CONTROL_APPLICATIONS_ENV) { - layer_widget->setToolTip(GetDescription(parameter.control)); - } - ui->configurations_layers_list->setItemWidget(item, layer_widget); if (configuration->selected_layer_name == parameter.key) { ui->configurations_layers_list->setCurrentItem(item); @@ -589,11 +585,11 @@ void TabConfigurations::OnSelectLayer(int currentRow) { assert(configuration != nullptr); if (configuration->selected_layer_name != layer_string) { - if (layer_string == ::GetLabel(LAYER_CONTROL_APPLICATIONS_API)) { + if (layer_string == ::GetLabel(LAYER_BUILTIN_API)) { if (!configurator.Get(HIDE_MESSAGE_NOTIFICATION_CONTROL_APPLICATION_API)) { QMessageBox message; message.setIcon(QMessageBox::Information); - message.setWindowTitle(::GetLabel(LAYER_CONTROL_APPLICATIONS_API)); + message.setWindowTitle(::GetLabel(LAYER_BUILTIN_API)); message.setText( "This item refers to Vulkan Layers not visible by Vulkan Configurator but at Vulkan Application launched, but " "enabled by the Vulkan Application at " @@ -601,7 +597,7 @@ void TabConfigurations::OnSelectLayer(int currentRow) { message.setInformativeText( format("If the Vulkan application is enabling a layer already controlled by Vulkan Configurator, the Vulkan " "Application setup is ignored.\n\nTo force ignoring these Vulkan Layers, set '%s' to 'Off'.", - ::GetLabel(LAYER_CONTROL_APPLICATIONS_API)) + ::GetLabel(LAYER_BUILTIN_API)) .c_str()); message.setCheckBox(new QCheckBox("Do not show again.")); message.exec(); @@ -609,11 +605,11 @@ void TabConfigurations::OnSelectLayer(int currentRow) { configurator.Set(HIDE_MESSAGE_NOTIFICATION_CONTROL_APPLICATION_API); } } - } else if (layer_string == ::GetLabel(LAYER_CONTROL_APPLICATIONS_ENV)) { + } else if (layer_string == ::GetLabel(LAYER_BUILTIN_ENV)) { if (!configurator.Get(HIDE_MESSAGE_NOTIFICATION_CONTROL_APPLICATION_ENV)) { QMessageBox message; message.setIcon(QMessageBox::Information); - message.setWindowTitle(::GetLabel(LAYER_CONTROL_APPLICATIONS_ENV)); + message.setWindowTitle(::GetLabel(LAYER_BUILTIN_ENV)); message.setText( "This item refers to Vulkan Layers not visible by Vulkan Configurator but at Vulkan Application launched, " "Vulkan Layers that are located using 'VK_ADD_LAYER_PATH' and enabled using 'VK_LOADER_LAYERS_ENABLE' " @@ -621,7 +617,7 @@ void TabConfigurations::OnSelectLayer(int currentRow) { message.setInformativeText(format("If the Vulkan application is enabling a layer already controlled by Vulkan " "Configurator, the Vulkan Application " "setup is ignored.\n\nTo force ignoring these Vulkan Layers, set '%s' to 'Off'.", - ::GetLabel(LAYER_CONTROL_APPLICATIONS_ENV)) + ::GetLabel(LAYER_BUILTIN_ENV)) .c_str()); message.setCheckBox(new QCheckBox("Do not show again.")); message.exec(); diff --git a/vkconfig_gui/tab_configurations.h b/vkconfig_gui/tab_configurations.h index 51d1c6c711..d497ed54f4 100644 --- a/vkconfig_gui/tab_configurations.h +++ b/vkconfig_gui/tab_configurations.h @@ -23,30 +23,11 @@ #include "tab.h" #include "settings_tree.h" #include "item.h" +#include "widget_resize_button.h" #include -#include -#include -class ResizeButton : public QPushButton { - Q_OBJECT - - public: - ResizeButton(QWidget *parent) : QPushButton(parent), parent(parent) {} - - bool eventFilter(QObject *o, QEvent *e) override { - if (e->type() == QEvent::Resize) { - const QRect enabled_button_rect = QRect(this->parent->width() - 24 - 5, 0, 24, 24); - this->setGeometry(enabled_button_rect); - } - return false; - } - - private: - QWidget *parent = nullptr; -}; - -struct TabConfigurations : public Tab { +class TabConfigurations : public Tab { Q_OBJECT public: diff --git a/vkconfig_gui/tab_diagnostics.h b/vkconfig_gui/tab_diagnostics.h index 173639c7e3..a0494892fa 100644 --- a/vkconfig_gui/tab_diagnostics.h +++ b/vkconfig_gui/tab_diagnostics.h @@ -22,7 +22,7 @@ #include "tab.h" -struct TabDiagnostics : public Tab { +class TabDiagnostics : public Tab { Q_OBJECT public: diff --git a/vkconfig_gui/tab_documentation.h b/vkconfig_gui/tab_documentation.h index deb8fcd994..2eff3b5043 100644 --- a/vkconfig_gui/tab_documentation.h +++ b/vkconfig_gui/tab_documentation.h @@ -22,7 +22,7 @@ #include "tab.h" -struct TabDocumentation : public Tab { +class TabDocumentation : public Tab { Q_OBJECT public: diff --git a/vkconfig_gui/tab_layers.cpp b/vkconfig_gui/tab_layers.cpp index da72b08918..3351669117 100644 --- a/vkconfig_gui/tab_layers.cpp +++ b/vkconfig_gui/tab_layers.cpp @@ -58,7 +58,6 @@ void TabLayers::UpdateUI_LayersPaths(UpdateUIMode ui_update_mode) { for (std::size_t group_index = configurator.layers.paths.size(); group_index > 0; --group_index) { const LayersPaths group_path = static_cast(group_index - 1); - const LayerType layer_type = ::GetLayerType(group_path); std::vector &paths_group = configurator.layers.paths[group_path]; for (std::size_t i = 0, n = paths_group.size(); i < n; ++i) { diff --git a/vkconfig_gui/tab_layers.h b/vkconfig_gui/tab_layers.h index 9cab5960aa..53110ff4a9 100644 --- a/vkconfig_gui/tab_layers.h +++ b/vkconfig_gui/tab_layers.h @@ -22,7 +22,7 @@ #include "tab.h" -struct TabLayers : public Tab { +class TabLayers : public Tab { Q_OBJECT public: diff --git a/vkconfig_gui/vkconfig.pro b/vkconfig_gui/vkconfig.pro index b262b341c4..4bf29fc93b 100644 --- a/vkconfig_gui/vkconfig.pro +++ b/vkconfig_gui/vkconfig.pro @@ -61,6 +61,7 @@ SOURCES += \ ../vkconfig_core/setting_string.cpp \ ../vkconfig_core/type_executable_mode.cpp \ ../vkconfig_core/type_hide_message.cpp \ + ../vkconfig_core/type_layer_builtin.cpp \ ../vkconfig_core/type_layer_control.cpp \ ../vkconfig_core/type_layer_type.cpp \ ../vkconfig_core/type_layers_paths.cpp \ @@ -74,6 +75,7 @@ SOURCES += \ ../vkconfig_core/version.cpp \ ../vkconfig_core/vulkan_info.cpp \ ../vkconfig_core/vulkan_util.cpp \ + widget_resize_button.cpp \ widget_layer_version.cpp \ widget_tab_configurations_layer.cpp \ widget_tab_layers_path.cpp \ @@ -137,6 +139,7 @@ HEADERS += \ ../vkconfig_core/setting_string.h \ ../vkconfig_core/type_executable_mode.h \ ../vkconfig_core/type_hide_message.h \ + ../vkconfig_core/type_layer_builtin.h \ ../vkconfig_core/type_layer_control.h \ ../vkconfig_core/type_layer_type.h \ ../vkconfig_core/type_layers_paths.h \ @@ -150,6 +153,7 @@ HEADERS += \ ../vkconfig_core/version.h \ ../vkconfig_core/vulkan_info.h \ ../vkconfig_core/vulkan_util.h \ + widget_resize_button.h \ widget_layer_version.h \ widget_tab_configurations_layer.h \ widget_tab_layers_path.h \ diff --git a/vkconfig_gui/widget_resize_button.cpp b/vkconfig_gui/widget_resize_button.cpp new file mode 100644 index 0000000000..a2408886f5 --- /dev/null +++ b/vkconfig_gui/widget_resize_button.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2020-2024 Valve Corporation + * Copyright (c) 2020-2024 LunarG, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: + * - Christophe Riccio + */ + +#include "widget_resize_button.h" + +ResizeButton::ResizeButton(QWidget *parent) : QPushButton(parent), parent(parent) {} + +bool ResizeButton::eventFilter(QObject *o, QEvent *e) { + (void)o; + + if (e->type() == QEvent::Resize) { + const QRect enabled_button_rect = QRect(this->parent->width() - 24 - 5, 0, 24, 24); + this->setGeometry(enabled_button_rect); + } + return false; +} diff --git a/vkconfig_gui/widget_resize_button.h b/vkconfig_gui/widget_resize_button.h new file mode 100644 index 0000000000..90f5856ac8 --- /dev/null +++ b/vkconfig_gui/widget_resize_button.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2020-2024 Valve Corporation + * Copyright (c) 2020-2024 LunarG, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: + * - Christophe Riccio + */ + +#pragma once + +#include +#include + +class ResizeButton : public QPushButton { + Q_OBJECT + + public: + ResizeButton(QWidget *parent); + + bool eventFilter(QObject *o, QEvent *e) override; + + private: + QWidget *parent = nullptr; +}; diff --git a/vkconfig_gui/widget_tab_configurations_layer.cpp b/vkconfig_gui/widget_tab_configurations_layer.cpp index 0a5d57b141..2cc76baf2c 100644 --- a/vkconfig_gui/widget_tab_configurations_layer.cpp +++ b/vkconfig_gui/widget_tab_configurations_layer.cpp @@ -21,38 +21,42 @@ #include "widget_tab_configurations_layer.h" #include "widget_setting.h" #include "tab_configurations.h" +#include "combo_box.h" #include "../vkconfig_core/configurator.h" ConfigurationLayerWidget::ConfigurationLayerWidget(TabConfigurations *tab, const Parameter ¶meter) - : tab(tab), layer_name(parameter.key) { + : layer_name(parameter.key), tab(tab) { const Configurator &configurator = Configurator::Get(); const Layer *layer = configurator.layers.Find(parameter.key, parameter.api_version); - if (IsVisibleLayer(parameter.control)) { - this->setEnabled(layer != nullptr && parameter.enabled); - - this->layer_state = new QComboBox(this); - this->layer_state->setSizeAdjustPolicy(QComboBox::AdjustToContents); - if (layer != nullptr) { - if (layer->type == LAYER_TYPE_EXPLICIT) { - for (int i = LAYER_CONTROL_EXPLICIT_FIRST; i <= LAYER_CONTROL_EXPLICIT_LAST; ++i) { - this->layer_state->addItem(GetToken(static_cast(i))); - this->layer_state->setItemData(i, GetDescription(static_cast(i)), Qt::ToolTipRole); - } - } else { - for (int i = LAYER_CONTROL_IMPLICIT_FIRST; i <= LAYER_CONTROL_IMPLICIT_LAST; ++i) { - this->layer_state->addItem(GetToken(static_cast(i))); - this->layer_state->setItemData(i, GetDescription(static_cast(i)), Qt::ToolTipRole); - } - } + this->layer_state = new ComboBox(this); + this->layer_state->setSizeAdjustPolicy(QComboBox::AdjustToContents); + + for (int i = LAYER_CONTROL_FIRST; i <= LAYER_CONTROL_LAST; ++i) { + const LayerControl layer_control = static_cast(i); + std::string label = ::GetLabel(layer_control); + /* + if (i == LAYER_CONTROL_AUTO && layer != nullptr) { + label += layer->GetActualControl() == LAYER_CONTROL_ON ? " (E)" : " (D)"; } - this->layer_state->setCurrentIndex(parameter.control); - this->layer_state->setToolTip(GetDescription(parameter.control)); - this->layer_state->setEnabled(layer != nullptr); - this->connect(this->layer_state, SIGNAL(currentIndexChanged(int)), this, SLOT(on_layer_state_currentIndexChanged(int))); + */ + this->layer_state->addItem(label.c_str()); + this->layer_state->setItemData(i, ::GetDescription(layer_control), Qt::ToolTipRole); + } + + this->layer_state->setCurrentIndex(parameter.control); + + if (parameter.control == LAYER_CONTROL_AUTO && layer != nullptr) { + std::string message = ::GetLabel(layer->GetActualControl()); + message += format(". %s", layer->GetActualControlTooltip().c_str()); + this->layer_state->setToolTip(message.c_str()); + } else { + this->layer_state->setToolTip(::GetDescription(parameter.control)); } + this->connect(this->layer_state, SIGNAL(currentIndexChanged(int)), this, SLOT(on_layer_state_currentIndexChanged(int))); + std::string decorated_name = parameter.key; if (layer != nullptr) { @@ -73,18 +77,21 @@ ConfigurationLayerWidget::ConfigurationLayerWidget(TabConfigurations *tab, const if (parameter.control == LAYER_CONTROL_OFF) { return; } - } else { - assert(layer != nullptr); - - if (layer->status != STATUS_STABLE) { - decorated_name += format(" (%s)", GetToken(layer->status)); - } } */ this->setText(decorated_name.c_str()); + + if (parameter.builtin != LAYER_BUILTIN_NONE) { + this->setToolTip(::GetDescription(parameter.builtin)); + } else { + assert(!parameter.manifest.Empty()); + this->setToolTip(parameter.manifest.AbsolutePath().c_str()); + } } bool ConfigurationLayerWidget::eventFilter(QObject *target, QEvent *event) { + (void)target; + QEvent::Type event_type = event->type(); if (event_type == QEvent::Wheel) { @@ -114,15 +121,15 @@ void ConfigurationLayerWidget::resizeEvent(QResizeEvent *event) { void ConfigurationLayerWidget::on_layer_state_currentIndexChanged(int index) { assert(index >= 0); - const std::string &text = this->layer_state->itemText(index).toStdString(); + const LayerControl control = static_cast(index); Configurator &configurator = Configurator::Get(); Configuration *configuration = configurator.GetActiveConfiguration(); Parameter *parameter = configuration->Find(this->layer_name); if (parameter != nullptr) { - parameter->control = GetLayerControl(text.c_str()); - this->layer_state->setToolTip(GetDescription(parameter->control)); + parameter->control = control; + this->layer_state->setToolTip(GetDescription(control)); configurator.Override(OVERRIDE_AREA_ALL); }