Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions include/slurp.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,15 @@ struct slurp_state {
uint32_t border;
uint32_t selection;
uint32_t choice;
uint32_t ruler;
} colors;

const char *font_family;

uint32_t border_weight;
uint32_t ruler_weight;
bool display_dimensions;
bool display_rulers;
bool single_point;
bool restrict_selection;
bool crosshairs;
Expand Down
1 change: 0 additions & 1 deletion lock.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,3 @@ bool acquire_lock() {
return true;
}


25 changes: 24 additions & 1 deletion main.c
Original file line number Diff line number Diff line change
Expand Up @@ -720,12 +720,15 @@ static const char usage[] =
"\n"
" -h Show help message and quit.\n"
" -d Display dimensions of selection.\n"
" -D Display rulers.\n"
" -b #rrggbbaa Set background color.\n"
" -c #rrggbbaa Set border color.\n"
" -s #rrggbbaa Set selection color.\n"
" -B #rrggbbaa Set option box color.\n"
" -R #rrggbbaa Set ruler color.\n"
" -F s Set the font family for the dimensions.\n"
" -w n Set border weight.\n"
" -W n Set ruler weight.\n"
" -f s Set output format.\n"
" -o Select a display output.\n"
" -p Select a single point.\n"
Expand Down Expand Up @@ -893,9 +896,12 @@ int main(int argc, char *argv[]) {
.border = BORDER_COLOR,
.selection = SELECTION_COLOR,
.choice = BG_COLOR,
.ruler = BG_COLOR,
},
.ruler_weight = 2,
.border_weight = 2,
.display_dimensions = false,
.display_rulers = false,
.restrict_selection = false,
.resizing_selection = false,
.fixed_aspect_ratio = false,
Expand All @@ -907,14 +913,20 @@ int main(int argc, char *argv[]) {
char *format = "%x,%y %wx%h\n";
bool output_boxes = false;
int w, h;
while ((opt = getopt(argc, argv, "hdb:c:s:B:w:proa:f:F:x")) != -1) {
while ((opt = getopt(argc, argv, "hdDb:R:c:s:B:w:W:proa:f:F:x")) != -1) {
switch (opt) {
case 'h':
printf("%s", usage);
return EXIT_SUCCESS;
case 'd':
state.display_dimensions = true;
break;
case 'D':
state.display_rulers = true;
break;
case 'R':
state.colors.ruler = parse_color(optarg);
break;
case 'b':
state.colors.background = parse_color(optarg);
break;
Expand Down Expand Up @@ -943,6 +955,16 @@ int main(int argc, char *argv[]) {
}
break;
}
case 'W': {
errno = 0;
char *endptr;
state.ruler_weight = strtol(optarg, &endptr, 10);
if (*endptr || errno) {
fprintf(stderr, "Error: expected numeric argument for -w\n");
exit(EXIT_FAILURE);
}
break;
}
case 'p':
state.single_point = true;
break;
Expand Down Expand Up @@ -1145,3 +1167,4 @@ int main(int argc, char *argv[]) {

return status;
}

33 changes: 33 additions & 0 deletions render.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <cairo/cairo.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>

Expand All @@ -19,6 +20,13 @@ static void draw_rect(cairo_t *cairo, struct slurp_box *box, uint32_t color) {
box->width, box->height);
}

// Treat width and height as X2 and Y2;
static void draw_line(cairo_t *cairo, struct slurp_box *box, uint32_t color) {
set_source_u32(cairo, color);
cairo_move_to(cairo, box->x, box->y);
cairo_line_to(cairo, box->width, box->height);
}

void render(struct slurp_output *output) {
struct slurp_state *state = output->state;
struct pool_buffer *buffer = output->current_buffer;
Expand Down Expand Up @@ -74,6 +82,31 @@ void render(struct slurp_output *output) {
draw_rect(cairo, sel_box, state->colors.border);
cairo_stroke(cairo);

if (state->display_rulers) {
bool revert_x = sel_box->x < current_selection->anchor_x;
bool revert_y = sel_box->y < current_selection->anchor_y;

uint32_t screen_x = current_selection->current_output->logical_geometry.x;
uint32_t screen_y = current_selection->current_output->logical_geometry.y;

struct slurp_box vertical_line;
vertical_line.x = sel_box->x + (revert_x ? -1 : sel_box->width + 1);
vertical_line.y = screen_y + (revert_y ? current_selection->current_output->height : 0);
vertical_line.width = sel_box->x + (revert_x ? -1 : sel_box->width + 1);
vertical_line.height = sel_box->y + (revert_y ? -1 : sel_box->height + 1);

struct slurp_box horizontal_line;
horizontal_line.x = screen_x + (revert_x ? current_selection->current_output->width : 0);
horizontal_line.y = sel_box->y + (revert_y ? -1 : sel_box->height + 1);
horizontal_line.width = vertical_line.width;
horizontal_line.height = vertical_line.height;

cairo_set_line_width(cairo, state->ruler_weight);
draw_line(cairo, &vertical_line, state->colors.ruler);
draw_line(cairo, &horizontal_line, state->colors.ruler);
cairo_stroke(cairo);
}

if (state->display_dimensions) {
cairo_select_font_face(cairo, state->font_family,
CAIRO_FONT_SLANT_NORMAL,
Expand Down
9 changes: 9 additions & 0 deletions slurp.1.scd
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ held, the selection is moved instead of being resized.
*-d*
Display dimensions of selection.

*-D*
Display rulers.

*-b* _color_
Set background color. Default is #FFFFFF40. See *COLORS* for more detail.

Expand All @@ -44,6 +47,9 @@ held, the selection is moved instead of being resized.
Set color for highlighting predefined rectangles from standard input when not
selected. Default is #FFFFFF40.

*-R* _color_
Set ruler color. Default is #00000000. See *COLORS* for more detail.

*-F* _font family_
Set the font family name when displaying the dimensions box. Only useful
when combined with the -d option. The available font family names guaranteed
Expand All @@ -53,6 +59,9 @@ held, the selection is moved instead of being resized.
*-w* _weight_
Set border weight. Default is 2.

*-W* _weight_
Set ruler weight. Default is 2.

*-f* _format_
Set format. See *FORMAT* for more detail.

Expand Down