1111
1212#include < algorithm>
1313#include < chrono>
14+ #include < cmath>
1415#include < cstdlib>
1516#include < cstring>
1617#include < ctime>
2930
3031namespace {
3132
33+ std::optional<double > finiteDouble (const toml::node_view<const toml::node>& node) {
34+ auto v = node.value <double >();
35+ if (v && !std::isfinite (*v)) {
36+ return std::nullopt ;
37+ }
38+ return v;
39+ }
40+
3241 std::string expandUserPathString (const std::string& path) {
3342 if (path.empty ()) {
3443 return path;
@@ -862,7 +871,7 @@ void ConfigService::parseTableInto(const toml::table& tbl, Config& config, bool
862871 bar.attachPanels = *v;
863872 if (auto v = (*barTbl)[" thickness" ].value <int64_t >())
864873 bar.thickness = std::clamp (static_cast <std::int32_t >(*v), 10 , 300 );
865- if (auto v = ( *barTbl)[" background_opacity" ]. value < double >( ))
874+ if (auto v = finiteDouble (( *barTbl)[" background_opacity" ]))
866875 bar.backgroundOpacity = std::clamp (static_cast <float >(*v), 0 .0f , 1 .0f );
867876 if (auto v = (*barTbl)[" radius" ].value <int64_t >()) {
868877 const auto r = std::clamp (static_cast <std::int32_t >(*v), 0 , 500 );
@@ -892,7 +901,7 @@ void ConfigService::parseTableInto(const toml::table& tbl, Config& config, bool
892901 bar.shadow = *v;
893902 if (auto v = (*barTbl)[" contact_shadow" ].value <bool >())
894903 bar.contactShadow = *v;
895- if (auto v = ( *barTbl)[" scale" ]. value < double >( ))
904+ if (auto v = finiteDouble (( *barTbl)[" scale" ]))
896905 bar.scale = std::clamp (static_cast <float >(*v), 0 .5f , 4 .0f );
897906 if (auto * n = (*barTbl)[" start" ].as_array ())
898907 bar.startWidgets = readStringArray (*n);
@@ -910,13 +919,13 @@ void ConfigService::parseTableInto(const toml::table& tbl, Config& config, bool
910919 if (auto fgStr = (*barTbl)[" capsule_foreground" ].value <std::string>()) {
911920 bar.widgetCapsuleForeground = colorSpecFromConfigString (*fgStr);
912921 }
913- if (auto v = ( *barTbl)[" capsule_padding" ]. value < double >( )) {
922+ if (auto v = finiteDouble (( *barTbl)[" capsule_padding" ])) {
914923 bar.widgetCapsulePadding = std::clamp (static_cast <float >(*v), 0 .0f , 48 .0f );
915924 }
916- if (auto v = ( *barTbl)[" capsule_radius" ]. value < double >( )) {
925+ if (auto v = finiteDouble (( *barTbl)[" capsule_radius" ])) {
917926 bar.widgetCapsuleRadius = std::clamp (*v, 0.0 , 80.0 );
918927 }
919- if (auto v = ( *barTbl)[" capsule_opacity" ]. value < double >( )) {
928+ if (auto v = finiteDouble (( *barTbl)[" capsule_opacity" ])) {
920929 bar.widgetCapsuleOpacity = std::clamp (static_cast <float >(*v), 0 .0f , 1 .0f );
921930 }
922931 if (barTbl->contains (" capsule_border" )) {
@@ -959,7 +968,7 @@ void ConfigService::parseTableInto(const toml::table& tbl, Config& config, bool
959968 ovr.attachPanels = *v;
960969 if (auto v = (*monTbl)[" thickness" ].value <int64_t >())
961970 ovr.thickness = std::clamp (static_cast <std::int32_t >(*v), 10 , 300 );
962- if (auto v = ( *monTbl)[" background_opacity" ]. value < double >( ))
971+ if (auto v = finiteDouble (( *monTbl)[" background_opacity" ]))
963972 ovr.backgroundOpacity = std::clamp (static_cast <float >(*v), 0 .0f , 1 .0f );
964973 if (auto v = (*monTbl)[" radius" ].value <int64_t >())
965974 ovr.radius = std::clamp (static_cast <std::int32_t >(*v), 0 , 500 );
@@ -979,7 +988,7 @@ void ConfigService::parseTableInto(const toml::table& tbl, Config& config, bool
979988 ovr.padding = static_cast <std::int32_t >(*v);
980989 if (auto v = (*monTbl)[" widget_spacing" ].value <int64_t >())
981990 ovr.widgetSpacing = static_cast <std::int32_t >(*v);
982- if (auto v = ( *monTbl)[" scale" ]. value < double >( ))
991+ if (auto v = finiteDouble (( *monTbl)[" scale" ]))
983992 ovr.scale = std::clamp (static_cast <float >(*v), 0 .5f , 4 .0f );
984993 if (auto v = (*monTbl)[" shadow" ].value <bool >())
985994 ovr.shadow = *v;
@@ -1001,13 +1010,13 @@ void ConfigService::parseTableInto(const toml::table& tbl, Config& config, bool
10011010 if (auto fgStr = (*monTbl)[" capsule_foreground" ].value <std::string>()) {
10021011 ovr.widgetCapsuleForeground = colorSpecFromConfigString (*fgStr);
10031012 }
1004- if (auto v = ( *monTbl)[" capsule_padding" ]. value < double >( )) {
1013+ if (auto v = finiteDouble (( *monTbl)[" capsule_padding" ])) {
10051014 ovr.widgetCapsulePadding = std::clamp (*v, 0.0 , 48.0 );
10061015 }
1007- if (auto v = ( *monTbl)[" capsule_radius" ]. value < double >( )) {
1016+ if (auto v = finiteDouble (( *monTbl)[" capsule_radius" ])) {
10081017 ovr.widgetCapsuleRadius = std::clamp (*v, 0.0 , 80.0 );
10091018 }
1010- if (auto v = ( *monTbl)[" capsule_opacity" ]. value < double >( )) {
1019+ if (auto v = finiteDouble (( *monTbl)[" capsule_opacity" ])) {
10111020 ovr.widgetCapsuleOpacity = std::clamp (*v, 0.0 , 1.0 );
10121021 }
10131022 if (monTbl->contains (" capsule_border" )) {
@@ -1108,10 +1117,10 @@ void ConfigService::parseTableInto(const toml::table& tbl, Config& config, bool
11081117 // Parse [shell]
11091118 if (auto * shellTbl = tbl[" shell" ].as_table ()) {
11101119 auto & shell = config.shell ;
1111- if (auto v = ( *shellTbl)[" ui_scale" ]. value < double >( )) {
1120+ if (auto v = finiteDouble (( *shellTbl)[" ui_scale" ])) {
11121121 shell.uiScale = std::clamp (static_cast <float >(*v), 0 .5f , 4 .0f );
11131122 }
1114- if (auto v = ( *shellTbl)[" corner_radius_scale" ]. value < double >( )) {
1123+ if (auto v = finiteDouble (( *shellTbl)[" corner_radius_scale" ])) {
11151124 shell.cornerRadiusScale = std::clamp (static_cast <float >(*v), 0 .0f , 2 .0f );
11161125 }
11171126 if (auto v = (*shellTbl)[" font_family" ].value <std::string>()) {
@@ -1147,7 +1156,7 @@ void ConfigService::parseTableInto(const toml::table& tbl, Config& config, bool
11471156 if (auto enabled = (*animationTbl)[" enabled" ].value <bool >()) {
11481157 shell.animation .enabled = *enabled;
11491158 }
1150- if (auto v = ( *animationTbl)[" speed" ]. value < double >( )) {
1159+ if (auto v = finiteDouble (( *animationTbl)[" speed" ])) {
11511160 shell.animation .speed = std::clamp (static_cast <float >(*v), 0 .05f , 4 .0f );
11521161 }
11531162 }
@@ -1161,7 +1170,7 @@ void ConfigService::parseTableInto(const toml::table& tbl, Config& config, bool
11611170 if (auto v = (*shadowTbl)[" offset_y" ].value <int64_t >()) {
11621171 shell.shadow .offsetY = std::clamp (static_cast <std::int32_t >(*v), -40 , 40 );
11631172 }
1164- if (auto v = ( *shadowTbl)[" alpha" ]. value < double >( )) {
1173+ if (auto v = finiteDouble (( *shadowTbl)[" alpha" ])) {
11651174 shell.shadow .alpha = std::clamp (static_cast <float >(*v), 0 .0f , 1 .0f );
11661175 }
11671176 }
@@ -1372,9 +1381,9 @@ void ConfigService::parseTableInto(const toml::table& tbl, Config& config, bool
13721381 if (wp.transitions .empty ())
13731382 wp.transitions .push_back (WallpaperTransition::Fade);
13741383 }
1375- if (auto v = ( *wpTbl)[" transition_duration" ]. value < double >( ))
1384+ if (auto v = finiteDouble (( *wpTbl)[" transition_duration" ]))
13761385 wp.transitionDurationMs = std::clamp (static_cast <float >(*v), 100 .0f , 30000 .0f );
1377- if (auto v = ( *wpTbl)[" edge_smoothness" ]. value < double >( ))
1386+ if (auto v = finiteDouble (( *wpTbl)[" edge_smoothness" ]))
13781387 wp.edgeSmoothness = std::clamp (static_cast <float >(*v), 0 .0f , 1 .0f );
13791388 if (auto v = (*wpTbl)[" directory" ].value <std::string>())
13801389 wp.directory = expandUserPathString (*v);
@@ -1438,9 +1447,9 @@ void ConfigService::parseTableInto(const toml::table& tbl, Config& config, bool
14381447 auto & ov = config.backdrop ;
14391448 if (auto v = (*ovTbl)[" enabled" ].value <bool >())
14401449 ov.enabled = *v;
1441- if (auto v = ( *ovTbl)[" blur_intensity" ]. value < double >( ))
1450+ if (auto v = finiteDouble (( *ovTbl)[" blur_intensity" ]))
14421451 ov.blurIntensity = std::clamp (static_cast <float >(*v), 0 .0f , 1 .0f );
1443- if (auto v = ( *ovTbl)[" tint_intensity" ]. value < double >( ))
1452+ if (auto v = finiteDouble (( *ovTbl)[" tint_intensity" ]))
14441453 ov.tintIntensity = std::clamp (static_cast <float >(*v), 0 .0f , 1 .0f );
14451454 }
14461455
@@ -1461,7 +1470,7 @@ void ConfigService::parseTableInto(const toml::table& tbl, Config& config, bool
14611470 notif.position = *v;
14621471 if (auto v = notifTable[" layer" ].value <std::string>())
14631472 notif.layer = *v;
1464- if (auto v = notifTable[" background_opacity" ]. value < double >( ))
1473+ if (auto v = finiteDouble ( notifTable[" background_opacity" ]))
14651474 notif.backgroundOpacity = std::clamp (static_cast <float >(*v), 0 .0f , 1 .0f );
14661475 if (auto v = notifTable[" offset_x" ].value <int64_t >())
14671476 notif.offsetX = static_cast <int >(*v);
@@ -1495,7 +1504,7 @@ void ConfigService::parseTableInto(const toml::table& tbl, Config& config, bool
14951504 dock.padding = std::clamp (static_cast <std::int32_t >(*v), 0 , 100 );
14961505 if (auto v = (*dockTbl)[" item_spacing" ].value <int64_t >())
14971506 dock.itemSpacing = std::clamp (static_cast <std::int32_t >(*v), 0 , 100 );
1498- if (auto v = ( *dockTbl)[" background_opacity" ]. value < double >( ))
1507+ if (auto v = finiteDouble (( *dockTbl)[" background_opacity" ]))
14991508 dock.backgroundOpacity = std::clamp (static_cast <float >(*v), 0 .0f , 1 .0f );
15001509 if (auto v = (*dockTbl)[" radius" ].value <int64_t >()) {
15011510 const auto r = std::clamp (static_cast <std::int32_t >(*v), 0 , 500 );
@@ -1525,13 +1534,13 @@ void ConfigService::parseTableInto(const toml::table& tbl, Config& config, bool
15251534 dock.autoHide = *v;
15261535 if (auto v = (*dockTbl)[" reserve_space" ].value <bool >())
15271536 dock.reserveSpace = *v;
1528- if (auto v = ( *dockTbl)[" active_scale" ]. value < double >( ))
1537+ if (auto v = finiteDouble (( *dockTbl)[" active_scale" ]))
15291538 dock.activeScale = std::clamp (static_cast <float >(*v), 0 .1f , 1 .75f );
1530- if (auto v = ( *dockTbl)[" inactive_scale" ]. value < double >( ))
1539+ if (auto v = finiteDouble (( *dockTbl)[" inactive_scale" ]))
15311540 dock.inactiveScale = std::clamp (static_cast <float >(*v), 0 .1f , 1 .0f );
1532- if (auto v = ( *dockTbl)[" active_opacity" ]. value < double >( ))
1541+ if (auto v = finiteDouble (( *dockTbl)[" active_opacity" ]))
15331542 dock.activeOpacity = std::clamp (static_cast <float >(*v), 0 .0f , 1 .0f );
1534- if (auto v = ( *dockTbl)[" inactive_opacity" ]. value < double >( ))
1543+ if (auto v = finiteDouble (( *dockTbl)[" inactive_opacity" ]))
15351544 dock.inactiveOpacity = std::clamp (static_cast <float >(*v), 0 .0f , 1 .0f );
15361545 if (auto v = (*dockTbl)[" show_dots" ].value <bool >())
15371546 dock.showDots = *v;
@@ -1594,7 +1603,7 @@ void ConfigService::parseTableInto(const toml::table& tbl, Config& config, bool
15941603 if (auto v = (*audioTbl)[" enable_sounds" ].value <bool >()) {
15951604 audio.enableSounds = *v;
15961605 }
1597- if (auto v = ( *audioTbl)[" sound_volume" ]. value < double >( )) {
1606+ if (auto v = finiteDouble (( *audioTbl)[" sound_volume" ])) {
15981607 audio.soundVolume = std::clamp (static_cast <float >(*v), 0 .0f , 1 .0f );
15991608 }
16001609 if (auto v = (*audioTbl)[" volume_change_sound" ].value <std::string>()) {
@@ -1708,10 +1717,10 @@ void ConfigService::parseTableInto(const toml::table& tbl, Config& config, bool
17081717 if (auto v = (*nightlightTbl)[" stop_time" ].value <std::string>()) {
17091718 nightlight.stopTime = *v;
17101719 }
1711- if (auto v = ( *nightlightTbl)[" latitude" ]. value < double >( )) {
1720+ if (auto v = finiteDouble (( *nightlightTbl)[" latitude" ])) {
17121721 nightlight.latitude = *v;
17131722 }
1714- if (auto v = ( *nightlightTbl)[" longitude" ]. value < double >( )) {
1723+ if (auto v = finiteDouble (( *nightlightTbl)[" longitude" ])) {
17151724 nightlight.longitude = *v;
17161725 }
17171726 if (auto v = (*nightlightTbl)[" temperature_day" ].value <int64_t >()) {
@@ -1779,7 +1788,7 @@ void ConfigService::parseTableInto(const toml::table& tbl, Config& config, bool
17791788
17801789 // Parse [idle] and [idle.behavior.*]
17811790 if (auto * idleTbl = tbl[" idle" ].as_table ()) {
1782- if (auto v = ( *idleTbl)[" pre_action_fade_seconds" ]. value < double >( )) {
1791+ if (auto v = finiteDouble (( *idleTbl)[" pre_action_fade_seconds" ])) {
17831792 const double d = *v;
17841793 config.idle .preActionFadeSeconds = static_cast <float >(std::clamp (d, 0.0 , 120.0 ));
17851794 }
0 commit comments