From 2ac566d2816c11b6fe6cc569a9cc29f44004aa08 Mon Sep 17 00:00:00 2001 From: Derek Foreman Date: Tue, 13 Jun 2023 08:28:18 -0500 Subject: [PATCH] libweston: Add more weston_coord arithmetic helpers Until now we've only had the unadorned arithmetic functions, but they're easy to abuse and tedious to use. For now, we just add weston_coord_global_add/sub functions and use them where appropriate. Signed-off-by: Derek Foreman --- desktop-shell/shell.c | 10 +++++----- include/libweston/matrix.h | 14 ++++++++++++++ kiosk-shell/kiosk-shell.c | 8 ++++---- libweston/compositor.c | 2 +- 4 files changed, 24 insertions(+), 10 deletions(-) diff --git a/desktop-shell/shell.c b/desktop-shell/shell.c index a8fb451f..53e0071a 100644 --- a/desktop-shell/shell.c +++ b/desktop-shell/shell.c @@ -344,7 +344,7 @@ get_panel_size(struct desktop_shell *shell, view->surface); b = weston_coord_surface_to_global(view, tmp_s); - a.c = weston_coord_sub(b.c, a.c); + a = weston_coord_global_sub(b, a); *width = a.c.x; *height = a.c.y; } @@ -2498,10 +2498,10 @@ desktop_surface_committed(struct weston_desktop_surface *desktop_surface, from_g = weston_coord_surface_to_global(view, from_s); to_g = weston_coord_surface_to_global(view, to_s); - offset.c = weston_coord_sub(to_g.c, from_g.c); - pos.c = weston_coord_add( - weston_view_get_pos_offset_global(view).c, - offset.c); + offset = weston_coord_global_sub(to_g, from_g); + pos = weston_coord_global_add( + weston_view_get_pos_offset_global(view), + offset); weston_view_set_position(shsurf->view, pos); } diff --git a/include/libweston/matrix.h b/include/libweston/matrix.h index 7b4adee1..2bee61fa 100644 --- a/include/libweston/matrix.h +++ b/include/libweston/matrix.h @@ -160,12 +160,26 @@ weston_coord_add(struct weston_coord a, struct weston_coord b) return weston_coord(a.x + b.x, a.y + b.y); } +static inline struct weston_coord_global __attribute__ ((warn_unused_result)) +weston_coord_global_add(struct weston_coord_global a, + struct weston_coord_global b) +{ + return (struct weston_coord_global){ .c = weston_coord_add(a.c, b.c) }; +} + static inline struct weston_coord __attribute__ ((warn_unused_result)) weston_coord_sub(struct weston_coord a, struct weston_coord b) { return weston_coord(a.x - b.x, a.y - b.y); } +static inline struct weston_coord_global __attribute__ ((warn_unused_result)) +weston_coord_global_sub(struct weston_coord_global a, + struct weston_coord_global b) +{ + return (struct weston_coord_global){ .c = weston_coord_sub(a.c, b.c) }; +} + static inline struct weston_coord __attribute__ ((warn_unused_result)) weston_coord_truncate(struct weston_coord in) { diff --git a/kiosk-shell/kiosk-shell.c b/kiosk-shell/kiosk-shell.c index 14bb78a5..960c4e91 100644 --- a/kiosk-shell/kiosk-shell.c +++ b/kiosk-shell/kiosk-shell.c @@ -820,10 +820,10 @@ desktop_surface_committed(struct weston_desktop_surface *desktop_surface, from_g = weston_coord_surface_to_global(shsurf->view, from_s); to_g = weston_coord_surface_to_global(shsurf->view, to_s); - offset.c = weston_coord_sub(to_g.c, from_g.c); - pos.c = weston_coord_add( - weston_view_get_pos_offset_global(shsurf->view).c, - offset.c); + offset = weston_coord_global_sub(to_g, from_g); + pos = weston_coord_global_add( + weston_view_get_pos_offset_global(shsurf->view), + offset); weston_view_set_position(shsurf->view, pos); weston_view_update_transform(shsurf->view); diff --git a/libweston/compositor.c b/libweston/compositor.c index c241ee35..b70878b9 100644 --- a/libweston/compositor.c +++ b/libweston/compositor.c @@ -6496,7 +6496,7 @@ weston_output_set_position(struct weston_output *output, return; } - output->move.c = weston_coord_sub(pos.c, output->pos.c); + output->move = weston_coord_global_sub(pos, output->pos); if (output->move.c.x == 0 && output->move.c.y == 0) return;