From 46d94cf575412e8de98877fb88780a7e7d72344f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=98=99=E2=97=A6=20The=20Tablet=20=E2=9D=80=20GamerGirla?= =?UTF-8?q?ndCo=20=E2=97=A6=E2=9D=A7?= Date: Sun, 20 Jul 2025 19:24:28 -0400 Subject: [PATCH] wip --- grub-core/gfxmenu/gfxmenu.c | 1 + grub-core/gfxmenu/gui_label.c | 40 ++++++++++++----------------- grub-core/gfxmenu/view.c | 27 +++++++++++++++++++- include/grub/gui.h | 48 ++++++++++++++++++++++++++++++++++- 4 files changed, 90 insertions(+), 26 deletions(-) diff --git a/grub-core/gfxmenu/gfxmenu.c b/grub-core/gfxmenu/gfxmenu.c index 72b39f90f..e6d4176b1 100644 --- a/grub-core/gfxmenu/gfxmenu.c +++ b/grub-core/gfxmenu/gfxmenu.c @@ -138,6 +138,7 @@ GRUB_MOD_INIT (gfxmenu) { term->fullscreen (); break; + } grub_gfxmenu_try_hook = grub_gfxmenu_try; diff --git a/grub-core/gfxmenu/gui_label.c b/grub-core/gfxmenu/gui_label.c index ffd50223c..605d502c2 100644 --- a/grub-core/gfxmenu/gui_label.c +++ b/grub-core/gfxmenu/gui_label.c @@ -24,6 +24,7 @@ #include #include #include +#include static const char *align_options[] = { @@ -33,30 +34,6 @@ static const char *align_options[] = 0 }; -enum align_mode { - align_left, - align_center, - align_right -}; - -struct grub_gui_label -{ - struct grub_gui_component comp; - - grub_gui_container_t parent; - grub_video_rect_t bounds; - char *id; - int visible; - char *text; - char *template; - grub_font_t font; - grub_video_rgba_color_t color; - int value; - enum align_mode align; -}; - -typedef struct grub_gui_label *grub_gui_label_t; - static void label_destroy (void *vself) { @@ -228,6 +205,7 @@ label_set_property (void *vself, const char *name, const char *value) else if (grub_strcmp (name, "id") == 0) { grub_gfxmenu_timeout_unregister ((grub_gui_component_t) self); + grub_gfxmenu_time_unregister(); grub_free (self->id); if (value) self->id = grub_strdup (value); @@ -237,6 +215,20 @@ label_set_property (void *vself, const char *name, const char *value) == 0) grub_gfxmenu_timeout_register ((grub_gui_component_t) self, label_set_state); + else if (self->id && grub_strcmp(self->id, GRUB_GFXMENU_DATE_COMPONENT_ID) == 0) { + + struct grub_datetime datetime; + grub_get_datetime(&datetime); + //grub_gfxmenu_ + char* valtmp = grub_strdup (value); + grub_snprintf(valtmp, 100, "%d-%02d-%02d %02d:%02d:%02d %s\n", + datetime.year, datetime.month, datetime.day, + datetime.hour, datetime.minute, datetime.second, + grub_get_weekday_name(&datetime)); + value = valtmp; + grub_gfxmenu_time_register((grub_gui_component_t)self, label_set_state); + + } } return GRUB_ERR_NONE; } diff --git a/grub-core/gfxmenu/view.c b/grub-core/gfxmenu/view.c index e02eba8b0..2509e8932 100644 --- a/grub-core/gfxmenu/view.c +++ b/grub-core/gfxmenu/view.c @@ -18,6 +18,7 @@ */ #include +#include #include #include #include @@ -134,6 +135,9 @@ grub_gfxmenu_view_destroy (grub_gfxmenu_view_t view) grub_gfxmenu_timeout_notifications = grub_gfxmenu_timeout_notifications->next; grub_free (p); } + struct grub_gfxmenu_time_notify *p; + p = grub_gfxmenu_time_notification; + grub_free (p); grub_video_bitmap_destroy (view->raw_desktop_image); grub_video_bitmap_destroy (view->scaled_desktop_image); if (view->terminal_box) @@ -258,6 +262,27 @@ update_menu_visit (grub_gui_component_t component, } } +struct grub_gfxmenu_time_notify * grub_gfxmenu_time_notification; + +static void redraw_time(struct grub_gfxmenu_view *view) +{ + struct grub_gfxmenu_time_notify* cur = grub_gfxmenu_time_notification; + grub_gui_label_t self = (grub_gui_label_t)cur->self; + + struct grub_datetime datetime; + grub_get_datetime(&datetime); + char* valtmp = grub_strdup (self->text); + grub_snprintf(valtmp, 100, "%d-%02d-%02d %02d:%02d:%02d %s\n", + datetime.year, datetime.month, datetime.day, + datetime.hour, datetime.minute, datetime.second, + grub_get_weekday_name(&datetime)); + self->text = valtmp; + grub_video_rect_t bounds; + cur->self->ops->get_bounds (cur->self, &bounds); + grub_video_set_area_status (GRUB_VIDEO_AREA_ENABLED); + grub_gfxmenu_view_redraw (view, &bounds); +} + /* Update any boot menu components with the current menu model and theme path. */ static void @@ -367,7 +392,7 @@ grub_gfxmenu_view_draw (grub_gfxmenu_view_t view) grub_video_set_area_status (GRUB_VIDEO_AREA_DISABLED); grub_gfxmenu_view_redraw (view, &view->screen); } - + redraw_time(view); } static void diff --git a/include/grub/gui.h b/include/grub/gui.h index 3657623c8..631b453b4 100644 --- a/include/grub/gui.h +++ b/include/grub/gui.h @@ -30,6 +30,7 @@ /* The component ID identifying GUI components to be updated as the timeout status changes. */ #define GRUB_GFXMENU_TIMEOUT_COMPONENT_ID "__timeout__" +#define GRUB_GFXMENU_DATE_COMPONENT_ID "__time__" typedef struct grub_gui_component *grub_gui_component_t; typedef struct grub_gui_container *grub_gui_container_t; @@ -86,7 +87,31 @@ struct grub_gfxmenu_timeout_notify grub_gui_component_t self; }; -extern struct grub_gfxmenu_timeout_notify *grub_gfxmenu_timeout_notifications; +extern struct grub_gfxmenu_timeout_notify* grub_gfxmenu_timeout_notifications; + +struct grub_gfxmenu_time_notify { + grub_gfxmenu_set_state_t set_state; + grub_gui_component_t self; +}; + +extern struct grub_gfxmenu_time_notify* grub_gfxmenu_time_notification; + +static inline grub_err_t grub_gfxmenu_time_register(grub_gui_component_t self, + grub_gfxmenu_set_state_t set_state) { + struct grub_gfxmenu_time_notify* te = grub_malloc(sizeof(*te)); + if (!te) + return grub_errno; + te->set_state = set_state; + te->self = self; + grub_gfxmenu_time_notification = te; + return GRUB_ERR_NONE; + +} +static inline void grub_gfxmenu_time_unregister(void) +{ + if(grub_gfxmenu_time_notification) + grub_free(grub_gfxmenu_time_notification) ; +} static inline grub_err_t grub_gfxmenu_timeout_register (grub_gui_component_t self, @@ -200,7 +225,28 @@ struct grub_gui_list struct grub_gui_component component; struct grub_gui_list_ops *ops; }; +enum align_mode { + align_left, + align_center, + align_right +}; +struct grub_gui_label +{ + struct grub_gui_component comp; + grub_gui_container_t parent; + grub_video_rect_t bounds; + char *id; + int visible; + char *text; + char *template; + grub_font_t font; + grub_video_rgba_color_t color; + int value; + enum align_mode align; +}; + +typedef struct grub_gui_label *grub_gui_label_t; /* Interfaces to concrete component classes. */