1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-15 19:57:36 +00:00

WindowServer: Make the menubar clock work again in the post-kernel world.

This is actually so much better. Grabbing directly at the RTC was silly. :^)
This commit is contained in:
Andreas Kling 2019-02-17 01:05:32 +01:00
parent 18062f4ad6
commit 3eb6c22a22

View file

@ -14,10 +14,10 @@
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <unistd.h> #include <unistd.h>
#include <stdio.h> #include <stdio.h>
#include <time.h>
#ifdef KERNEL #ifdef KERNEL
#include <Kernel/ProcFS.h> #include <Kernel/ProcFS.h>
#include <Kernel/RTC.h>
#endif #endif
//#define DEBUG_COUNTERS //#define DEBUG_COUNTERS
@ -218,11 +218,14 @@ WSWindowManager::WSWindowManager()
// NOTE: This ensures that the system menu has the correct dimensions. // NOTE: This ensures that the system menu has the correct dimensions.
set_current_menubar(nullptr); set_current_menubar(nullptr);
#if 0
WSMessageLoop::the().start_timer(300, [this] { WSMessageLoop::the().start_timer(300, [this] {
static time_t last_update_time;
time_t now = time(nullptr);
if (now != last_update_time) {
invalidate(menubar_rect()); invalidate(menubar_rect());
last_update_time = now;
}
}); });
#endif
invalidate(); invalidate();
compose(); compose();
@ -692,13 +695,17 @@ void WSWindowManager::draw_menubar()
return true; return true;
}); });
#ifdef KERNEL time_t now = time(nullptr);
unsigned year, month, day, hour, minute, second; auto* tm = localtime(&now);
RTC::read_registers(year, month, day, hour, minute, second); auto time_text = String::format("%4u-%02u-%02u %02u:%02u:%02u\n",
auto time_text = String::format("%04u-%02u-%02u %02u:%02u:%02u", year, month, day, hour, minute, second); tm->tm_year + 1900,
tm->tm_mon + 1,
tm->tm_mday,
tm->tm_hour,
tm->tm_min,
tm->tm_sec);
auto time_rect = menubar_rect().translated(-(menubar_menu_margin() / 2), 0); auto time_rect = menubar_rect().translated(-(menubar_menu_margin() / 2), 0);
m_back_painter->draw_text(time_rect, time_text, TextAlignment::CenterRight, Color::Black); m_back_painter->draw_text(time_rect, time_text, TextAlignment::CenterRight, Color::Black);
#endif
} }
void WSWindowManager::draw_cursor() void WSWindowManager::draw_cursor()