diff options
-rw-r--r-- | examples/output-layout.c | 22 | ||||
-rw-r--r-- | include/wlr/types/wlr_output_layout.h | 6 | ||||
-rw-r--r-- | types/wlr_output_layout.c | 30 |
3 files changed, 45 insertions, 13 deletions
diff --git a/examples/output-layout.c b/examples/output-layout.c index cc363504..13abb6a1 100644 --- a/examples/output-layout.c +++ b/examples/output-layout.c @@ -46,24 +46,20 @@ static void handle_output_frame(struct output_state *output, struct timespec *ts struct sample_state *sample = state->data; struct wlr_output *wlr_output = output->output; - int32_t width, height; - wlr_output_effective_resolution(wlr_output, &width, &height); - wlr_output_make_current(wlr_output); wlr_renderer_begin(sample->renderer, wlr_output); - float matrix[16]; - - // transform global coordinates to local coordinates - int local_x = sample->x_offs; - int local_y = sample->y_offs; + if (wlr_output_layout_intersects(sample->layout, output->output, + sample->x_offs, sample->y_offs, + sample->x_offs + 128, sample->y_offs + 128)) { + float matrix[16]; - wlr_output_layout_output_coords(sample->layout, output->output, &local_x, - &local_y); + // transform global coordinates to local coordinates + int local_x = sample->x_offs; + int local_y = sample->y_offs; + wlr_output_layout_output_coords(sample->layout, output->output, &local_x, + &local_y); - if (local_x < width && local_x + 128 > 0 && local_y < height && - local_y + 128 > 0) { - // render the image if it intersects with the output wlr_texture_get_matrix(sample->cat_texture, &matrix, &wlr_output->transform_matrix, local_x, local_y); wlr_render_with_matrix(sample->renderer, diff --git a/include/wlr/types/wlr_output_layout.h b/include/wlr/types/wlr_output_layout.h index 7c904838..1b83bfaf 100644 --- a/include/wlr/types/wlr_output_layout.h +++ b/include/wlr/types/wlr_output_layout.h @@ -40,4 +40,10 @@ void wlr_output_layout_remove(struct wlr_output_layout *layout, void wlr_output_layout_output_coords(struct wlr_output_layout *layout, struct wlr_output *reference, int *x, int *y); +bool wlr_output_layout_contains_point(struct wlr_output_layout *layout, + struct wlr_output *reference, int x, int y); + +bool wlr_output_layout_intersects(struct wlr_output_layout *layout, + struct wlr_output *reference, int x1, int y1, int x2, int y2); + #endif diff --git a/types/wlr_output_layout.c b/types/wlr_output_layout.c index b4a3565e..ea93610d 100644 --- a/types/wlr_output_layout.c +++ b/types/wlr_output_layout.c @@ -47,6 +47,36 @@ struct wlr_output_layout_output *wlr_output_layout_get( } +static bool output_contains_point( struct wlr_output_layout_output *l_output, + int x, int y, int width, int height) { + return x >= l_output->x && x <= l_output->x + width && + y >= l_output->y && y <= l_output->y + height; +} + +bool wlr_output_layout_contains_point(struct wlr_output_layout *layout, + struct wlr_output *reference, int x, int y) { + struct wlr_output_layout_output *layout_output = wlr_output_layout_get(layout, reference); + int width, height; + wlr_output_effective_resolution(layout_output->output, &width, &height); + return output_contains_point(layout_output, x, y, width, height); +} + +bool wlr_output_layout_intersects(struct wlr_output_layout *layout, + struct wlr_output *reference, int x1, int y1, int x2, int y2) { + struct wlr_output_layout_output *l_output = wlr_output_layout_get(layout, reference); + if (!l_output) { + return false; + } + int width, height; + wlr_output_effective_resolution(l_output->output, &width, &height); + + // the output must contain one of the points + return output_contains_point(l_output, x1, y1, width, height) || + output_contains_point(l_output, x2, y2, width, height) || + output_contains_point(l_output, x2, y1, width, height) || + output_contains_point(l_output, y2, x1, width, height); +} + struct wlr_output *wlr_output_layout_output_at(struct wlr_output_layout *layout, double x, double y) { struct wlr_output *ret = NULL; |