mirror of
https://gitlab.freedesktop.org/wayland/weston
synced 2024-07-05 17:29:06 +00:00
libweston: Make a common helper for clamping a coord to an output
This is a tricky bit of code and we use it in two places. Let's make a single implementation. Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
This commit is contained in:
parent
71e38cf2ef
commit
18cce195d3
|
@ -2040,6 +2040,10 @@ struct weston_coord_buffer __attribute__ ((warn_unused_result))
|
||||||
weston_coord_surface_to_buffer(const struct weston_surface *surface,
|
weston_coord_surface_to_buffer(const struct weston_surface *surface,
|
||||||
struct weston_coord_surface coord);
|
struct weston_coord_surface coord);
|
||||||
|
|
||||||
|
struct weston_coord_global __attribute__ ((warn_unused_result))
|
||||||
|
weston_coord_global_clamp_for_output(struct weston_coord_global pos,
|
||||||
|
const struct weston_output *output);
|
||||||
|
|
||||||
void
|
void
|
||||||
weston_view_activate_input(struct weston_view *view,
|
weston_view_activate_input(struct weston_view *view,
|
||||||
struct weston_seat *seat,
|
struct weston_seat *seat,
|
||||||
|
|
|
@ -406,7 +406,6 @@ weston_mode_switch_finish(struct weston_output *output,
|
||||||
* lower-right corner */
|
* lower-right corner */
|
||||||
wl_list_for_each(seat, &output->compositor->seat_list, link) {
|
wl_list_for_each(seat, &output->compositor->seat_list, link) {
|
||||||
struct weston_pointer *pointer = weston_seat_get_pointer(seat);
|
struct weston_pointer *pointer = weston_seat_get_pointer(seat);
|
||||||
double quantum = 1.0 / 1024.0;
|
|
||||||
int32_t x, y;
|
int32_t x, y;
|
||||||
|
|
||||||
if (!pointer)
|
if (!pointer)
|
||||||
|
@ -419,11 +418,8 @@ weston_mode_switch_finish(struct weston_output *output,
|
||||||
weston_output_contains_coord(output, pointer->pos))
|
weston_output_contains_coord(output, pointer->pos))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (pointer->pos.c.x >= output->pos.c.x + output->width - quantum)
|
pointer->pos = weston_coord_global_clamp_for_output(pointer->pos,
|
||||||
pointer->pos.c.x = output->pos.c.x + output->width - quantum;
|
output);
|
||||||
|
|
||||||
if (pointer->pos.c.y >= output->pos.c.y + output->height - quantum)
|
|
||||||
pointer->pos.c.y = output->pos.c.y + output->height - quantum;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pixman_region32_fini(&old_output_region);
|
pixman_region32_fini(&old_output_region);
|
||||||
|
@ -905,6 +901,27 @@ weston_coord_surface_to_buffer(const struct weston_surface *surface,
|
||||||
return tmp;
|
return tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
WL_EXPORT struct weston_coord_global
|
||||||
|
weston_coord_global_clamp_for_output(struct weston_coord_global pos,
|
||||||
|
const struct weston_output *output)
|
||||||
|
{
|
||||||
|
struct weston_coord_global clamped_pos;
|
||||||
|
double quantum = 1.0 / 1024.0;
|
||||||
|
int x = pos.c.x;
|
||||||
|
int y = pos.c.y;
|
||||||
|
|
||||||
|
if (x < output->pos.c.x)
|
||||||
|
clamped_pos.c.x = output->pos.c.x;
|
||||||
|
else if (x >= output->pos.c.x + output->width - quantum)
|
||||||
|
clamped_pos.c.x = output->pos.c.x + output->width - quantum;
|
||||||
|
if (y < output->pos.c.y)
|
||||||
|
clamped_pos.c.y = output->pos.c.y;
|
||||||
|
else if (y >= output->pos.c.y + output->height - quantum)
|
||||||
|
clamped_pos.c.y = output->pos.c.y + output->height - quantum;
|
||||||
|
|
||||||
|
return clamped_pos;
|
||||||
|
}
|
||||||
|
|
||||||
WL_EXPORT pixman_box32_t
|
WL_EXPORT pixman_box32_t
|
||||||
weston_matrix_transform_rect(struct weston_matrix *matrix,
|
weston_matrix_transform_rect(struct weston_matrix *matrix,
|
||||||
pixman_box32_t rect)
|
pixman_box32_t rect)
|
||||||
|
|
|
@ -2141,21 +2141,7 @@ weston_pointer_clamp_for_output(struct weston_pointer *pointer,
|
||||||
struct weston_output *output,
|
struct weston_output *output,
|
||||||
struct weston_coord_global pos)
|
struct weston_coord_global pos)
|
||||||
{
|
{
|
||||||
double quantum = 1.0 / 1024.0;
|
return weston_coord_global_clamp_for_output(pos, output);
|
||||||
struct weston_coord_global out = pos;
|
|
||||||
int x = pos.c.x;
|
|
||||||
int y = pos.c.y;
|
|
||||||
|
|
||||||
if (x < output->pos.c.x)
|
|
||||||
out.c.x = output->pos.c.x;
|
|
||||||
else if (x >= output->pos.c.x + output->width - quantum)
|
|
||||||
out.c.x = output->pos.c.x + output->width - quantum;
|
|
||||||
if (y < output->pos.c.y)
|
|
||||||
out.c.y = output->pos.c.y;
|
|
||||||
else if (y >= output->pos.c.y + output->height - quantum)
|
|
||||||
out.c.y = output->pos.c.y + output->height - quantum;
|
|
||||||
|
|
||||||
return out;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
WL_EXPORT struct weston_coord_global
|
WL_EXPORT struct weston_coord_global
|
||||||
|
|
Loading…
Reference in New Issue
Block a user