From 9ceeecdc84d5c44dd496e93a4b380c6f03bc8183 Mon Sep 17 00:00:00 2001 From: David Donahue Date: Fri, 28 May 2021 21:15:06 -0500 Subject: [PATCH 1/7] Implemented ^pa command for X position --- dtao.c | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/dtao.c b/dtao.c index 5696c55..71bfc4a 100644 --- a/dtao.c +++ b/dtao.c @@ -134,9 +134,32 @@ parse_color(const char *str, pixman_color_t *clr) clr->blue = ((parsed >> 0) & 0xff) * 0x101; return 0; } +static int +parse_movement_absolute(const char *str, uint32_t *xpos) +{ + if (!*str) { + return 1; + } else if (!strchr(str, ';')) { + if (*str >= '0' && *str <= '9') { + *xpos = atoi(str); + } else if (*str == 'w') { + *xpos = atoi(++str) * width / 100; + } else { + return 1; + } + } else { + return 1; + } + + if (*xpos > width) + *xpos = width; + + return 0; + +} static char * -handle_cmd(char *cmd, pixman_color_t *bg, pixman_color_t *fg) +handle_cmd(char *cmd, pixman_color_t *bg, pixman_color_t *fg, uint32_t *xpos) { char *arg, *end; @@ -158,6 +181,9 @@ handle_cmd(char *cmd, pixman_color_t *bg, pixman_color_t *fg) } else if (parse_color(arg, fg)) { fprintf(stderr, "Bad color string \"%s\"\n", arg); } + } else if (!strcmp(cmd, "pa")) { + if(parse_movement_absolute (arg, xpos)) + fprintf(stderr, "Invalid absolute motion argument \"%s\"\n", arg); } else { fprintf(stderr, "Unrecognized command \"%s\"\n", cmd); } @@ -220,7 +246,7 @@ draw_frame(char *text) if (state == UTF8_ACCEPT && *p == '^') { p++; if (*p != '^') { - p = handle_cmd(p, &textbgcolor, &textfgcolor); + p = handle_cmd(p, &textbgcolor, &textfgcolor, &xpos); pixman_image_unref(fgfill); fgfill = pixman_image_create_solid_fill(&textfgcolor); continue; From a03c054e1cfc55d4069f68cc861b9deb1b0117e0 Mon Sep 17 00:00:00 2001 From: David Donahue Date: Fri, 28 May 2021 21:25:42 -0500 Subject: [PATCH 2/7] Implemented ^sx() and ^rx() --- dtao.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/dtao.c b/dtao.c index 71bfc4a..79d0cca 100644 --- a/dtao.c +++ b/dtao.c @@ -58,6 +58,8 @@ static enum align titlealign, subalign; static bool expand; static bool run_display = true; +static uint32_t savedx = 0; + static struct fcft_font *font; static char line[MAX_LINE_LEN]; static char lastline[MAX_LINE_LEN]; @@ -182,8 +184,12 @@ handle_cmd(char *cmd, pixman_color_t *bg, pixman_color_t *fg, uint32_t *xpos) fprintf(stderr, "Bad color string \"%s\"\n", arg); } } else if (!strcmp(cmd, "pa")) { - if(parse_movement_absolute (arg, xpos)) + if (parse_movement_absolute (arg, xpos)) fprintf(stderr, "Invalid absolute motion argument \"%s\"\n", arg); + } else if (!strcmp(cmd, "sx")) { + savedx = *xpos; + } else if (!strcmp(cmd, "rx")) { + *xpos = savedx; } else { fprintf(stderr, "Unrecognized command \"%s\"\n", cmd); } From 04f5133cb046bd1151f7d1ac2152fddf260f4d03 Mon Sep 17 00:00:00 2001 From: David Donahue Date: Fri, 28 May 2021 23:43:34 -0500 Subject: [PATCH 3/7] Implemented ^p() commands for X position --- dtao.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) diff --git a/dtao.c b/dtao.c index 79d0cca..48cae78 100644 --- a/dtao.c +++ b/dtao.c @@ -136,6 +136,7 @@ parse_color(const char *str, pixman_color_t *clr) clr->blue = ((parsed >> 0) & 0xff) * 0x101; return 0; } + static int parse_movement_absolute(const char *str, uint32_t *xpos) { @@ -160,6 +161,54 @@ parse_movement_absolute(const char *str, uint32_t *xpos) } +static int +parse_movement_relative(const char *str, uint32_t *xpos) +{ + if (!*str) { + *xpos = 0; + } else if (!strchr(str, ';')) { + if (*str >= '0' && *str <= '9') { + *xpos += atoi(str); + } else if (*str == '-'){ + if (*++str == 'w') { + if ((uint32_t) atoi(++str) * width / 100 < *xpos) { + *xpos -= atoi(str) * width / 100; + } else { + *xpos = 0; + } + } else { + if ((uint32_t) atoi(str) < *xpos) { + *xpos -= atoi(str); + } else { + *xpos = 0; + } + } + } else if (*str == 'w') { + *xpos += atoi(++str) * width / 100; + } else if (*str == '_') { + if (!strcmp(str, "_LEFT")) { + *xpos = 0; + } else if (!strcmp(str, "_RIGHT")) { + *xpos = width; + } else if (!strcmp(str, "_CENTER")) { + *xpos = width/2; + } else { + return 1; + } + } else { + return 1; + } + } else { + return 1; + } + + if (*xpos > width) + *xpos = width; + + return 0; + +} + static char * handle_cmd(char *cmd, pixman_color_t *bg, pixman_color_t *fg, uint32_t *xpos) { @@ -185,7 +234,10 @@ handle_cmd(char *cmd, pixman_color_t *bg, pixman_color_t *fg, uint32_t *xpos) } } else if (!strcmp(cmd, "pa")) { if (parse_movement_absolute (arg, xpos)) - fprintf(stderr, "Invalid absolute motion argument \"%s\"\n", arg); + fprintf(stderr, "Invalid absolute position argument \"%s\"\n", arg); + } else if (!strcmp(cmd, "p")) { + if (parse_movement_relative (arg, xpos)) + fprintf(stderr, "Invalid relative position argument \"%s\"\n", arg); } else if (!strcmp(cmd, "sx")) { savedx = *xpos; } else if (!strcmp(cmd, "rx")) { From 40aee66b8c0336327364b0db2f01f728284f2c68 Mon Sep 17 00:00:00 2001 From: David Donahue Date: Sat, 29 May 2021 00:41:28 -0500 Subject: [PATCH 4/7] Implemented Y position commands and aliases --- doc/dtao.1.ronn | 2 +- dtao.c | 102 +++++++++++++++++++++++++++++------------------- 2 files changed, 63 insertions(+), 41 deletions(-) diff --git a/doc/dtao.1.ronn b/doc/dtao.1.ronn index 67395d1..469438f 100644 --- a/doc/dtao.1.ronn +++ b/doc/dtao.1.ronn @@ -114,7 +114,7 @@ Note: the positioning of graphics in dzen is not obvious. dtao may opt to imple relative positioning: calculate X and/or Y position according to the argument format and add it to the current position * `^p()`: - resets Y position to default; alias for `^pa(;0)` + resets Y position to default; alias for `^pa(;w50)` * `^p(_LEFT)`, `^p(_CENTER)`, `^p(_RIGHT)`: move to left edge, center, or right edge of window; aliases for `^pa(w0)`, `^pa(w50)`, and `^pa(w100)` diff --git a/dtao.c b/dtao.c index 48cae78..14ba57e 100644 --- a/dtao.c +++ b/dtao.c @@ -138,79 +138,101 @@ parse_color(const char *str, pixman_color_t *clr) } static int -parse_movement_absolute(const char *str, uint32_t *xpos) +parse_movement_arg(const char *str, uint32_t max) { - if (!*str) { + if (!str) + return 0; + + if (*str == '-') + return -(parse_movement_arg (++str, max)); + + if (*str == 'w') + return atoi(++str) * max / 100; + + return atoi(str); +} + +static int +parse_movement_absolute(char *str, uint32_t *xpos, uint32_t *ypos) +{ + char *xarg = str; + char *yarg; + + /* ^pa() requires an argument */ + if (!*str) return 1; - } else if (!strchr(str, ';')) { - if (*str >= '0' && *str <= '9') { - *xpos = atoi(str); - } else if (*str == 'w') { - *xpos = atoi(++str) * width / 100; - } else { - return 1; - } - } else { + + /* Negative numbers are invalid with absolute movements */ + if (strchr(str, '-')) return 1; + + if (!(yarg = strchr(str, ';'))) { + *xpos = parse_movement_arg (str, width); + } else if (*str == ';') { + *ypos = parse_movement_arg (++str, height); + } else { + *yarg++ = '\0'; + *ypos = parse_movement_arg (yarg, height); + *xpos = parse_movement_arg (xarg, width); + *--yarg = ';'; } if (*xpos > width) *xpos = width; - return 0; + if (*ypos > height) + *ypos = height; + return 0; } static int -parse_movement_relative(const char *str, uint32_t *xpos) +parse_movement_relative(char *str, uint32_t *xpos, uint32_t *ypos) { + char *xarg = str; + char *yarg; + if (!*str) { - *xpos = 0; - } else if (!strchr(str, ';')) { - if (*str >= '0' && *str <= '9') { - *xpos += atoi(str); - } else if (*str == '-'){ - if (*++str == 'w') { - if ((uint32_t) atoi(++str) * width / 100 < *xpos) { - *xpos -= atoi(str) * width / 100; - } else { - *xpos = 0; - } - } else { - if ((uint32_t) atoi(str) < *xpos) { - *xpos -= atoi(str); - } else { - *xpos = 0; - } - } - } else if (*str == 'w') { - *xpos += atoi(++str) * width / 100; - } else if (*str == '_') { + *ypos = (height + font->ascent - font->descent) / 2; + } else if (!(yarg = strchr(str, ';'))) { + if (*str == '_') { if (!strcmp(str, "_LEFT")) { *xpos = 0; } else if (!strcmp(str, "_RIGHT")) { *xpos = width; } else if (!strcmp(str, "_CENTER")) { *xpos = width/2; + } else if (!strcmp(str, "_TOP")) { + *ypos = 0; + } else if (!strcmp(str, "_BOTTOM")) { + *ypos = height; } else { return 1; } } else { - return 1; + *xpos += parse_movement_arg (str, width); } + } else if (*str == ';') { + *ypos += parse_movement_arg (++str, height); } else { - return 1; + *yarg++ = '\0'; + *ypos += parse_movement_arg (yarg, height); + *xpos += parse_movement_arg (xarg, width); + *--yarg = ';'; } if (*xpos > width) *xpos = width; + if (*ypos > height) + *ypos = height; + return 0; } static char * -handle_cmd(char *cmd, pixman_color_t *bg, pixman_color_t *fg, uint32_t *xpos) +handle_cmd(char *cmd, pixman_color_t *bg, pixman_color_t *fg, uint32_t *xpos, uint32_t *ypos) { char *arg, *end; @@ -233,10 +255,10 @@ handle_cmd(char *cmd, pixman_color_t *bg, pixman_color_t *fg, uint32_t *xpos) fprintf(stderr, "Bad color string \"%s\"\n", arg); } } else if (!strcmp(cmd, "pa")) { - if (parse_movement_absolute (arg, xpos)) + if (parse_movement_absolute (arg, xpos, ypos)) fprintf(stderr, "Invalid absolute position argument \"%s\"\n", arg); } else if (!strcmp(cmd, "p")) { - if (parse_movement_relative (arg, xpos)) + if (parse_movement_relative (arg, xpos, ypos)) fprintf(stderr, "Invalid relative position argument \"%s\"\n", arg); } else if (!strcmp(cmd, "sx")) { savedx = *xpos; @@ -304,7 +326,7 @@ draw_frame(char *text) if (state == UTF8_ACCEPT && *p == '^') { p++; if (*p != '^') { - p = handle_cmd(p, &textbgcolor, &textfgcolor, &xpos); + p = handle_cmd(p, &textbgcolor, &textfgcolor, &xpos, &ypos); pixman_image_unref(fgfill); fgfill = pixman_image_create_solid_fill(&textfgcolor); continue; From 780852eb7cdd20c46c6871558b1e42870ceda471 Mon Sep 17 00:00:00 2001 From: David Donahue Date: Sat, 29 May 2021 01:00:46 -0500 Subject: [PATCH 5/7] Implemented ascent and descent percent arguments --- dtao.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/dtao.c b/dtao.c index 14ba57e..0b29375 100644 --- a/dtao.c +++ b/dtao.c @@ -149,6 +149,12 @@ parse_movement_arg(const char *str, uint32_t max) if (*str == 'w') return atoi(++str) * max / 100; + if (*str == 'd') + return atoi(++str) * font->descent / 100; + + if (*str == 'a') + return atoi(++str) * font->ascent / 100; + return atoi(str); } From 11286b181e438dffd57e331c4de7880ad5f19a11 Mon Sep 17 00:00:00 2001 From: David Donahue Date: Sat, 29 May 2021 01:26:50 -0500 Subject: [PATCH 6/7] combined relative and absolute position functions --- dtao.c | 48 +++++++----------------------------------------- 1 file changed, 7 insertions(+), 41 deletions(-) diff --git a/dtao.c b/dtao.c index 0b29375..ddd299e 100644 --- a/dtao.c +++ b/dtao.c @@ -159,41 +159,7 @@ parse_movement_arg(const char *str, uint32_t max) } static int -parse_movement_absolute(char *str, uint32_t *xpos, uint32_t *ypos) -{ - char *xarg = str; - char *yarg; - - /* ^pa() requires an argument */ - if (!*str) - return 1; - - /* Negative numbers are invalid with absolute movements */ - if (strchr(str, '-')) - return 1; - - if (!(yarg = strchr(str, ';'))) { - *xpos = parse_movement_arg (str, width); - } else if (*str == ';') { - *ypos = parse_movement_arg (++str, height); - } else { - *yarg++ = '\0'; - *ypos = parse_movement_arg (yarg, height); - *xpos = parse_movement_arg (xarg, width); - *--yarg = ';'; - } - - if (*xpos > width) - *xpos = width; - - if (*ypos > height) - *ypos = height; - - return 0; -} - -static int -parse_movement_relative(char *str, uint32_t *xpos, uint32_t *ypos) +parse_movement (char *str, uint32_t *xpos, uint32_t *ypos, uint32_t xoffset, uint32_t yoffset) { char *xarg = str; char *yarg; @@ -216,14 +182,14 @@ parse_movement_relative(char *str, uint32_t *xpos, uint32_t *ypos) return 1; } } else { - *xpos += parse_movement_arg (str, width); + *xpos = parse_movement_arg (str, width) + xoffset; } } else if (*str == ';') { - *ypos += parse_movement_arg (++str, height); + *ypos = parse_movement_arg (++str, height) + yoffset; } else { *yarg++ = '\0'; - *ypos += parse_movement_arg (yarg, height); - *xpos += parse_movement_arg (xarg, width); + *ypos = parse_movement_arg (yarg, height) + yoffset; + *xpos = parse_movement_arg (xarg, width) + xoffset; *--yarg = ';'; } @@ -261,10 +227,10 @@ handle_cmd(char *cmd, pixman_color_t *bg, pixman_color_t *fg, uint32_t *xpos, ui fprintf(stderr, "Bad color string \"%s\"\n", arg); } } else if (!strcmp(cmd, "pa")) { - if (parse_movement_absolute (arg, xpos, ypos)) + if (parse_movement (arg, xpos, ypos, 0, 0)) fprintf(stderr, "Invalid absolute position argument \"%s\"\n", arg); } else if (!strcmp(cmd, "p")) { - if (parse_movement_relative (arg, xpos, ypos)) + if (parse_movement (arg, xpos, ypos, *xpos, *ypos)) fprintf(stderr, "Invalid relative position argument \"%s\"\n", arg); } else if (!strcmp(cmd, "sx")) { savedx = *xpos; From 6784366462e4afe01a3171bbad6b09f4f11443b8 Mon Sep 17 00:00:00 2001 From: David Donahue Date: Sun, 11 Jul 2021 13:22:10 -0500 Subject: [PATCH 7/7] Removed "UNIMPLEMENTED" from the position commands section of the manpage" --- doc/dtao.1.ronn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/dtao.1.ronn b/doc/dtao.1.ronn index 469438f..a04a0bb 100644 --- a/doc/dtao.1.ronn +++ b/doc/dtao.1.ronn @@ -105,7 +105,7 @@ Note: the positioning of graphics in dzen is not obvious. dtao may opt to imple draw circle outline centered at current position, moving right by pixels -### Positioning [UNIMPLEMENTED] +### Positioning * `^pa(``)`, `^pa(;``)`, `^pa(``;``)`: absolute positioning: set X and/or Y position according to the argument format (see below)