Skip to content

Commit

Permalink
Adds input region labels.
Browse files Browse the repository at this point in the history
  • Loading branch information
tmccombs authored and emersion committed Aug 18, 2020
1 parent f8eb0b8 commit 795f526
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
3 changes: 2 additions & 1 deletion include/slurp.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ struct slurp_box {
int32_t x, y;
int32_t width, height;
struct wl_list link;
char *label;
};

struct slurp_selection {
Expand Down Expand Up @@ -100,7 +101,7 @@ struct slurp_seat {
// keymap:
struct xkb_keymap *xkb_keymap;
struct xkb_state *xkb_state;

// touch:
struct wl_touch *wl_touch;
int32_t touch_id;
Expand Down
9 changes: 7 additions & 2 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,11 @@ static void print_formatted_result(const struct slurp_box *result,
case 'h':
printf("%d", result->height);
continue;
case 'l':
if (result->label) {
printf("%s", result->label);
}
continue;
default:
// If no case was executed, revert i back - we don't need to
// skip the next character.
Expand Down Expand Up @@ -753,8 +758,8 @@ int main(int argc, char *argv[]) {
size_t line_size = 0;
while (getline(&line, &line_size, stdin) >= 0) {
struct slurp_box in_box = {0};
if (sscanf(line, "%d,%d %dx%d", &in_box.x, &in_box.y,
&in_box.width, &in_box.height) != 4) {
if (sscanf(line, "%d,%d %dx%d %m[^\n]", &in_box.x, &in_box.y,
&in_box.width, &in_box.height, &in_box.label) < 4) {
fprintf(stderr, "invalid box format: %s\n", line);
return EXIT_FAILURE;
}
Expand Down
6 changes: 5 additions & 1 deletion slurp.1.scd
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ select, or click to cancel the selection.

If the standard input is not a TTY, slurp will read a list of predefined
rectangles for quick selection. Each line must be in the form
"<x>,<y> <width>x<height>".
"<x>,<y> <width>x<height> [label]". The label is optional and can be any string
that doesn't contain newlines. It can be accessed using the "%l" sequence in a
format string.

If the _Esc_ key is pressed, selection is cancelled. If the _Space_ key is
held, the selection is moved instead of being resized.
Expand Down Expand Up @@ -64,6 +66,8 @@ Interpreted sequences are:

%h The height of the selection

%l Label included with region from stdin

The default format is "%x,%y %wx%h".

# AUTHORS
Expand Down

0 comments on commit 795f526

Please sign in to comment.