diff --git a/include/slurp.h b/include/slurp.h index 92e37a9..7244516 100644 --- a/include/slurp.h +++ b/include/slurp.h @@ -31,6 +31,7 @@ struct slurp_state { } colors; uint32_t border_weight; + bool display_dimensions; struct slurp_box result; }; diff --git a/main.c b/main.c index cebe49c..7e29b8b 100644 --- a/main.c +++ b/main.c @@ -332,6 +332,7 @@ static const char usage[] = "Usage: slurp [options...]\n" "\n" " -h Show help message and quit.\n" + " -d Display dimensions of selection.\n" " -b #rrggbb Set background color.\n" " -c #rrggbb Set border color.\n" " -s #rrggbb Set selection color.\n" @@ -363,14 +364,18 @@ int main(int argc, char *argv[]) { .selection = 0x00000000, }, .border_weight = 2, + .display_dimensions = false, }; int opt; - while ((opt = getopt(argc, argv, "hb:c:s:w:")) != -1) { + while ((opt = getopt(argc, argv, "hdb:c:s:w:")) != -1) { switch (opt) { case 'h': printf("%s", usage); return EXIT_SUCCESS; + case 'd': + state.display_dimensions = true; + break; case 'b': state.colors.background = parse_color(optarg); break; diff --git a/render.c b/render.c index ef1445b..22e0350 100644 --- a/render.c +++ b/render.c @@ -46,5 +46,16 @@ void render(struct slurp_output *output) { cairo_rectangle(cairo, x * scale, y * scale, width * scale, height * scale); cairo_stroke(cairo); + + if (state->display_dimensions) { + cairo_select_font_face(cairo, "Sans", CAIRO_FONT_SLANT_NORMAL, + CAIRO_FONT_WEIGHT_NORMAL); + cairo_set_font_size(cairo, 14 * scale); + // buffer of 12 can hold selections up to 99999x99999 + char dimensions[12]; + snprintf(dimensions, sizeof(dimensions), "%ix%i", width, height); + cairo_move_to(cairo, (x + width + 10) * scale, (y + height + 20) * scale); + cairo_show_text(cairo, dimensions); + } } } diff --git a/slurp.1.scd b/slurp.1.scd index f85410c..7df00c4 100644 --- a/slurp.1.scd +++ b/slurp.1.scd @@ -19,6 +19,9 @@ select, or click to cancel the selection. *-h* Show help message and quit. +*-d* + Display dimensions of selection. + *-b* _color_ Set background color. See *COLORS* for more detail.