Skip to content

feat: add sunrise/sunset scheduling support#72

Open
BaigHack3rss wants to merge 3 commits into
hyprwm:mainfrom
BaigHack3rss:main
Open

feat: add sunrise/sunset scheduling support#72
BaigHack3rss wants to merge 3 commits into
hyprwm:mainfrom
BaigHack3rss:main

Conversation

@BaigHack3rss

@BaigHack3rss BaigHack3rss commented Nov 29, 2025

Copy link
Copy Markdown

Updates

New Helper

  • NSunCalc: Added a helper that computes sunrise and sunset using the NOAA formulas.

Config Enhancements

  • ConfigManager extended with:
    • latitude and longitude options
    • Support for SUN-based profile times (sunrise/sunset–driven scheduling)

Behavior Changes

  • Emit a warning when two profiles share the same clock slot.
  • Skip profiles when required sun events (sunrise/sunset) are missing.

Testing Notes

  • Verified locally.
  • Original features continue to function.
  • Sunset computation works as expected.
  • Sunrise computation works as expected.
  • Automatic updating of sunrise/sunset times functions correctly.
    • The precise update interval is uncertain: likely on restart (possibly daily, but unverified).

- add NSunCalc helper that computes sunrise/sunset with NOAA formulas
- extend ConfigManager with latitude/longitude options and SUN-based profile times
- warn when two profiles share a clock slot and skip profiles with missing sun events

Tests: Tested locally; Original features work, sunset works according to
my knowledge, sunrise not tested (2:00 am right now)
BaigHack3rss and others added 2 commits March 19, 2026 06:56
Resolved conflicts in ConfigManager.cpp:
- Preserved sunrise/sunset scheduling feature
- Adopted upstream's graceful error handling (continue instead of RASSERT)
- Combined both approaches for robust sun time computation
Comment thread src/SunCalc.hpp
@@ -0,0 +1,116 @@
#ifndef SUNCALC_HPP
#define SUNCALC_HPP

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use #pragma once it's not 1978

Comment thread src/SunCalc.hpp
namespace NSunCalc {

struct SLocation {
double latitude; // degrees

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no uninitialized primitives

Comment thread src/SunCalc.hpp
static double calcSunEventUTC(int day, int month, int year, double latitude, double longitude, bool isSunrise);

// Shared constants
static constexpr double MINUTES_PER_HOUR = 60.0;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need to spit those into the hpp file they can stay in the cpp

Comment thread src/SunCalc.cpp
#include <limits>
#include <chrono>

namespace NSunCalc {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no namespace xxx { in .cpp files. Prefix your methods with NSunCalc or using namespace NSunCalc.

Comment thread src/SunCalc.cpp
}

// ------------------ NOAA Core Functions ------------------
// Based on NOAA solar position calculator reference implementation.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the reference implementation? If it's GPL, we can't do that.

Comment thread src/ConfigManager.cpp
const double timezoneHours = static_cast<double>(info.offset.count()) / SECONDS_PER_HOUR;
std::time_t nowT = std::chrono::system_clock::to_time_t(now);
std::tm localTm{};
localtime_r(&nowT, &localTm);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't there an STL fn for this

Comment thread src/ConfigManager.cpp
result.reserve(keys.size());

const double latitude = static_cast<double>(std::any_cast<Hyprlang::FLOAT>(m_config.getConfigValue("latitude")));
const double longitude = static_cast<double>(std::any_cast<Hyprlang::FLOAT>(m_config.getConfigValue("longitude")));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sc<> from hyprutils

Comment thread src/SunCalc.cpp
std::time_t tt = system_clock::to_time_t(shifted);

std::tm utc{};
gmtime_r(&tt, &utc);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't there an STL fn for this?

Comment thread src/SunCalc.cpp
int m = static_cast<int>(std::fmod(totalMinutes, MINUTES_PER_HOUR));

char buf[6];
std::snprintf(buf, sizeof(buf), "%02d:%02d", h, m);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ew, ouch, no C allowed here. std::format.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants