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
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ Select an output and print its name:
slurp -o -f "%o"
```

Print the geometry of the output currently containing the pointer:

```sh
slurp -O
```

Select a window under Sway, using `swaymsg` and `jq`:

```sh
Expand Down
1 change: 1 addition & 0 deletions include/slurp.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ struct slurp_state {
bool single_point;
bool restrict_selection;
bool crosshairs;
bool print_focused_output; // Print focused output geometry and exit
bool resizing_selection;
struct wl_list boxes; // slurp_box::link
bool fixed_aspect_ratio;
Expand Down
18 changes: 17 additions & 1 deletion main.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,12 @@ static void pointer_handle_enter(void *data, struct wl_pointer *wl_pointer,
// TODO: handle multiple overlapping outputs
seat->pointer_selection.current_output = output;

if (seat->state->print_focused_output) {
seat->state->result = output->logical_geometry;
seat->state->running = false;
return;
}

move_seat(seat, surface_x, surface_y, &seat->pointer_selection);

switch (seat->button_state) {
Expand Down Expand Up @@ -728,6 +734,7 @@ static const char usage[] =
" -w n Set border weight.\n"
" -f s Set output format.\n"
" -o Select a display output.\n"
" -O Print the focused display output geometry and exit.\n"
" -p Select a single point.\n"
" -r Restrict selection to predefined boxes.\n"
" -a w:h Force aspect ratio.\n"
Expand Down Expand Up @@ -897,6 +904,7 @@ int main(int argc, char *argv[]) {
.border_weight = 2,
.display_dimensions = false,
.restrict_selection = false,
.print_focused_output = false,
.resizing_selection = false,
.fixed_aspect_ratio = false,
.aspect_ratio = 0,
Expand All @@ -907,7 +915,7 @@ 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, "hdb:c:s:B:w:proa:f:F:xO")) != -1) {
switch (opt) {
case 'h':
printf("%s", usage);
Expand Down Expand Up @@ -949,6 +957,9 @@ int main(int argc, char *argv[]) {
case 'o':
output_boxes = true;
break;
case 'O':
state.print_focused_output = true;
break;
case 'r':
state.restrict_selection = true;
break;
Expand Down Expand Up @@ -978,6 +989,11 @@ int main(int argc, char *argv[]) {
return EXIT_FAILURE;
}

if (state.print_focused_output && (state.single_point || state.restrict_selection)) {
fprintf(stderr, "-O cannot be used with -p or -r\n");
return EXIT_FAILURE;
}

if (!acquire_lock()) {
// acquire_lock prints an appropriate error message itself
return EXIT_FAILURE;
Expand Down
4 changes: 4 additions & 0 deletions slurp.1.scd
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ held, the selection is moved instead of being resized.
Add predefined rectangles for all outputs, as if provided on standard input.
The label will be the name of the output.

*-O*
Immediately print the geometry of the output currently containing the pointer
and exit.

*-r*
Require the user to select one of the predefined rectangles. These can come
from standard input, if *-o* is used, the rectangles of all display outputs.
Expand Down