From bb8ef7d271c371b01a1ba8115b75701ed9538340 Mon Sep 17 00:00:00 2001 From: Derek Foreman Date: Wed, 31 Aug 2022 11:48:05 -0500 Subject: [PATCH] libweston: Refactor point in output test This is arguably a little nicer without calling the pixman functions directly. In the future when we have different datatypes for coordinates in different spaces, this test will only be valid on global coordinates, so this change is also a precursor to stronger type validation. Signed-off-by: Derek Foreman --- desktop-shell/shell.c | 5 ++--- include/libweston/libweston.h | 4 ++++ libweston/compositor.c | 10 ++++++++-- libweston/input.c | 9 +++------ 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/desktop-shell/shell.c b/desktop-shell/shell.c index 48005831..922b16b6 100644 --- a/desktop-shell/shell.c +++ b/desktop-shell/shell.c @@ -3836,7 +3836,7 @@ weston_view_set_initial_position(struct weston_view *view, } wl_list_for_each(output, &compositor->output_list, link) { - if (pixman_region32_contains_point(&output->region, ix, iy, NULL)) { + if (weston_output_contains_point(output, ix, iy)) { target_output = output; break; } @@ -4251,8 +4251,7 @@ shell_reposition_view_on_output_change(struct weston_view *view) * otherwise, move it to the first output. */ visible = 0; wl_list_for_each(output, &ec->output_list, link) { - if (pixman_region32_contains_point(&output->region, - x, y, NULL)) { + if (weston_output_contains_point(output, x, y)) { visible = 1; break; } diff --git a/include/libweston/libweston.h b/include/libweston/libweston.h index 4db11111..38d7a6e9 100644 --- a/include/libweston/libweston.h +++ b/include/libweston/libweston.h @@ -2311,6 +2311,10 @@ void weston_output_allow_protection(struct weston_output *output, bool allow_protection); +bool +weston_output_contains_point(struct weston_output *output, + int32_t x, int32_t y); + int weston_compositor_enable_touch_calibrator(struct weston_compositor *compositor, weston_touch_calibration_save_func save); diff --git a/libweston/compositor.c b/libweston/compositor.c index 7b9ebe41..b50334d1 100644 --- a/libweston/compositor.c +++ b/libweston/compositor.c @@ -201,6 +201,13 @@ weston_mode_switch_send_events(struct weston_head *head, } } +WL_EXPORT bool +weston_output_contains_point(struct weston_output *output, + int32_t x, int32_t y) +{ + return pixman_region32_contains_point(&output->region, x, y, NULL); +} + static void weston_mode_switch_finish(struct weston_output *output, int mode_changed, int scale_changed) @@ -234,8 +241,7 @@ weston_mode_switch_finish(struct weston_output *output, if (!pixman_region32_contains_point(&old_output_region, x, y, NULL) || - pixman_region32_contains_point(&output->region, - x, y, NULL)) + weston_output_contains_point(output, x, y)) continue; if (x >= output->x + output->width) diff --git a/libweston/input.c b/libweston/input.c index 6cbb8db0..7cbbdb68 100644 --- a/libweston/input.c +++ b/libweston/input.c @@ -1688,11 +1688,9 @@ weston_pointer_clamp(struct weston_pointer *pointer, wl_fixed_t *fx, wl_fixed_t wl_list_for_each(output, &ec->output_list, link) { if (pointer->seat->output && pointer->seat->output != output) continue; - if (pixman_region32_contains_point(&output->region, - x, y, NULL)) + if (weston_output_contains_point(output, x, y)) valid = 1; - if (pixman_region32_contains_point(&output->region, - old_x, old_y, NULL)) + if (weston_output_contains_point(output, old_x, old_y)) prev = output; } @@ -1757,8 +1755,7 @@ weston_pointer_handle_output_destroy(struct wl_listener *listener, void *data) y = wl_fixed_to_int(pointer->y); wl_list_for_each(output, &ec->output_list, link) { - if (pixman_region32_contains_point(&output->region, - x, y, NULL)) + if (weston_output_contains_point(output, x, y)) return; /* Aproximante the distance from the pointer to the center of