mirror of
https://gitlab.freedesktop.org/wlroots/wlroots.git
synced 2025-11-27 06:59:46 -05:00
move wlr_box from /types to /util
This commit is contained in:
parent
d975f35bba
commit
e192d87731
35 changed files with 80 additions and 62 deletions
|
|
@ -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',
|
||||
|
|
|
|||
122
types/wlr_box.c
122
types/wlr_box.c
|
|
@ -1,122 +0,0 @@
|
|||
#include <limits.h>
|
||||
#include <math.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <wayland-server-protocol.h>
|
||||
#include <wlr/types/wlr_box.h>
|
||||
#include <wlr/util/log.h>
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
@ -10,6 +10,7 @@
|
|||
#include <wlr/types/wlr_pointer.h>
|
||||
#include <wlr/types/wlr_tablet_tool.h>
|
||||
#include <wlr/types/wlr_touch.h>
|
||||
#include <wlr/util/box.h>
|
||||
#include <wlr/util/log.h>
|
||||
#include "util/signal.h"
|
||||
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@
|
|||
#include <string.h>
|
||||
#include <wayland-server-protocol.h>
|
||||
#include <wlr/types/wlr_matrix.h>
|
||||
#include <wlr/types/wlr_box.h>
|
||||
#include <wlr/types/wlr_output.h>
|
||||
#include <wlr/util/box.h>
|
||||
|
||||
void wlr_matrix_identity(float mat[static 9]) {
|
||||
static const float identity[9] = {
|
||||
|
|
|
|||
|
|
@ -9,11 +9,11 @@
|
|||
#include <wlr/interfaces/wlr_output.h>
|
||||
#include <wlr/render/interface.h>
|
||||
#include <wlr/render/wlr_renderer.h>
|
||||
#include <wlr/types/wlr_box.h>
|
||||
#include <wlr/types/wlr_matrix.h>
|
||||
#include <wlr/types/wlr_output.h>
|
||||
#include <wlr/types/wlr_seat.h>
|
||||
#include <wlr/types/wlr_surface.h>
|
||||
#include <wlr/util/box.h>
|
||||
#include <wlr/util/log.h>
|
||||
#include <wlr/util/region.h>
|
||||
#include "backend/backend.h"
|
||||
|
|
|
|||
|
|
@ -2,9 +2,9 @@
|
|||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
#include <wayland-server-core.h>
|
||||
#include <wlr/types/wlr_box.h>
|
||||
#include <wlr/types/wlr_output_damage.h>
|
||||
#include <wlr/types/wlr_output.h>
|
||||
#include <wlr/util/box.h>
|
||||
#include "util/signal.h"
|
||||
|
||||
static void output_handle_destroy(struct wl_listener *listener, void *data) {
|
||||
|
|
|
|||
|
|
@ -2,9 +2,9 @@
|
|||
#include <float.h>
|
||||
#include <limits.h>
|
||||
#include <stdlib.h>
|
||||
#include <wlr/types/wlr_box.h>
|
||||
#include <wlr/types/wlr_output_layout.h>
|
||||
#include <wlr/types/wlr_output.h>
|
||||
#include <wlr/util/box.h>
|
||||
#include <wlr/util/log.h>
|
||||
#include "util/signal.h"
|
||||
|
||||
|
|
|
|||
|
|
@ -4,9 +4,9 @@
|
|||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <wayland-server-core.h>
|
||||
#include <wlr/types/wlr_box.h>
|
||||
#include <wlr/types/wlr_pointer_constraints_v1.h>
|
||||
#include <wlr/types/wlr_region.h>
|
||||
#include <wlr/util/box.h>
|
||||
#include <wlr/util/log.h>
|
||||
#include "util/signal.h"
|
||||
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@
|
|||
#include <wlr/types/wlr_linux_dmabuf_v1.h>
|
||||
#include <wlr/types/wlr_screencopy_v1.h>
|
||||
#include <wlr/backend.h>
|
||||
#include <wlr/util/box.h>
|
||||
#include <wlr/util/log.h>
|
||||
#include "wlr-screencopy-unstable-v1-protocol.h"
|
||||
#include "render/pixel_format.h"
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <wlr/util/box.h>
|
||||
#include <wlr/util/log.h>
|
||||
#include "types/wlr_xdg_shell.h"
|
||||
#include "util/signal.h"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue