aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorache <ache@ache.one>2022-11-06 22:48:23 +0100
committerache <ache@ache.one>2022-11-06 22:48:23 +0100
commit2f5efc821ba09d39d5f316bca32cbb71330c7315 (patch)
tree279f678e2378a82e7f15cf3d0d4689d33ce6431a
parentLocale set (diff)
Show date
-rw-r--r--src/main.c2
-rw-r--r--src/render.c45
-rw-r--r--src/render.h4
3 files changed, 49 insertions, 2 deletions
diff --git a/src/main.c b/src/main.c
index 94d1d0c..2425dd0 100644
--- a/src/main.c
+++ b/src/main.c
@@ -358,6 +358,8 @@ static void draw(saver_state_t *state)
draw_logo(state);
}
+ draw_date_field(state);
+
draw_password_field(state);
// Automatically reset this after every draw call
diff --git a/src/render.c b/src/render.c
index e3ed98f..1b40fcd 100644
--- a/src/render.c
+++ b/src/render.c
@@ -281,6 +281,39 @@ void draw_logo(saver_state_t *state)
set_layer_needs_draw(state, LAYER_LOGO, false);
}
+void draw_date_field(saver_state_t *state)
+{
+ const double cursor_height = 40.0;
+ const double cursor_width = 30.0;
+ const double field_x = kLogoBackgroundWidth + 50.0;
+ const double field_y = (state->canvas_height - cursor_height) / 2.0;
+ const double field_padding = 10.0;
+
+ cairo_t *cr = state->ctx;
+
+ // Common color for status and password field
+ cairo_set_source_rgba(cr, 1.0, 1.0, 1.0, state->password_opacity);
+
+ char date[256] = "";
+ char datePrompt[256] = "";
+ time_t nowInstant = time(NULL);
+ struct tm* now = localtime(&nowInstant);
+
+ strftime(date, 256, "%T %a %d/%m/%y", now);
+ sprintf(datePrompt, "%s/%s", date, state->password_prompt);
+
+ // Measure status text
+ const char *prompt = datePrompt;
+ pango_layout_set_font_description(state->pango_layout, state->status_font);
+ pango_layout_set_text(state->pango_layout, prompt, -1);
+
+ int t_width, t_height;
+ pango_layout_get_size(state->pango_layout, &t_width, &t_height);
+ double line_height = t_height / PANGO_SCALE;
+
+
+
+}
void draw_password_field(saver_state_t *state)
{
const double cursor_height = 40.0;
@@ -288,14 +321,22 @@ void draw_password_field(saver_state_t *state)
const double field_x = kLogoBackgroundWidth + 50.0;
const double field_y = (state->canvas_height - cursor_height) / 2.0;
const double field_padding = 10.0;
-
+
cairo_t *cr = state->ctx;
// Common color for status and password field
cairo_set_source_rgba(cr, 1.0, 1.0, 1.0, state->password_opacity);
+ char date[256] = "";
+ char datePrompt[256] = "";
+ time_t nowInstant = time(NULL);
+ struct tm* now = localtime(&nowInstant);
+
+ strftime(date, 256, "%T %a %d/%m/%y", now);
+ sprintf(datePrompt, "%s\n%s", date, state->password_prompt);
+
// Measure status text
- const char *prompt = state->password_prompt;
+ const char *prompt = datePrompt;
pango_layout_set_font_description(state->pango_layout, state->status_font);
pango_layout_set_text(state->pango_layout, prompt, -1);
diff --git a/src/render.h b/src/render.h
index 5bc7016..27b917f 100644
--- a/src/render.h
+++ b/src/render.h
@@ -18,6 +18,7 @@
#define kMaxAnimations 32
#define kMaxPasswordLength 128
#define kMaxPromptLength 128
+#define kMaxPromptLength 128
#define kMaxTimers 16
typedef unsigned animation_key_t;
@@ -28,6 +29,7 @@ typedef enum {
LAYER_PROMPT = 1 << 1,
LAYER_LOGO = 1 << 2,
LAYER_PASSWORD = 1 << 3,
+ LAYER_DATE = 1 << 4,
} layer_type_t;
@@ -67,6 +69,8 @@ typedef struct {
RsvgHandle *spinner_svg_handle;
animation_key_t spinner_anim_key;
+ char date_prompt[kMaxPromptLength];
+
char password_prompt[kMaxPromptLength];
char password_buffer[kMaxPasswordLength];
double password_opacity;