clock/text fixes, string fixes

This commit is contained in:
Chris Guillott 2017-05-29 11:22:36 -05:00
parent 4c77571185
commit 638cf1a6e2
3 changed files with 41 additions and 28 deletions

View File

@ -1024,7 +1024,7 @@ int main(int argc, char *argv[]) {
arg++;
if (strlen(arg) != 8 || sscanf(arg, "%08[0-9a-fA-F]", insidevercolor) != 1)
errx(1, "insidevercolor is invalid, color must be given in 8-byte format: rrggbbaa\n");
errx(1, "insidevercolor is invalid, color must be given in 4-byte format: rrggbbaa\n");
}
else if (strcmp(longopts[optind].name, "insidewrongcolor") == 0) {
char *arg = optarg;
@ -1034,7 +1034,7 @@ int main(int argc, char *argv[]) {
arg++;
if (strlen(arg) != 8 || sscanf(arg, "%08[0-9a-fA-F]", insidewrongcolor) != 1)
errx(1, "insidewrongcolor is invalid, color must be given in 8-byte format: rrggbbaa\n");
errx(1, "insidewrongcolor is invalid, color must be given in 4-byte format: rrggbbaa\n");
}
else if (strcmp(longopts[optind].name, "insidecolor") == 0) {
char *arg = optarg;
@ -1044,7 +1044,7 @@ int main(int argc, char *argv[]) {
arg++;
if (strlen(arg) != 8 || sscanf(arg, "%08[0-9a-fA-F]", insidecolor) != 1)
errx(1, "insidecolor is invalid, color must be given in 8-byte format: rrggbbaa\n");
errx(1, "insidecolor is invalid, color must be given in 4-byte format: rrggbbaa\n");
}
else if (strcmp(longopts[optind].name, "ringvercolor") == 0) {
char *arg = optarg;
@ -1054,7 +1054,7 @@ int main(int argc, char *argv[]) {
arg++;
if (strlen(arg) != 8 || sscanf(arg, "%08[0-9a-fA-F]", ringvercolor) != 1)
errx(1, "ringvercolor is invalid, color must be given in 8-byte format: rrggbb\n");
errx(1, "ringvercolor is invalid, color must be given in 4-byte format: rrggbb\n");
}
else if (strcmp(longopts[optind].name, "ringwrongcolor") == 0) {
char *arg = optarg;
@ -1064,7 +1064,7 @@ int main(int argc, char *argv[]) {
arg++;
if (strlen(arg) != 8 || sscanf(arg, "%08[0-9a-fA-F]", ringwrongcolor) != 1)
errx(1, "ringwrongcolor is invalid, color must be given in 8-byte format: rrggbb\n");
errx(1, "ringwrongcolor is invalid, color must be given in r-byte format: rrggbb\n");
}
else if (strcmp(longopts[optind].name, "ringcolor") == 0) {
char *arg = optarg;
@ -1074,7 +1074,7 @@ int main(int argc, char *argv[]) {
arg++;
if (strlen(arg) != 8 || sscanf(arg, "%08[0-9a-fA-F]", ringcolor) != 1)
errx(1, "ringcolor is invalid, color must be given in 8-byte format: rrggbb\n");
errx(1, "ringcolor is invalid, color must be given in 4-byte format: rrggbb\n");
}
else if (strcmp(longopts[optind].name, "linecolor") == 0) {
char *arg = optarg;
@ -1084,7 +1084,7 @@ int main(int argc, char *argv[]) {
arg++;
if (strlen(arg) != 8 || sscanf(arg, "%08[0-9a-fA-F]", linecolor) != 1)
errx(1, "linecolor is invalid, color must be given in 8-byte format: rrggbb\n");
errx(1, "linecolor is invalid, color must be given in 4-byte format: rrggbb\n");
}
else if (strcmp(longopts[optind].name, "textcolor") == 0) {
char *arg = optarg;
@ -1094,7 +1094,7 @@ int main(int argc, char *argv[]) {
arg++;
if (strlen(arg) != 8 || sscanf(arg, "%08[0-9a-fA-F]", textcolor) != 1)
errx(1, "textcolor is invalid, color must be given in 8-byte format: rrggbb\n");
errx(1, "textcolor is invalid, color must be given in 4-byte format: rrggbbaa\n");
}
else if (strcmp(longopts[optind].name, "timecolor") == 0) {
char *arg = optarg;
@ -1104,7 +1104,7 @@ int main(int argc, char *argv[]) {
arg++;
if (strlen(arg) != 8 || sscanf(arg, "%08[0-9a-fA-F]", timecolor) != 1)
errx(1, "timecolor is invalid, color must be given in 8-byte format: rrggbb\n");
errx(1, "timecolor is invalid, color must be given in 4-byte format: rrggbbaa\n");
}
else if (strcmp(longopts[optind].name, "datecolor") == 0) {
char *arg = optarg;
@ -1114,7 +1114,7 @@ int main(int argc, char *argv[]) {
arg++;
if (strlen(arg) != 8 || sscanf(arg, "%08[0-9a-fA-F]", datecolor) != 1)
errx(1, "datecolor is invalid, color must be given in 8-byte format: rrggbb\n");
errx(1, "datecolor is invalid, color must be given in 4-byte format: rrggbbaa\n");
}
else if (strcmp(longopts[optind].name, "keyhlcolor") == 0) {
char *arg = optarg;
@ -1124,7 +1124,7 @@ int main(int argc, char *argv[]) {
arg++;
if (strlen(arg) != 8 || sscanf(arg, "%08[0-9a-fA-F]", keyhlcolor) != 1)
errx(1, "keyhlcolor is invalid, color must be given in 8-byte format: rrggbb\n");
errx(1, "keyhlcolor is invalid, color must be given in 4-byte format: rrggbbaa\n");
}
else if (strcmp(longopts[optind].name, "bshlcolor") == 0) {
char *arg = optarg;
@ -1134,7 +1134,7 @@ int main(int argc, char *argv[]) {
arg++;
if (strlen(arg) != 8 || sscanf(arg, "%08[0-9a-fA-F]", bshlcolor) != 1)
errx(1, "bshlcolor is invalid, color must be given in 8-byte format: rrggbb\n");
errx(1, "bshlcolor is invalid, color must be given in 4-byte format: rrggbbaa\n");
}
else if (strcmp(longopts[optind].name, "separatorcolor") == 0) {
char *arg = optarg;
@ -1144,7 +1144,7 @@ int main(int argc, char *argv[]) {
arg++;
if (strlen(arg) != 8 || sscanf(arg, "%08[0-9a-fA-F]", separatorcolor) != 1)
errx(1, "separator is invalid, color must be given in 8-byte format: rrggbb\n");
errx(1, "separator is invalid, color must be given in 4-byte format: rrggbbaa\n");
}
else if (strcmp(longopts[optind].name, "timestr") == 0) {
//read in to timestr

View File

@ -5,9 +5,6 @@
#convert /tmp/screenshot.png -scale 10% -scale 1000% /tmp/screenshot.png
#pkill i3lock && i3lock -i /tmp/screenshot.png
#IMG=/tmp/screenshot.png
IMG=/home/arcana/wall/arcwall2_1080.png
B='#00000000' # blank
C='#ffffff22' # clear ish
D='#ff00ffcc' # default
@ -16,7 +13,6 @@ W='#880000bb' # wrong
V='#bb00bbbb' # verifying
./i3lock \
--image $IMG \
--insidevercolor=$C \
--ringvercolor=$V \
\
@ -29,12 +25,14 @@ V='#bb00bbbb' # verifying
--separatorcolor=$D \
\
--textcolor=$T \
--timecolor=$T \
--datecolor=$T \
--keyhlcolor=$W \
--bshlcolor=$W \
\
--screen 0 \
--blur 5 \
--clock \
--timestr="%H:%M:%S" \
--datestr="%A, %m %Y" \
--blur 5 \

View File

@ -267,10 +267,10 @@ xcb_pixmap_t draw_image(uint32_t *resolution) {
{timecolor[2], timecolor[3], '\0'},
{timecolor[4], timecolor[5], '\0'},
{timecolor[6], timecolor[7], '\0'}};
uint32_t date16[4] = {(strtol(strgroupsc[0], NULL, 16)),
(strtol(strgroupsc[1], NULL, 16)),
(strtol(strgroupsc[2], NULL, 16)),
(strtol(strgroupsc[3], NULL, 16))};
uint32_t date16[4] = {(strtol(strgroupsd[0], NULL, 16)),
(strtol(strgroupsd[1], NULL, 16)),
(strtol(strgroupsd[2], NULL, 16)),
(strtol(strgroupsd[3], NULL, 16))};
char strgroupsk[4][3] = {{keyhlcolor[0], keyhlcolor[1], '\0'},
{keyhlcolor[2], keyhlcolor[3], '\0'},
{keyhlcolor[4], keyhlcolor[5], '\0'},
@ -299,6 +299,7 @@ xcb_pixmap_t draw_image(uint32_t *resolution) {
/* https://github.com/ravinrabbid/i3lock-clock/commit/0de3a411fa5249c3a4822612c2d6c476389a1297 */
time_t rawtime;
struct tm* timeinfo;
bool unlock_indic_text = false;
time(&rawtime);
timeinfo = localtime(&rawtime);
@ -413,6 +414,20 @@ xcb_pixmap_t draw_image(uint32_t *resolution) {
break;
}
if (text) {
unlock_indic_text = true;
cairo_text_extents_t extents;
double x, y;
cairo_text_extents(ctx, text, &extents);
x = BUTTON_CENTER - ((extents.width / 2) + extents.x_bearing);
y = BUTTON_CENTER - ((extents.height / 2) + extents.y_bearing);
cairo_move_to(ctx, x, y);
cairo_show_text(ctx, text);
cairo_close_path(ctx);
}
if (auth_state == STATE_AUTH_WRONG && (modifier_string != NULL)) {
cairo_text_extents_t extents;
double x, y;
@ -471,20 +486,20 @@ xcb_pixmap_t draw_image(uint32_t *resolution) {
cairo_stroke(ctx);
}
}
if (show_clock) {
char *text = NULL;
if (show_clock && !unlock_indic_text) {
char *text = NULL;
char *date = NULL;
char time_text[40] = {0};
char date_text[40] = {0};
strftime(time_text, 40, time_format, timeinfo);
strftime(date_text, 40, date_format, timeinfo);
text = time_text;
if (text == NULL) {
text = time_text;
}
date = date_text;
double width = 0;
double height = 0;
if (text) {
double x, y;
cairo_text_extents_t extents;