Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for crosshairs #56

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions include/slurp.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ struct slurp_state {
uint32_t border_weight;
bool display_dimensions;
bool single_point;
bool crosshairs;
struct wl_list boxes; // slurp_box::link

struct slurp_box result;
Expand Down
15 changes: 11 additions & 4 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,14 @@ static void pointer_handle_leave(void *data, struct wl_pointer *wl_pointer,
}

static void seat_set_outputs_dirty(struct slurp_seat *seat) {
struct slurp_state *state = seat->state;
struct slurp_output *output;
wl_list_for_each(output, &seat->state->outputs, link) {
if (box_intersect(&output->logical_geometry,
&seat->pointer_selection.selection) ||
box_intersect(&output->logical_geometry,
&seat->touch_selection.selection)) {
&seat->touch_selection.selection) ||
state->crosshairs) {
set_output_dirty(output);
}
}
Expand Down Expand Up @@ -121,8 +123,10 @@ static void handle_active_selection_motion(struct slurp_seat *seat, struct slurp
static void pointer_handle_motion(void *data, struct wl_pointer *wl_pointer,
uint32_t time, wl_fixed_t surface_x, wl_fixed_t surface_y) {
struct slurp_seat *seat = data;
struct slurp_state *state = seat->state;

// the places the cursor moved away from are also dirty
if (seat->pointer_selection.has_selection) {
if (seat->pointer_selection.has_selection || state->crosshairs) {
seat_set_outputs_dirty(seat);
}

Expand Down Expand Up @@ -153,7 +157,7 @@ static void pointer_handle_motion(void *data, struct wl_pointer *wl_pointer,
break;
}

if (seat->pointer_selection.has_selection) {
if (seat->pointer_selection.has_selection || state->crosshairs) {
seat_set_outputs_dirty(seat);
}
}
Expand Down Expand Up @@ -702,7 +706,7 @@ int main(int argc, char *argv[]) {

int opt;
char *format = "%x,%y %wx%h";
while ((opt = getopt(argc, argv, "hdb:c:s:w:pf:")) != -1) {
while ((opt = getopt(argc, argv, "hdb:c:s:w:pf:x")) != -1) {
switch (opt) {
case 'h':
printf("%s", usage);
Expand Down Expand Up @@ -735,6 +739,9 @@ int main(int argc, char *argv[]) {
case 'p':
state.single_point = true;
break;
case 'x':
state.crosshairs = true;
break;
default:
printf("%s", usage);
return EXIT_FAILURE;
Expand Down
15 changes: 15 additions & 0 deletions render.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,21 @@ void render(struct slurp_output *output) {
&seat->touch_selection :
&seat->pointer_selection;

if (!current_selection->has_selection && state->crosshairs) {
if (output->logical_geometry.x <= current_selection->x &&
output->logical_geometry.x + output->logical_geometry.width >= current_selection->x &&
output->logical_geometry.y <= current_selection->y &&
output->logical_geometry.y + output->logical_geometry.height >= current_selection->y) {

set_source_u32(cairo, state->colors.selection);
cairo_rectangle(cairo, 0, current_selection->y, output->logical_geometry.width, 1);
cairo_fill(cairo);
cairo_rectangle(cairo, current_selection->x - output->logical_geometry.x,
output->logical_geometry.y, 1, output->logical_geometry.height);
cairo_fill(cairo);
}
}

if (!seat->wl_pointer) {
continue;
}
Expand Down