Skip to content

Commit 680663a

Browse files
committed
fix(config): restore user path expansion lost in 51265b5
1 parent 985871e commit 680663a

3 files changed

Lines changed: 41 additions & 35 deletions

File tree

src/config/schema/config_schema.cpp

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ namespace noctalia::config::schema {
9090
field(&LockscreenConfig::blurredDesktop, "blurred_desktop"),
9191
field(&LockscreenConfig::blurIntensity, "blur_intensity", kUnitRange),
9292
field(&LockscreenConfig::tintIntensity, "tint_intensity", kUnitRange),
93-
field(&LockscreenConfig::wallpaper, "wallpaper"),
93+
pathStringField(&LockscreenConfig::wallpaper, "wallpaper"),
9494
field(&LockscreenConfig::monitors, "monitors"),
9595
};
9696
return s;
@@ -401,7 +401,7 @@ namespace noctalia::config::schema {
401401
field(&DockConfig::showInstanceCount, "show_instance_count"),
402402
enumField(&DockConfig::launcherPosition, "launcher_position", kDockLauncherPositions),
403403
field(&DockConfig::launcherIcon, "launcher_icon"),
404-
field(&DockConfig::launcherCustomImage, "launcher_custom_image"),
404+
pathStringField(&DockConfig::launcherCustomImage, "launcher_custom_image"),
405405
field(&DockConfig::launcherCustomImageColorize, "launcher_custom_image_colorize"),
406406
field(&DockConfig::pinned, "pinned"),
407407
field(&DockConfig::monitors, "monitors"),
@@ -643,36 +643,6 @@ namespace noctalia::config::schema {
643643
);
644644
}
645645

646-
// String holding a filesystem path: ~ and $VARS expand on read, emitted raw.
647-
template <typename Struct> Field<Struct> pathStringField(std::string Struct::* member, std::string_view key) {
648-
return custom<Struct>(
649-
key,
650-
[member, key](const toml::table& tbl, Struct& out, std::string_view, Diagnostics&) {
651-
if (auto v = tbl[key].value<std::string>()) {
652-
out.*member = v->empty() ? *v : FileUtils::expandUserPath(*v).string();
653-
}
654-
},
655-
[member, key](toml::table& tbl, const Struct& in) { tbl.insert_or_assign(key, in.*member); }
656-
);
657-
}
658-
659-
template <typename Struct>
660-
Field<Struct> optionalPathStringField(std::optional<std::string> Struct::* member, std::string_view key) {
661-
return custom<Struct>(
662-
key,
663-
[member, key](const toml::table& tbl, Struct& out, std::string_view, Diagnostics&) {
664-
if (auto v = tbl[key].value<std::string>()) {
665-
out.*member = v->empty() ? *v : FileUtils::expandUserPath(*v).string();
666-
}
667-
},
668-
[member, key](toml::table& tbl, const Struct& in) {
669-
if ((in.*member).has_value()) {
670-
tbl.insert_or_assign(key, *(in.*member));
671-
}
672-
}
673-
);
674-
}
675-
676646
template <typename Struct>
677647
Field<Struct> optionalBoolField(std::optional<bool> Struct::* member, std::string_view key) {
678648
return custom<Struct>(

src/config/schema/field.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "config/config_types.h"
44
#include "config/schema/diagnostics.h"
55
#include "core/toml.h"
6+
#include "util/file_utils.h"
67
#include "util/string_utils.h"
78

89
#include <cmath>
@@ -218,6 +219,36 @@ namespace noctalia::config::schema {
218219
return Field<Struct>{key, std::move(read), std::move(write)};
219220
}
220221

222+
// String holding a filesystem path: ~ and $VARS expand on read, emitted raw.
223+
template <typename Struct> Field<Struct> pathStringField(std::string Struct::* member, std::string_view key) {
224+
return custom<Struct>(
225+
key,
226+
[member, key](const toml::table& tbl, Struct& out, std::string_view, Diagnostics&) {
227+
if (auto v = tbl[key].value<std::string>()) {
228+
out.*member = v->empty() ? *v : FileUtils::expandUserPath(*v).string();
229+
}
230+
},
231+
[member, key](toml::table& tbl, const Struct& in) { tbl.insert_or_assign(key, in.*member); }
232+
);
233+
}
234+
235+
template <typename Struct>
236+
Field<Struct> optionalPathStringField(std::optional<std::string> Struct::* member, std::string_view key) {
237+
return custom<Struct>(
238+
key,
239+
[member, key](const toml::table& tbl, Struct& out, std::string_view, Diagnostics&) {
240+
if (auto v = tbl[key].value<std::string>()) {
241+
out.*member = v->empty() ? *v : FileUtils::expandUserPath(*v).string();
242+
}
243+
},
244+
[member, key](toml::table& tbl, const Struct& in) {
245+
if ((in.*member).has_value()) {
246+
tbl.insert_or_assign(key, *(in.*member));
247+
}
248+
}
249+
);
250+
}
251+
221252
// A keyless field that runs cross-field logic after all leaf reads (enforcing
222253
// invariants a per-field codec can't express, e.g. day > night). Writes
223254
// nothing. Place it last in a Schema so it sees the fully-read struct.

src/shell/bar/widget_factory.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
#include "shell/bar/widgets/workspaces_widget.h"
4747
#include "system/format_units.h"
4848
#include "ui/style.h"
49+
#include "util/file_utils.h"
4950
#include "util/string_utils.h"
5051
#include "wayland/wayland_connection.h"
5152

@@ -90,9 +91,12 @@ namespace {
9091
}
9192

9293
WidgetCustomImage customImageFor(const WidgetConfig* wc) {
94+
if (wc == nullptr) {
95+
return {};
96+
}
9397
return WidgetCustomImage{
94-
.path = wc != nullptr ? wc->getString("custom_image", "") : std::string{},
95-
.colorize = wc != nullptr ? wc->getBool("custom_image_colorize", false) : false,
98+
.path = FileUtils::expandUserPath(wc->getString("custom_image", "")).string(),
99+
.colorize = wc->getBool("custom_image_colorize", false),
96100
};
97101
}
98102

@@ -468,7 +472,8 @@ std::unique_ptr<Widget> WidgetFactory::create(
468472
if (type == "sysmon") {
469473
const bool verticalBar = barPosition == "left" || barPosition == "right";
470474
std::string statStr = wc != nullptr ? wc->getString("stat", "cpu_usage") : std::string("cpu_usage");
471-
std::string path = wc != nullptr ? wc->getString("path", "/") : std::string("/");
475+
std::string path =
476+
FileUtils::expandUserPath(wc != nullptr ? wc->getString("path", "/") : std::string("/")).string();
472477
SysmonStat stat = SysmonStat::CpuUsage;
473478
if (statStr == "cpu_temp") {
474479
stat = SysmonStat::CpuTemp;

0 commit comments

Comments
 (0)