libweston: Add weston_coord_truncate()

Truncating a weston coord to integer values is something we do
frequently enough to warrant a helper function.

Use this in the kiosk and desktop shells where appropriate.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
This commit is contained in:
Derek Foreman 2023-06-13 07:14:53 -05:00 committed by Pekka Paalanen
parent ca1f6936c4
commit 1f81c082b5
3 changed files with 12 additions and 4 deletions

View File

@ -982,8 +982,9 @@ touch_move_grab_motion(struct weston_touch_grab *grab,
es = weston_desktop_surface_get_surface(shsurf->desktop_surface); es = weston_desktop_surface_get_surface(shsurf->desktop_surface);
pos.c.x = (int)(pos.c.x + wl_fixed_to_double(move->dx)); pos.c.x = pos.c.x + wl_fixed_to_double(move->dx);
pos.c.y = (int)(pos.c.y + wl_fixed_to_double(move->dy)); pos.c.y = pos.c.y + wl_fixed_to_double(move->dy);
pos.c = weston_coord_truncate(pos.c);
weston_view_set_position(shsurf->view, pos); weston_view_set_position(shsurf->view, pos);
weston_compositor_schedule_repaint(es->compositor); weston_compositor_schedule_repaint(es->compositor);

View File

@ -166,6 +166,12 @@ weston_coord_sub(struct weston_coord a, struct weston_coord b)
return weston_coord(a.x - b.x, a.y - b.y); return weston_coord(a.x - b.x, a.y - b.y);
} }
static inline struct weston_coord __attribute__ ((warn_unused_result))
weston_coord_truncate(struct weston_coord in)
{
return (struct weston_coord){ (int)in.x, (int)in.y };
}
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -171,10 +171,11 @@ touch_move_grab_motion(struct weston_touch_grab *touch_grab,
surface = weston_desktop_surface_get_surface(shsurf->desktop_surface); surface = weston_desktop_surface_get_surface(shsurf->desktop_surface);
dx = (int)(touch->grab_pos.c.x + wl_fixed_to_double(shgrab->dx)); dx = touch->grab_pos.c.x + wl_fixed_to_double(shgrab->dx);
dy = (int)(touch->grab_pos.c.y + wl_fixed_to_double(shgrab->dy)); dy = touch->grab_pos.c.y + wl_fixed_to_double(shgrab->dy);
pos.c = weston_coord(dx, dy); pos.c = weston_coord(dx, dy);
pos.c = weston_coord_truncate(pos.c);
weston_view_set_position(shsurf->view, pos); weston_view_set_position(shsurf->view, pos);
weston_compositor_schedule_repaint(surface->compositor); weston_compositor_schedule_repaint(surface->compositor);