Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions assets/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -3641,6 +3641,10 @@
"description": "Show placeholder text when no window is focused instead of hiding the widget",
"label": "Show Empty Label"
},
"show-glyph": {
"description": "Show the widget glyph or custom image",
"label": "Show Glyph"
},
"show-icon": {
"description": "Show this widget's icon",
"label": "Show Icon"
Expand All @@ -3665,6 +3669,10 @@
"description": "Show the status card above the login box for unlock hints and auth prompts. Errors and Caps Lock warnings still appear when this is off.",
"label": "Unlock Hint"
},
"show-value": {
"description": "Show the current value next to the visualization",
"label": "Show Value"
},
"show-vpn-label": {
"description": "Replaces network label with VPN label in replace mode; adds VPN label next to VPN icon in both mode",
"label": "Show VPN Label"
Expand Down Expand Up @@ -3722,6 +3730,10 @@
"description": "Color role used for urgent workspaces; fixed hex colors are also supported",
"label": "Urgent Color"
},
"visualization": {
"description": "Gauge, graph, or no data visualization",
"label": "Visualization"
},
"vertical-format": {
"description": "Optional format used on vertical bars",
"label": "Vertical Format"
Expand Down
73 changes: 73 additions & 0 deletions src/config/config_migrations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ namespace noctalia::config {
constexpr int kCustomButtonCommandsMigrationVersion = 6;
constexpr int kDeadZoneActionsMigrationVersion = 7;
constexpr int kLockscreenLoginBoxDeprecatedSettingsMigrationVersion = 8;
constexpr int kSysmonPresentationMigrationVersion = 9;
constexpr std::int64_t kMaxBarRadius = 500;
constexpr std::array<std::string_view, 5> kBarRadiusKeys = {
"radius", "radius_top_left", "radius_top_right", "radius_bottom_left", "radius_bottom_right",
Expand Down Expand Up @@ -416,6 +417,66 @@ namespace noctalia::config {
});
}

template <typename OnChanged> void migrateSysmonPresentationSettings(toml::table& root, OnChanged&& onChanged) {
auto* widgets = root["widget"].as_table();
if (widgets == nullptr) {
return;
}

for (auto& [widgetName, widgetNode] : *widgets) {
auto* widget = widgetNode.as_table();
if (widget == nullptr || (*widget)["type"].value_or(std::string(widgetName.str())) != "sysmon") {
continue;
}

bool changed = false;
if (const auto showIcon = (*widget)["show_icon"].value<bool>(); showIcon.has_value()) {
if (!widget->contains("show_glyph")) {
widget->insert_or_assign("show_glyph", *showIcon);
}
widget->erase("show_icon");
changed = true;
}

const auto display = (*widget)["display"].value<std::string>();
if (display.has_value()) {
if (!widget->contains("visualization")) {
const std::string visualization = *display == "text" ? "none" : *display;
widget->insert_or_assign("visualization", visualization);
}
widget->erase("display");
changed = true;
}

if (const auto showLabel = (*widget)["show_label"].value<bool>(); showLabel.has_value()) {
if (!widget->contains("show_value")) {
bool showValue = *showLabel;
if (display == "text") {
showValue = true;
} else if (display == "none") {
showValue = false;
}
widget->insert_or_assign("show_value", showValue);
}
widget->erase("show_label");
changed = true;
} else if (display.has_value() && !widget->contains("show_value")) {
widget->insert_or_assign("show_value", *display != "none");
changed = true;
}

if (changed) {
onChanged("widget." + std::string(widgetName.str()));
}
}
}

void migrateSysmonPresentationSettingsSidecar(toml::table& root, schema::Diagnostics& diag) {
migrateSysmonPresentationSettings(root, [&diag](const std::string& path) {
diag.warn(path, "migrated sysmon presentation settings to their canonical names");
});
}

void migrateCustomButtonCommandsSidecar(toml::table& root, schema::Diagnostics& diag) {
migrateCustomButtonCommands(root, [&diag](const std::string& path, std::string_view message) {
diag.warn(path, std::string(message));
Expand Down Expand Up @@ -517,6 +578,11 @@ namespace noctalia::config {
.summary = "lockscreen: drop removed login box show_password_hint setting",
.apply = migrateLockscreenLoginBoxDeprecatedSettingsSidecar,
},
{
.toVersion = kSysmonPresentationMigrationVersion,
.summary = "widget: migrate sysmon presentation settings",
.apply = migrateSysmonPresentationSettingsSidecar,
},
};
return migrations;
}
Expand Down Expand Up @@ -625,6 +691,13 @@ namespace noctalia::config {
.message = "removed deprecated show_password_hint",
});
});
migrateSysmonPresentationSettings(root, [&issues](const std::string& path) {
issues.push_back({
.migrationVersion = kSysmonPresentationMigrationVersion,
.path = path,
.message = "sysmon display settings are now visualization, show_value, and show_glyph",
});
});
}

std::string legacyConfigIssueFingerprint(const LegacyConfigIssues& issues) {
Expand Down
16 changes: 16 additions & 0 deletions src/config/config_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,26 @@ namespace {
}
}

void validateSysmonWidgetSettings(std::string_view widgetName, const WidgetConfig& widget) {
if (widget.type != "sysmon") {
return;
}

const bool showGlyph = widget.getBool("show_glyph", true);
const bool showValue = widget.getBool("show_value", true);
const std::string visualization = widget.getString("visualization", "gauge");
if (!showGlyph && !showValue && visualization == "none") {
throw std::runtime_error(
"widget." + std::string(widgetName) + ": show_glyph, show_value, and visualization cannot all be disabled"
);
}
}

void validateWidgetSettings(std::string_view widgetName, const WidgetConfig& widget) {
validateWidgetColorSettings(widgetName, widget);
validateWidgetScaleSetting(widgetName, widget);
validateKeyboardLayoutWidgetSettings(widgetName, widget);
validateSysmonWidgetSettings(widgetName, widget);
}

std::optional<std::string> componentOwnerId(std::string_view ownerPath, std::string_view prefix) {
Expand Down
Loading