From 6e25d1b7a86d6744be480523454d512b9f8af160 Mon Sep 17 00:00:00 2001 From: Simeon Simeonov Date: Mon, 25 Nov 2024 14:54:03 +0100 Subject: Add support for UNIX time and release 3.2.15 --- CHANGELOG | 7 +++++ extras.c | 84 +++++++++++++++++++++++++++--------------------------- i3lock-extended.1 | 21 +++++++++----- i3lock.c | 63 ++++++++++++++++++++++++---------------- include/extras.h | 2 +- meson.build | 2 +- unlock_indicator.c | 29 +++++++++++++------ 7 files changed, 124 insertions(+), 84 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 258177d..655b65a 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,10 @@ +2024-11-24 i3lock-extended 3.2.15 + + • Fetch and sync upstream master + • Add support for UNIX time (seconds since Epoch) + • Rename elapsed-time-* options to display-text-* + + 2024-04-12 i3lock-extended 2.2.15 • Fetch and sync with i3lock 2.15 diff --git a/extras.c b/extras.c index 4e321ff..62599cd 100644 --- a/extras.c +++ b/extras.c @@ -46,11 +46,11 @@ static void i3lock_color_to_array(double *rgb16, const char *color) { } -static void i3clock_fetch_digital_clock_xy(int *x, - int *y, - const i3lock_digital_clock_t *dc, - const uint32_t *resolution, - int text_length) { +static void i3lock_fetch_digital_clock_xy(int *x, + int *y, + const i3lock_digital_clock_t *dc, + const uint32_t *resolution, + int text_length) { /* x */ if (dc->horizontal_alignment == I3LOCK_ALIGN_CENTER) { @@ -75,7 +75,7 @@ static void i3clock_fetch_digital_clock_xy(int *x, } -static void i3clock_fetch_led_clock_xy(int *x, +static void i3lock_fetch_led_clock_xy(int *x, int *y, const i3lock_led_clock_t *lc, const uint32_t *resolution) { @@ -211,11 +211,11 @@ void i3lock_draw_digital_clock(cairo_t *cr, for (screen = 0; screen < xr_screens; ++screen) { screen_resolution[0] = xr_resolutions[screen].width; screen_resolution[1] = xr_resolutions[screen].height; - i3clock_fetch_digital_clock_xy(&x, - &y, - dc, - screen_resolution, - strlen(current_time_str)); + i3lock_fetch_digital_clock_xy(&x, + &y, + dc, + screen_resolution, + strlen(current_time_str)); cairo_move_to(cr, x + xr_resolutions[screen].x, y + xr_resolutions[screen].y); @@ -224,11 +224,11 @@ void i3lock_draw_digital_clock(cairo_t *cr, return; } - i3clock_fetch_digital_clock_xy(&x, - &y, - dc, - resolution, - strlen(current_time_str)); + i3lock_fetch_digital_clock_xy(&x, + &y, + dc, + resolution, + strlen(current_time_str)); /* printf("%dx%d\n", *resolution, *(resolution + 1)); */ cairo_move_to(cr, x, y); cairo_show_text(cr, current_time_str); @@ -244,7 +244,7 @@ void i3lock_draw_string(cairo_t *cr, int x, y; /* create a dummy i3lock_digital_clock_t structure in order to reuse - i3clock_fetch_digital_clock_xy */ + i3lock_fetch_digital_clock_xy */ i3lock_digital_clock_t dc = {et->text_size, "", "", @@ -263,11 +263,11 @@ void i3lock_draw_string(cairo_t *cr, for (screen = 0; screen < xr_screens; ++screen) { screen_resolution[0] = xr_resolutions[screen].width; screen_resolution[1] = xr_resolutions[screen].height; - i3clock_fetch_digital_clock_xy(&x, - &y, - &dc, - screen_resolution, - strlen(formatted_string)); + i3lock_fetch_digital_clock_xy(&x, + &y, + &dc, + screen_resolution, + strlen(formatted_string)); cairo_move_to(cr, x + xr_resolutions[screen].x, y + xr_resolutions[screen].y); @@ -276,11 +276,11 @@ void i3lock_draw_string(cairo_t *cr, return; } - i3clock_fetch_digital_clock_xy(&x, - &y, - &dc, - resolution, - strlen(formatted_string)); + i3lock_fetch_digital_clock_xy(&x, + &y, + &dc, + resolution, + strlen(formatted_string)); /* printf("%dx%d\n", *resolution, *(resolution + 1)); */ cairo_move_to(cr, x, y); cairo_show_text(cr, formatted_string); @@ -297,7 +297,7 @@ void i3lock_draw_elapsed_time(cairo_t *cr, int x, y, seconds, minutes, hours, diff_seconds; /* create a dummy i3lock_digital_clock_t structure in ordet to reuse - i3clock_fetch_digital_clock_xy */ + i3lock_fetch_digital_clock_xy */ i3lock_digital_clock_t dc = {et->text_size, "", "", @@ -339,11 +339,11 @@ void i3lock_draw_elapsed_time(cairo_t *cr, for (screen = 0; screen < xr_screens; ++screen) { screen_resolution[0] = xr_resolutions[screen].width; screen_resolution[1] = xr_resolutions[screen].height; - i3clock_fetch_digital_clock_xy(&x, - &y, - &dc, - screen_resolution, - strlen(elapsed_time_str)); + i3lock_fetch_digital_clock_xy(&x, + &y, + &dc, + screen_resolution, + strlen(elapsed_time_str)); cairo_move_to(cr, x + xr_resolutions[screen].x, y + xr_resolutions[screen].y); @@ -352,11 +352,11 @@ void i3lock_draw_elapsed_time(cairo_t *cr, return; } - i3clock_fetch_digital_clock_xy(&x, - &y, - &dc, - resolution, - strlen(elapsed_time_str)); + i3lock_fetch_digital_clock_xy(&x, + &y, + &dc, + resolution, + strlen(elapsed_time_str)); /* printf("%dx%d\n", *resolution, *(resolution + 1)); */ cairo_move_to(cr, x, y); cairo_show_text(cr, elapsed_time_str); @@ -379,10 +379,10 @@ void i3lock_draw_led_clock(cairo_t *cr, screen_resolution[1] = xr_resolutions[screen].height; side_length = xr_resolutions[screen].height / I3LOCK_SCALE_LED_SPACING; space_length = xr_resolutions[screen].height / I3LOCK_SCALE_LED_LENGTH; - i3clock_fetch_led_clock_xy(&base_x, - &base_y, - lc, - screen_resolution); + i3lock_fetch_led_clock_xy(&base_x, + &base_y, + lc, + screen_resolution); base_x += xr_resolutions[screen].x; base_y += xr_resolutions[screen].y; base_x_h = base_x + space_length / 2 + side_length / 2; diff --git a/i3lock-extended.1 b/i3lock-extended.1 index 5a15f42..a5aae27 100644 --- a/i3lock-extended.1 +++ b/i3lock-extended.1 @@ -49,6 +49,7 @@ i3lock\-extended \- improved screen locker .RB [\|\-T .IR template \|] .RB [\|\-t\|] +.RB [\|\-U\|] .RB [\|\-u\|] .RB [\|\-v\|] .RB [\|\-W @@ -98,6 +99,8 @@ Elapsed time since activation Display-text .IP \[bu] Count broken-down time until a specific calendar time (absolute time) +.IP \[bu] +UNIX time (seconds since Epoch) .SH OPTIONS .TP @@ -191,8 +194,8 @@ displays a hardcoded Windows-Pointer (thus enabling you to mess with your friends by using a screenshot of a Windows desktop as a locking-screen). .TP -.BI \-R\ rrggbb \fR,\ \fB\-\-elapsed\-time\-color= rrggbb -The color of the elapsed time (text). Default: 000000 (black). +.BI \-R\ rrggbb \fR,\ \fB\-\-display\-text\-color= rrggbb +The color of the display text, elapsed time and UNIX time (text). Default: 000000 (black). .TP .BI \-r\ rate \fR,\ \fB\-\-refresh\-rate= rate @@ -227,7 +230,7 @@ support each one explicitly. .TP .BI \-S\ size \fR,\ \fB\-\-text\-size= size -The text size for elapsed time, digital clock and display-text. Default: 28. +The text size for digital clock, display text, elapsed time and UNIX time. Default: 28. .TP .BI \-T\ template \fR,\ \fB\-\-digital\-clock\-template= template @@ -238,6 +241,10 @@ The date(time) template for the digital clock. Default: %H:%M:%S. If an image is specified (via \-i) it will display the image tiled all over the screen (if it is a multi-monitor setup, the image is visible on all screens). +.TP +.B \-U, \-\-unix-time +Display UNIX time (seconds since Epoch) + .TP .B \-u, \-\-no-unlock-indicator Disable the unlock indicator. i3lock will by default show an unlock indicator @@ -251,8 +258,8 @@ Display the version of your .B i3lock .TP -.BI \-W\ halign \fR,\ \fB\-\-elapsed\-time\-halign= halign -The horizontal alignment for elapsed time and display-text. +.BI \-W\ halign \fR,\ \fB\-\-display\-text\-halign= halign +The horizontal alignment for display text, elapsed time and UNIX time. Valid halign values: left, center, right. Default: right .TP @@ -273,8 +280,8 @@ Valid valign values: top, middle, bottom. Default: bottom The vertical alignment for the digital clock. Default: top .TP -.BI \-Z\ valign \fR,\ \fB\-\-elapsed\-time\-valign= valign -The vertical alignment for elapsed time and display-text. Default: bottom +.BI \-Z\ valign \fR,\ \fB\-\-display\-text\-valign= valign +The vertical alignment for display text, elapsed time and UNIX time. Default: bottom .SH DPMS diff --git a/i3lock.c b/i3lock.c index 44a30f2..c35330e 100644 --- a/i3lock.c +++ b/i3lock.c @@ -84,6 +84,7 @@ static void input_done(void); bool digital_clock = false; bool led_clock = false; bool elapsed_time = false; +bool unix_time = false; /* display seconds since epoch */ int count_until = 0; /* count seconds until */ int refresh_rate = 2; /* 2 frames per second */ i3lock_digital_clock_t i3lock_digital_clock = {28, @@ -103,7 +104,7 @@ i3lock_led_clock_t i3lock_led_clock = {"ffff00", "000000", I3LOCK_ALIGN_CENTER, I3LOCK_ALIGN_BOTTOM}; -char *display_text = NULL; +char *display_text_template = NULL; #endif char color[7] = "a3a3a3"; @@ -1081,17 +1082,17 @@ int main(int argc, char *argv[]) { {"dpms", no_argument, NULL, 'd'}, {"color", required_argument, NULL, 'c'}, #ifdef EXTRAS - {"count-until", no_argument, NULL, 'C'}, + {"count-until", required_argument, NULL, 'C'}, {"digital-clock", no_argument, NULL, 'D'}, {"digital-clock-color", required_argument, NULL, 'G'}, {"digital-clock-template", required_argument, NULL, 'T'}, {"digital-clock-halign", required_argument, NULL, 'x'}, {"digital-clock-valign", required_argument, NULL, 'y'}, - {"display-text", no_argument, NULL, 'J'}, + {"display-text", required_argument, NULL, 'J'}, {"elapsed-time", no_argument, NULL, 'E'}, - {"elapsed-time-color", required_argument, NULL, 'R'}, - {"elapsed-time-halign", required_argument, NULL, 'W'}, - {"elapsed-time-valign", required_argument, NULL, 'Z'}, + {"display-text-color", required_argument, NULL, 'R'}, + {"display-text-halign", required_argument, NULL, 'W'}, + {"display-text-valign", required_argument, NULL, 'Z'}, {"led-clock", no_argument, NULL, 'L'}, {"led-clock-halign", required_argument, NULL, 'X'}, {"led-clock-valign", required_argument, NULL, 'Y'}, @@ -1100,6 +1101,7 @@ int main(int argc, char *argv[]) { {"led-on-color", required_argument, NULL, 'O'}, {"refresh-rate", required_argument, NULL, 'r'}, {"text-size", required_argument, NULL, 'S'}, + {"unix-time", no_argument, NULL, 'U'}, #endif {"pointer", required_argument, NULL, 'p'}, {"debug", no_argument, NULL, 0}, @@ -1117,7 +1119,7 @@ int main(int argc, char *argv[]) { int code = EXIT_FAILURE; #ifdef EXTRAS - char *optstring = "hvnbDdELC:c:B:G:F:J:O:R:r:S:T:W:X:x:Y:y:Z:p:ui:teI:fk"; + char *optstring = "hvnbDdELUC:c:B:G:F:J:O:R:r:S:T:W:X:x:Y:y:Z:p:ui:teI:fk"; #else char *optstring = "hvnbdc:p:ui:teI:fk"; #endif @@ -1163,6 +1165,9 @@ int main(int argc, char *argv[]) { digital_clock = true; break; case 'E': + if ((display_text_template != NULL) || (unix_time)) { + errx(EXIT_FAILURE, "Display text, elapsed time and UNIX time are mutually exclusive options\n"); + } elapsed_time = true; i3lock_elapsed_time.start_time = time(NULL); break; @@ -1205,13 +1210,16 @@ int main(int argc, char *argv[]) { DEBUG("led-off-color: %s\n", i3lock_led_clock.led_off_color); break; } - case 'J': { - display_text = strdup(optarg); - if (display_text == NULL) { + case 'J': { /* display-text */ + if ((elapsed_time) || (unix_time)) { + errx(EXIT_FAILURE, "Display text, elapsed time and UNIX time are mutually exclusive options\n"); + } + display_text_template = strdup(optarg); + if (display_text_template == NULL) { errx(EXIT_FAILURE, "Unable to initialize display_text\n"); } - DEBUG("display_text: %s\n", display_text); + DEBUG("display_text: %s\n", display_text_template); break; } case 'O': { /* led-on-color */ @@ -1226,16 +1234,17 @@ int main(int argc, char *argv[]) { DEBUG("led-on-color: %s\n", i3lock_led_clock.led_on_color); break; } - case 'R': { /* elapsed-time-color */ + case 'R': { /* display-text-color */ char *arg = optarg; /* Skip # if present */ if (arg[0] == '#') arg++; + /* since display-text is a subset of elapsed time, we store it in a i3lock_elapsed_time */ if (strlen(arg) != 6 || sscanf(arg, "%06[0-9a-fA-F]", i3lock_elapsed_time.color) != 1) - errx(EXIT_FAILURE, "elapsed-time-color is invalid, it must be given in 3-byte hexadecimal format: rrggbb\n"); - DEBUG("elapsed-time-color: %s\n", i3lock_elapsed_time.color); + errx(EXIT_FAILURE, "display-text-color is invalid, it must be given in 3-byte hexadecimal format: rrggbb\n"); + DEBUG("display-text-color: %s\n", i3lock_elapsed_time.color); break; } case 'r': /* refresh-rate */ @@ -1254,17 +1263,23 @@ int main(int argc, char *argv[]) { DEBUG("digital-clock-template: %s\n", i3lock_digital_clock.template); break; - case 'W': /* elapsed-time-halign */ + case 'U': /* UNIX time (epoch time) */ + if ((display_text_template != NULL) || (elapsed_time)) { + errx(EXIT_FAILURE, "Display text, elapsed time and UNIX time are mutually exclusive options\n"); + } + unix_time = true; + break; + case 'W': /* display-text-halign */ /* the default is right */ if (strcasecmp(optarg, "left") == 0) { i3lock_elapsed_time.horizontal_alignment = I3LOCK_ALIGN_LEFT; - DEBUG("elapsed-time-halign: left\n"); + DEBUG("display-text-halign: left\n"); } else if (strcasecmp(optarg, "center") == 0) { i3lock_elapsed_time.horizontal_alignment = I3LOCK_ALIGN_CENTER; - DEBUG("elapsed-time-halign: center\n"); + DEBUG("display-text-halign: center\n"); } else { /* value already set */ - DEBUG("elapsed-time-halign: right\n"); + DEBUG("display-tex-halign: right\n"); } break; case 'X': /* led-clock-halign */ @@ -1319,17 +1334,17 @@ int main(int argc, char *argv[]) { DEBUG("digital-clock-valign: top\n"); } break; - case 'Z': /* elapsed-time-valign */ + case 'Z': /* display-tex-valign */ /* the default is bottom */ if (strcasecmp(optarg, "middle") == 0) { i3lock_elapsed_time.vertical_alignment = I3LOCK_ALIGN_MIDDLE; - DEBUG("elapsed-time-valign: middle\n"); + DEBUG("display-tex-valign: middle\n"); } else if (strcasecmp(optarg, "top") == 0) { i3lock_elapsed_time.vertical_alignment = I3LOCK_ALIGN_TOP; - DEBUG("elapsed-time-valign: top\n"); + DEBUG("display-text-valign: top\n"); } else { /* value already set */ - DEBUG("elapsed-time-valign: bottom\n"); + DEBUG("display-text-valign: bottom\n"); } break; #endif @@ -1378,8 +1393,8 @@ int main(int argc, char *argv[]) { "[-c color] [-D] [-d] [-E] [-e] [-F color] [-f] [-k]" "[-G color] [-h] [-I timeout] [-i image.png] [-J text] " "[-L] [-n] [-O color] [-p win|default] [-R color] " - "[-r refresh rate] [-S size] [-T template] [-t] [-u] [-v] " - "[-W horizontal-alignment] [-X horizontal-alignment] " + "[-r refresh rate] [-S size] [-T template] [-t] [-U] [-u] " + "[-v] [-W horizontal-alignment] [-X horizontal-alignment] " "[-x horizontal-alignment] [-Y vertical-alignment] " "[-y vertical-alignment] [-Z vertical-alignment]"); #else diff --git a/include/extras.h b/include/extras.h index 4f791d8..3e3b51c 100644 --- a/include/extras.h +++ b/include/extras.h @@ -1,6 +1,6 @@ /* * This file is part of i3lock-extended - * Copyright (C) 2020-2023 Simeon Simeonov + * Copyright (C) 2020-2024 Simeon Simeonov * i3lock-extended is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/meson.build b/meson.build index 6960930..a69decc 100644 --- a/meson.build +++ b/meson.build @@ -6,7 +6,7 @@ project( 'i3lock-extended', 'c', - version: '2.2.15', + version: '3.2.15', default_options: [ 'c_std=c11', 'warning_level=1', # enable all warnings (-Wall) diff --git a/unlock_indicator.c b/unlock_indicator.c index 33b9406..2baf738 100644 --- a/unlock_indicator.c +++ b/unlock_indicator.c @@ -59,20 +59,21 @@ extern bool debug_mode; #ifdef EXTRAS /* timekeeping */ -#define I3LOCK_COUNT_UNTIL_BUFFER 128 -char count_until_str[I3LOCK_COUNT_UNTIL_BUFFER]; +#define I3LOCK_DISPLAY_TEXT_BUFFER_SIZE 128 +char display_text[I3LOCK_DISPLAY_TEXT_BUFFER_SIZE]; time_t now; struct tm *brokentime; /* enable the digital clock */ extern bool digital_clock; extern bool led_clock; extern bool elapsed_time; +extern bool unix_time; extern int count_until; extern i3lock_digital_clock_t i3lock_digital_clock; extern i3lock_elapsed_time_t i3lock_elapsed_time; extern i3lock_led_clock_t i3lock_led_clock; /* display text */ -extern char *display_text; +extern char *display_text_template; #endif /* The current position in the input buffer. Useful to determine if any @@ -438,27 +439,37 @@ void draw_image(xcb_pixmap_t bg_pixmap, uint32_t *resolution) { resolution, brokentime); } - /* elapsed time or counter with display text or only display text */ + + /* elapsed time, counter with display text, UNIX time or display text */ if (elapsed_time) { i3lock_draw_elapsed_time(xcb_ctx, &i3lock_elapsed_time, resolution, &now); - } else if (display_text != NULL) { + } else if (unix_time) { + snprintf(display_text, + I3LOCK_DISPLAY_TEXT_BUFFER_SIZE, + "%d", (int) now); + i3lock_draw_string(xcb_ctx, + display_text, + &i3lock_elapsed_time, + resolution); + } else if (display_text_template != NULL) { + /* display text */ if (count_until) { if (i3lock_format_elapsed_time( - count_until_str, display_text, - I3LOCK_COUNT_UNTIL_BUFFER, + display_text_template, + I3LOCK_DISPLAY_TEXT_BUFFER_SIZE, count_until - (int) now) != NULL) { i3lock_draw_string(xcb_ctx, - count_until_str, + display_text, &i3lock_elapsed_time, resolution); } } else { i3lock_draw_string(xcb_ctx, - display_text, + display_text_template, &i3lock_elapsed_time, resolution); } -- cgit v1.3