From e192d8773181681baa5f189b3375992ff41bc5e0 Mon Sep 17 00:00:00 2001 From: Simon Zeni Date: Thu, 1 Jul 2021 16:36:01 -0400 Subject: move wlr_box from /types to /util --- backend/drm/drm.c | 1 + examples/fullscreen-shell.c | 1 + examples/output-layout.c | 1 + examples/quads.c | 1 + examples/tablet.c | 2 +- include/backend/wayland.h | 1 - include/wlr/interfaces/wlr_output.h | 1 - include/wlr/render/interface.h | 4 +- include/wlr/render/wlr_renderer.h | 3 +- include/wlr/types/wlr_box.h | 39 +------- include/wlr/types/wlr_cursor.h | 2 +- include/wlr/types/wlr_layer_shell_v1.h | 2 +- include/wlr/types/wlr_matrix.h | 5 +- include/wlr/types/wlr_output_damage.h | 3 +- include/wlr/types/wlr_output_layout.h | 2 +- include/wlr/types/wlr_pointer_constraints_v1.h | 1 - include/wlr/types/wlr_screencopy_v1.h | 2 +- include/wlr/types/wlr_surface.h | 2 +- include/wlr/types/wlr_xdg_shell.h | 5 +- include/wlr/util/box.h | 42 +++++++++ render/gles2/renderer.c | 1 + render/pixman/renderer.c | 1 + render/wlr_renderer.c | 1 + types/meson.build | 1 - types/wlr_box.c | 122 ------------------------- types/wlr_cursor.c | 1 + types/wlr_matrix.c | 2 +- types/wlr_output.c | 2 +- types/wlr_output_damage.c | 2 +- types/wlr_output_layout.c | 2 +- types/wlr_pointer_constraints_v1.c | 2 +- types/wlr_screencopy_v1.c | 1 + types/xdg_shell/wlr_xdg_surface.c | 1 + util/box.c | 121 ++++++++++++++++++++++++ util/meson.build | 1 + util/region.c | 1 - 36 files changed, 200 insertions(+), 182 deletions(-) create mode 100644 include/wlr/util/box.h delete mode 100644 types/wlr_box.c create mode 100644 util/box.c diff --git a/backend/drm/drm.c b/backend/drm/drm.c index b6b4baf6..fb498a5d 100644 --- a/backend/drm/drm.c +++ b/backend/drm/drm.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include diff --git a/examples/fullscreen-shell.c b/examples/fullscreen-shell.c index 52776c55..c4916a71 100644 --- a/examples/fullscreen-shell.c +++ b/examples/fullscreen-shell.c @@ -14,6 +14,7 @@ #include #include #include +#include #include /** diff --git a/examples/output-layout.c b/examples/output-layout.c index 121ea15b..356d5d56 100644 --- a/examples/output-layout.c +++ b/examples/output-layout.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include "cat.h" diff --git a/examples/quads.c b/examples/quads.c index 8745706e..6696ef7c 100644 --- a/examples/quads.c +++ b/examples/quads.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include diff --git a/examples/tablet.c b/examples/tablet.c index 7d82f441..5d0e8dcc 100644 --- a/examples/tablet.c +++ b/examples/tablet.c @@ -9,13 +9,13 @@ #include #include #include -#include #include #include #include #include #include #include +#include #include #include diff --git a/include/backend/wayland.h b/include/backend/wayland.h index 5d69c248..6f4fa201 100644 --- a/include/backend/wayland.h +++ b/include/backend/wayland.h @@ -8,7 +8,6 @@ #include #include -#include #include #include diff --git a/include/wlr/interfaces/wlr_output.h b/include/wlr/interfaces/wlr_output.h index 83a8c321..83d1b58a 100644 --- a/include/wlr/interfaces/wlr_output.h +++ b/include/wlr/interfaces/wlr_output.h @@ -11,7 +11,6 @@ #include #include -#include #include /** diff --git a/include/wlr/render/interface.h b/include/wlr/render/interface.h index 1e355d43..b3a21b0b 100644 --- a/include/wlr/render/interface.h +++ b/include/wlr/render/interface.h @@ -13,10 +13,12 @@ #include #include #include -#include #include #include +struct wlr_box; +struct wlr_fbox; + struct wlr_renderer_impl { bool (*bind_buffer)(struct wlr_renderer *renderer, struct wlr_buffer *buffer); diff --git a/include/wlr/render/wlr_renderer.h b/include/wlr/render/wlr_renderer.h index 4a98443f..bae2fa97 100644 --- a/include/wlr/render/wlr_renderer.h +++ b/include/wlr/render/wlr_renderer.h @@ -13,7 +13,6 @@ #include #include #include -#include enum wlr_renderer_read_pixels_flags { WLR_RENDERER_READ_PIXELS_Y_INVERT = 1, @@ -22,6 +21,8 @@ enum wlr_renderer_read_pixels_flags { struct wlr_renderer_impl; struct wlr_drm_format_set; struct wlr_buffer; +struct wlr_box; +struct wlr_fbox; struct wlr_renderer { const struct wlr_renderer_impl *impl; diff --git a/include/wlr/types/wlr_box.h b/include/wlr/types/wlr_box.h index 2a407c4d..8720cef8 100644 --- a/include/wlr/types/wlr_box.h +++ b/include/wlr/types/wlr_box.h @@ -1,42 +1,7 @@ -/* - * This an unstable interface of wlroots. No guarantees are made regarding the - * future consistency of this API. - */ -#ifndef WLR_USE_UNSTABLE -#error "Add -DWLR_USE_UNSTABLE to enable unstable wlroots features" -#endif - #ifndef WLR_TYPES_WLR_BOX_H #define WLR_TYPES_WLR_BOX_H -#include -#include -#include - -struct wlr_box { - int x, y; - int width, height; -}; - -struct wlr_fbox { - double x, y; - double width, height; -}; - -void wlr_box_closest_point(const struct wlr_box *box, double x, double y, - double *dest_x, double *dest_y); - -bool wlr_box_intersection(struct wlr_box *dest, const struct wlr_box *box_a, - const struct wlr_box *box_b); - -bool wlr_box_contains_point(const struct wlr_box *box, double x, double y); - -bool wlr_box_empty(const struct wlr_box *box); - -/** - * Transforms a box inside a `width` x `height` box. - */ -void wlr_box_transform(struct wlr_box *dest, const struct wlr_box *box, - enum wl_output_transform transform, int width, int height); +#warning "wlr_box has been moved to wlr/util/box.h" +#include #endif diff --git a/include/wlr/types/wlr_cursor.h b/include/wlr/types/wlr_cursor.h index 58ce8505..71eddc43 100644 --- a/include/wlr/types/wlr_cursor.h +++ b/include/wlr/types/wlr_cursor.h @@ -10,7 +10,6 @@ #define WLR_TYPES_WLR_CURSOR_H #include -#include #include #include #include @@ -26,6 +25,7 @@ * the screen, and so on. */ +struct wlr_box; struct wlr_cursor_state; struct wlr_cursor { diff --git a/include/wlr/types/wlr_layer_shell_v1.h b/include/wlr/types/wlr_layer_shell_v1.h index 3b214dc9..846b9466 100644 --- a/include/wlr/types/wlr_layer_shell_v1.h +++ b/include/wlr/types/wlr_layer_shell_v1.h @@ -8,10 +8,10 @@ #ifndef WLR_TYPES_WLR_LAYER_SHELL_V1_H #define WLR_TYPES_WLR_LAYER_SHELL_V1_H + #include #include #include -#include #include #include "wlr-layer-shell-unstable-v1-protocol.h" diff --git a/include/wlr/types/wlr_matrix.h b/include/wlr/types/wlr_matrix.h index ede78cb1..1a8b5be5 100644 --- a/include/wlr/types/wlr_matrix.h +++ b/include/wlr/types/wlr_matrix.h @@ -16,8 +16,9 @@ #ifndef WLR_TYPES_WLR_MATRIX_H #define WLR_TYPES_WLR_MATRIX_H -#include -#include +#include + +struct wlr_box; /** Writes the identity matrix into mat */ void wlr_matrix_identity(float mat[static 9]); diff --git a/include/wlr/types/wlr_output_damage.h b/include/wlr/types/wlr_output_damage.h index e4b1f862..e7c609ed 100644 --- a/include/wlr/types/wlr_output_damage.h +++ b/include/wlr/types/wlr_output_damage.h @@ -11,7 +11,6 @@ #include #include -#include #include /** @@ -21,6 +20,8 @@ */ #define WLR_OUTPUT_DAMAGE_PREVIOUS_LEN 2 +struct wlr_box; + /** * Tracks damage for an output. * diff --git a/include/wlr/types/wlr_output_layout.h b/include/wlr/types/wlr_output_layout.h index 4f4266e9..5cb742c6 100644 --- a/include/wlr/types/wlr_output_layout.h +++ b/include/wlr/types/wlr_output_layout.h @@ -11,9 +11,9 @@ #include #include -#include #include +struct wlr_box; struct wlr_output_layout_state; /** diff --git a/include/wlr/types/wlr_pointer_constraints_v1.h b/include/wlr/types/wlr_pointer_constraints_v1.h index 0c49e3bf..90438729 100644 --- a/include/wlr/types/wlr_pointer_constraints_v1.h +++ b/include/wlr/types/wlr_pointer_constraints_v1.h @@ -12,7 +12,6 @@ #include #include #include -#include #include #include "pointer-constraints-unstable-v1-protocol.h" diff --git a/include/wlr/types/wlr_screencopy_v1.h b/include/wlr/types/wlr_screencopy_v1.h index 1c45f905..aaa300b3 100644 --- a/include/wlr/types/wlr_screencopy_v1.h +++ b/include/wlr/types/wlr_screencopy_v1.h @@ -11,7 +11,7 @@ #include #include -#include +#include struct wlr_screencopy_manager_v1 { struct wl_global *global; diff --git a/include/wlr/types/wlr_surface.h b/include/wlr/types/wlr_surface.h index 72dc4b30..7668c83d 100644 --- a/include/wlr/types/wlr_surface.h +++ b/include/wlr/types/wlr_surface.h @@ -14,8 +14,8 @@ #include #include #include -#include #include +#include enum wlr_surface_state_field { WLR_SURFACE_STATE_BUFFER = 1 << 0, diff --git a/include/wlr/types/wlr_xdg_shell.h b/include/wlr/types/wlr_xdg_shell.h index 856648f9..f80c6685 100644 --- a/include/wlr/types/wlr_xdg_shell.h +++ b/include/wlr/types/wlr_xdg_shell.h @@ -8,9 +8,10 @@ #ifndef WLR_TYPES_WLR_XDG_SHELL_H #define WLR_TYPES_WLR_XDG_SHELL_H -#include -#include + #include +#include +#include #include "xdg-shell-protocol.h" struct wlr_xdg_shell { diff --git a/include/wlr/util/box.h b/include/wlr/util/box.h new file mode 100644 index 00000000..2a407c4d --- /dev/null +++ b/include/wlr/util/box.h @@ -0,0 +1,42 @@ +/* + * This an unstable interface of wlroots. No guarantees are made regarding the + * future consistency of this API. + */ +#ifndef WLR_USE_UNSTABLE +#error "Add -DWLR_USE_UNSTABLE to enable unstable wlroots features" +#endif + +#ifndef WLR_TYPES_WLR_BOX_H +#define WLR_TYPES_WLR_BOX_H + +#include +#include +#include + +struct wlr_box { + int x, y; + int width, height; +}; + +struct wlr_fbox { + double x, y; + double width, height; +}; + +void wlr_box_closest_point(const struct wlr_box *box, double x, double y, + double *dest_x, double *dest_y); + +bool wlr_box_intersection(struct wlr_box *dest, const struct wlr_box *box_a, + const struct wlr_box *box_b); + +bool wlr_box_contains_point(const struct wlr_box *box, double x, double y); + +bool wlr_box_empty(const struct wlr_box *box); + +/** + * Transforms a box inside a `width` x `height` box. + */ +void wlr_box_transform(struct wlr_box *dest, const struct wlr_box *box, + enum wl_output_transform transform, int width, int height); + +#endif diff --git a/render/gles2/renderer.c b/render/gles2/renderer.c index a31896bf..7ca08d9f 100644 --- a/render/gles2/renderer.c +++ b/render/gles2/renderer.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include "render/egl.h" #include "render/gles2.h" diff --git a/render/pixman/renderer.c b/render/pixman/renderer.c index 71af1939..ff9c0f3a 100644 --- a/render/pixman/renderer.c +++ b/render/pixman/renderer.c @@ -5,6 +5,7 @@ #include #include #include +#include #include #include "render/pixman.h" diff --git a/render/wlr_renderer.c b/render/wlr_renderer.c index 2fa79b27..cf307bd3 100644 --- a/render/wlr_renderer.c +++ b/render/wlr_renderer.c @@ -5,6 +5,7 @@ #include #include #include +#include #include #include diff --git a/types/meson.build b/types/meson.build index cf644978..6a650035 100644 --- a/types/meson.build +++ b/types/meson.build @@ -16,7 +16,6 @@ wlr_files += files( 'xdg_shell/wlr_xdg_shell.c', 'xdg_shell/wlr_xdg_surface.c', 'xdg_shell/wlr_xdg_toplevel.c', - 'wlr_box.c', 'wlr_buffer.c', 'wlr_compositor.c', 'wlr_cursor.c', diff --git a/types/wlr_box.c b/types/wlr_box.c deleted file mode 100644 index 3e33ba97..00000000 --- a/types/wlr_box.c +++ /dev/null @@ -1,122 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include - -void wlr_box_closest_point(const struct wlr_box *box, double x, double y, - double *dest_x, double *dest_y) { - // if box is empty, then it contains no points, so no closest point either - if (box->width <= 0 || box->height <= 0) { - *dest_x = NAN; - *dest_y = NAN; - return; - } - - // find the closest x point - if (x < box->x) { - *dest_x = box->x; - } else if (x >= box->x + box->width) { - *dest_x = box->x + box->width - 1; - } else { - *dest_x = x; - } - - // find closest y point - if (y < box->y) { - *dest_y = box->y; - } else if (y >= box->y + box->height) { - *dest_y = box->y + box->height - 1; - } else { - *dest_y = y; - } -} - -bool wlr_box_empty(const struct wlr_box *box) { - return box == NULL || box->width <= 0 || box->height <= 0; -} - -bool wlr_box_intersection(struct wlr_box *dest, const struct wlr_box *box_a, - const struct wlr_box *box_b) { - bool a_empty = wlr_box_empty(box_a); - bool b_empty = wlr_box_empty(box_b); - - if (a_empty || b_empty) { - dest->x = 0; - dest->y = 0; - dest->width = -100; - dest->height = -100; - return false; - } - - int x1 = fmax(box_a->x, box_b->x); - int y1 = fmax(box_a->y, box_b->y); - int x2 = fmin(box_a->x + box_a->width, box_b->x + box_b->width); - int y2 = fmin(box_a->y + box_a->height, box_b->y + box_b->height); - - dest->x = x1; - dest->y = y1; - dest->width = x2 - x1; - dest->height = y2 - y1; - - return !wlr_box_empty(dest); -} - -bool wlr_box_contains_point(const struct wlr_box *box, double x, double y) { - if (wlr_box_empty(box)) { - return false; - } else { - return x >= box->x && x < box->x + box->width && - y >= box->y && y < box->y + box->height; - } -} - -void wlr_box_transform(struct wlr_box *dest, const struct wlr_box *box, - enum wl_output_transform transform, int width, int height) { - struct wlr_box src = *box; - - if (transform % 2 == 0) { - dest->width = src.width; - dest->height = src.height; - } else { - dest->width = src.height; - dest->height = src.width; - } - - switch (transform) { - case WL_OUTPUT_TRANSFORM_NORMAL: - dest->x = src.x; - dest->y = src.y; - break; - case WL_OUTPUT_TRANSFORM_90: - dest->x = height - src.y - src.height; - dest->y = src.x; - break; - case WL_OUTPUT_TRANSFORM_180: - dest->x = width - src.x - src.width; - dest->y = height - src.y - src.height; - break; - case WL_OUTPUT_TRANSFORM_270: - dest->x = src.y; - dest->y = width - src.x - src.width; - break; - case WL_OUTPUT_TRANSFORM_FLIPPED: - dest->x = width - src.x - src.width; - dest->y = src.y; - break; - case WL_OUTPUT_TRANSFORM_FLIPPED_90: - dest->x = src.y; - dest->y = src.x; - break; - case WL_OUTPUT_TRANSFORM_FLIPPED_180: - dest->x = src.x; - dest->y = height - src.y - src.height; - break; - case WL_OUTPUT_TRANSFORM_FLIPPED_270: - dest->x = height - src.y - src.height; - dest->y = width - src.x - src.width; - break; - } -} diff --git a/types/wlr_cursor.c b/types/wlr_cursor.c index aff7859d..2bc22668 100644 --- a/types/wlr_cursor.c +++ b/types/wlr_cursor.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include "util/signal.h" diff --git a/types/wlr_matrix.c b/types/wlr_matrix.c index 775b991c..a1b2b31a 100644 --- a/types/wlr_matrix.c +++ b/types/wlr_matrix.c @@ -2,8 +2,8 @@ #include #include #include -#include #include +#include void wlr_matrix_identity(float mat[static 9]) { static const float identity[9] = { diff --git a/types/wlr_output.c b/types/wlr_output.c index 0e21fcf2..325b0233 100644 --- a/types/wlr_output.c +++ b/types/wlr_output.c @@ -9,11 +9,11 @@ #include #include #include -#include #include #include #include #include +#include #include #include #include "backend/backend.h" diff --git a/types/wlr_output_damage.c b/types/wlr_output_damage.c index 76dac57f..b0655a65 100644 --- a/types/wlr_output_damage.c +++ b/types/wlr_output_damage.c @@ -2,9 +2,9 @@ #include #include #include -#include #include #include +#include #include "util/signal.h" static void output_handle_destroy(struct wl_listener *listener, void *data) { diff --git a/types/wlr_output_layout.c b/types/wlr_output_layout.c index 3286b8f8..8c474387 100644 --- a/types/wlr_output_layout.c +++ b/types/wlr_output_layout.c @@ -2,9 +2,9 @@ #include #include #include -#include #include #include +#include #include #include "util/signal.h" diff --git a/types/wlr_pointer_constraints_v1.c b/types/wlr_pointer_constraints_v1.c index eca45984..d608b778 100644 --- a/types/wlr_pointer_constraints_v1.c +++ b/types/wlr_pointer_constraints_v1.c @@ -4,9 +4,9 @@ #include #include #include -#include #include #include +#include #include #include "util/signal.h" diff --git a/types/wlr_screencopy_v1.c b/types/wlr_screencopy_v1.c index ba55bbe2..9469c53f 100644 --- a/types/wlr_screencopy_v1.c +++ b/types/wlr_screencopy_v1.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include "wlr-screencopy-unstable-v1-protocol.h" #include "render/pixel_format.h" diff --git a/types/xdg_shell/wlr_xdg_surface.c b/types/xdg_shell/wlr_xdg_surface.c index 0f85ac2d..33cf3319 100644 --- a/types/xdg_shell/wlr_xdg_surface.c +++ b/types/xdg_shell/wlr_xdg_surface.c @@ -1,6 +1,7 @@ #include #include #include +#include #include #include "types/wlr_xdg_shell.h" #include "util/signal.h" diff --git a/util/box.c b/util/box.c new file mode 100644 index 00000000..b382716b --- /dev/null +++ b/util/box.c @@ -0,0 +1,121 @@ +#include +#include +#include +#include +#include +#include + +void wlr_box_closest_point(const struct wlr_box *box, double x, double y, + double *dest_x, double *dest_y) { + // if box is empty, then it contains no points, so no closest point either + if (box->width <= 0 || box->height <= 0) { + *dest_x = NAN; + *dest_y = NAN; + return; + } + + // find the closest x point + if (x < box->x) { + *dest_x = box->x; + } else if (x >= box->x + box->width) { + *dest_x = box->x + box->width - 1; + } else { + *dest_x = x; + } + + // find closest y point + if (y < box->y) { + *dest_y = box->y; + } else if (y >= box->y + box->height) { + *dest_y = box->y + box->height - 1; + } else { + *dest_y = y; + } +} + +bool wlr_box_empty(const struct wlr_box *box) { + return box == NULL || box->width <= 0 || box->height <= 0; +} + +bool wlr_box_intersection(struct wlr_box *dest, const struct wlr_box *box_a, + const struct wlr_box *box_b) { + bool a_empty = wlr_box_empty(box_a); + bool b_empty = wlr_box_empty(box_b); + + if (a_empty || b_empty) { + dest->x = 0; + dest->y = 0; + dest->width = -100; + dest->height = -100; + return false; + } + + int x1 = fmax(box_a->x, box_b->x); + int y1 = fmax(box_a->y, box_b->y); + int x2 = fmin(box_a->x + box_a->width, box_b->x + box_b->width); + int y2 = fmin(box_a->y + box_a->height, box_b->y + box_b->height); + + dest->x = x1; + dest->y = y1; + dest->width = x2 - x1; + dest->height = y2 - y1; + + return !wlr_box_empty(dest); +} + +bool wlr_box_contains_point(const struct wlr_box *box, double x, double y) { + if (wlr_box_empty(box)) { + return false; + } else { + return x >= box->x && x < box->x + box->width && + y >= box->y && y < box->y + box->height; + } +} + +void wlr_box_transform(struct wlr_box *dest, const struct wlr_box *box, + enum wl_output_transform transform, int width, int height) { + struct wlr_box src = *box; + + if (transform % 2 == 0) { + dest->width = src.width; + dest->height = src.height; + } else { + dest->width = src.height; + dest->height = src.width; + } + + switch (transform) { + case WL_OUTPUT_TRANSFORM_NORMAL: + dest->x = src.x; + dest->y = src.y; + break; + case WL_OUTPUT_TRANSFORM_90: + dest->x = height - src.y - src.height; + dest->y = src.x; + break; + case WL_OUTPUT_TRANSFORM_180: + dest->x = width - src.x - src.width; + dest->y = height - src.y - src.height; + break; + case WL_OUTPUT_TRANSFORM_270: + dest->x = src.y; + dest->y = width - src.x - src.width; + break; + case WL_OUTPUT_TRANSFORM_FLIPPED: + dest->x = width - src.x - src.width; + dest->y = src.y; + break; + case WL_OUTPUT_TRANSFORM_FLIPPED_90: + dest->x = src.y; + dest->y = src.x; + break; + case WL_OUTPUT_TRANSFORM_FLIPPED_180: + dest->x = src.x; + dest->y = height - src.y - src.height; + break; + case WL_OUTPUT_TRANSFORM_FLIPPED_270: + dest->x = height - src.y - src.height; + dest->y = width - src.x - src.width; + break; + } +} diff --git a/util/meson.build b/util/meson.build index 5e31cbbe..c2b46749 100644 --- a/util/meson.build +++ b/util/meson.build @@ -1,5 +1,6 @@ wlr_files += files( 'array.c', + 'box.c', 'global.c', 'log.c', 'region.c', diff --git a/util/region.c b/util/region.c index f39f0469..817d7b1a 100644 --- a/util/region.c +++ b/util/region.c @@ -2,7 +2,6 @@ #include #include #include -#include #include void wlr_region_scale(pixman_region32_t *dst, pixman_region32_t *src, -- cgit v1.2.3