Lock screen (amane ipc call lock): the wallpaper blurred, the date with the weather, a big clock, Hyprland's splash, the music with controls, the next event, new notifications, the battery, ~/.face and the password (PAM); lock.look.* and lock.show.* settings
This commit is contained in:
+55
-2
@@ -71,6 +71,17 @@ impl Service for Clock {
|
||||
}
|
||||
}
|
||||
|
||||
impl Clock {
|
||||
// local seconds since 1970, 0 until the first tick
|
||||
pub fn now(&self) -> i64 {
|
||||
self.now
|
||||
}
|
||||
|
||||
pub fn avatar(&self) -> Option<&str> {
|
||||
self.avatar.as_deref()
|
||||
}
|
||||
}
|
||||
|
||||
fn now_unix() -> i64 {
|
||||
SystemTime::now().duration_since(UNIX_EPOCH).map_or(0, |since| since.as_secs() as i64)
|
||||
}
|
||||
@@ -92,7 +103,7 @@ fn home_dir() -> PathBuf {
|
||||
}
|
||||
|
||||
// a path from the settings, ~/ meaning the home folder
|
||||
fn expanded(path: &str) -> PathBuf {
|
||||
pub fn expanded(path: &str) -> PathBuf {
|
||||
match path.strip_prefix("~/") {
|
||||
Some(rest) => home_dir().join(rest),
|
||||
None => PathBuf::from(path),
|
||||
@@ -1049,6 +1060,48 @@ fn month_name(month: u32) -> &'static str {
|
||||
MONTHS[(month as usize + 11) % 12]
|
||||
}
|
||||
|
||||
// "Tuesday, 20 October" for local seconds `now`
|
||||
pub fn date_words(now: i64) -> String {
|
||||
let days = now.div_euclid(86_400);
|
||||
let (_, month, day) = parse::civil_from_days(days);
|
||||
|
||||
format!("{}, {day} {}", weekday_name(days), month_name(month))
|
||||
}
|
||||
|
||||
// the weather now as its icon and "14° Munich", once it's known
|
||||
pub fn weather_now() -> Option<(Glyph, String)> {
|
||||
let forecast = Forecast::read();
|
||||
let weather = forecast.weather.as_ref()?;
|
||||
|
||||
Some((sky_glyph(weather.code, weather.is_day), format!("{:.0}° {}", weather.temperature, settings::city())))
|
||||
}
|
||||
|
||||
// the soonest event that hasn't ended at local seconds `now`: when ("Tomorrow 09:30"), its title and its calendar's colour
|
||||
pub fn next_event(now: i64) -> Option<(String, String, Option<Color>)> {
|
||||
let agenda = Agenda::read();
|
||||
let entry = agenda.events.iter().filter(|entry| entry.end > now).min_by_key(|entry| entry.start)?;
|
||||
|
||||
let today = now.div_euclid(86_400);
|
||||
let day = entry.start.div_euclid(86_400).max(today);
|
||||
|
||||
let (_, month, number) = parse::civil_from_days(day);
|
||||
|
||||
let named = match day - today {
|
||||
0 => String::from("Today"),
|
||||
1 => String::from("Tomorrow"),
|
||||
2..=6 => String::from(weekday_name(day)),
|
||||
_ => format!("{number} {}", month_name(month)),
|
||||
};
|
||||
|
||||
let when = match (entry.all_day, entry.start <= now) {
|
||||
(true, _) => named,
|
||||
(false, true) => format!("Now until {}", hhmm(entry.end)),
|
||||
(false, false) => format!("{named} {}", hhmm(entry.start)),
|
||||
};
|
||||
|
||||
Some((when, entry.summary.clone(), entry.color))
|
||||
}
|
||||
|
||||
fn sky_glyph(code: u32, day: bool) -> Glyph {
|
||||
match parse::sky(code) {
|
||||
Sky::Clear if day => Glyph::Sun,
|
||||
@@ -1093,7 +1146,7 @@ pub fn height() -> f32 {
|
||||
2.0 * layout::pad() + settings::avatar_size() + gap + middle_h() + gap + 1.0 + gap + calendar_h()
|
||||
}
|
||||
|
||||
fn name() -> String {
|
||||
pub fn name() -> String {
|
||||
let user = env::var("USER").unwrap_or_default();
|
||||
let mut letters = user.chars();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user