Merge pull request #799 from acrisci/annotate-output-layout-vars

annotate wlr-output-layout coord variables
This commit is contained in:
Drew DeVault 2018-04-02 10:12:13 -04:00 committed by GitHub
commit ee1a2f2f8a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 44 additions and 43 deletions

View file

@ -40,41 +40,42 @@ struct wlr_output_layout_output *wlr_output_layout_get(
struct wlr_output_layout *layout, struct wlr_output *reference); struct wlr_output_layout *layout, struct wlr_output *reference);
struct wlr_output *wlr_output_layout_output_at(struct wlr_output_layout *layout, struct wlr_output *wlr_output_layout_output_at(struct wlr_output_layout *layout,
double x, double y); double lx, double ly);
void wlr_output_layout_add(struct wlr_output_layout *layout, void wlr_output_layout_add(struct wlr_output_layout *layout,
struct wlr_output *output, int x, int y); struct wlr_output *output, int lx, int ly);
void wlr_output_layout_move(struct wlr_output_layout *layout, void wlr_output_layout_move(struct wlr_output_layout *layout,
struct wlr_output *output, int x, int y); struct wlr_output *output, int lx, int ly);
void wlr_output_layout_remove(struct wlr_output_layout *layout, void wlr_output_layout_remove(struct wlr_output_layout *layout,
struct wlr_output *output); struct wlr_output *output);
/** /**
* Given x and y as pointers to global coordinates, adjusts them to local output * Given x and y in layout coordinates, adjusts them to local output
* coordinates relative to the given reference output. * coordinates relative to the given reference output.
*/ */
void wlr_output_layout_output_coords(struct wlr_output_layout *layout, void wlr_output_layout_output_coords(struct wlr_output_layout *layout,
struct wlr_output *reference, double *x, double *y); struct wlr_output *reference, double *lx, double *ly);
bool wlr_output_layout_contains_point(struct wlr_output_layout *layout, bool wlr_output_layout_contains_point(struct wlr_output_layout *layout,
struct wlr_output *reference, int x, int y); struct wlr_output *reference, int lx, int ly);
bool wlr_output_layout_intersects(struct wlr_output_layout *layout, bool wlr_output_layout_intersects(struct wlr_output_layout *layout,
struct wlr_output *reference, const struct wlr_box *target_box); struct wlr_output *reference, const struct wlr_box *target_lbox);
/** /**
* Get the closest point on this layout from the given point from the reference * Get the closest point on this layout from the given point from the reference
* output. If reference is NULL, gets the closest point from the entire layout. * output. If reference is NULL, gets the closest point from the entire layout.
*/ */
void wlr_output_layout_closest_point(struct wlr_output_layout *layout, void wlr_output_layout_closest_point(struct wlr_output_layout *layout,
struct wlr_output *reference, double x, double y, double *dest_x, struct wlr_output *reference, double lx, double ly, double *dest_lx,
double *dest_y); double *dest_ly);
/** /**
* Get the box of the layout for the given reference output. If `reference` * Get the box of the layout for the given reference output in layout
* is NULL, the box will be for the extents of the entire layout. * coordinates. If `reference` is NULL, the box will be for the extents of the
* entire layout.
*/ */
struct wlr_box *wlr_output_layout_get_box( struct wlr_box *wlr_output_layout_get_box(
struct wlr_output_layout *layout, struct wlr_output *reference); struct wlr_output_layout *layout, struct wlr_output *reference);
@ -109,6 +110,6 @@ enum wlr_direction {
*/ */
struct wlr_output *wlr_output_layout_adjacent_output( struct wlr_output *wlr_output_layout_adjacent_output(
struct wlr_output_layout *layout, enum wlr_direction direction, struct wlr_output_layout *layout, enum wlr_direction direction,
struct wlr_output *reference, double ref_x, double ref_y); struct wlr_output *reference, double ref_lx, double ref_ly);
#endif #endif

View file

@ -191,7 +191,7 @@ static struct wlr_output_layout_output *wlr_output_layout_output_create(
} }
void wlr_output_layout_add(struct wlr_output_layout *layout, void wlr_output_layout_add(struct wlr_output_layout *layout,
struct wlr_output *output, int x, int y) { struct wlr_output *output, int lx, int ly) {
struct wlr_output_layout_output *l_output = struct wlr_output_layout_output *l_output =
wlr_output_layout_get(layout, output); wlr_output_layout_get(layout, output);
if (!l_output) { if (!l_output) {
@ -201,8 +201,8 @@ void wlr_output_layout_add(struct wlr_output_layout *layout,
return; return;
} }
} }
l_output->x = x; l_output->x = lx;
l_output->y = y; l_output->y = ly;
l_output->state->auto_configured = false; l_output->state->auto_configured = false;
wlr_output_layout_reconfigure(layout); wlr_output_layout_reconfigure(layout);
wlr_output_create_global(output); wlr_output_create_global(output);
@ -221,19 +221,19 @@ struct wlr_output_layout_output *wlr_output_layout_get(
} }
bool wlr_output_layout_contains_point(struct wlr_output_layout *layout, bool wlr_output_layout_contains_point(struct wlr_output_layout *layout,
struct wlr_output *reference, int x, int y) { struct wlr_output *reference, int lx, int ly) {
if (reference) { if (reference) {
struct wlr_output_layout_output *l_output = struct wlr_output_layout_output *l_output =
wlr_output_layout_get(layout, reference); wlr_output_layout_get(layout, reference);
struct wlr_box *box = wlr_output_layout_output_get_box(l_output); struct wlr_box *box = wlr_output_layout_output_get_box(l_output);
return wlr_box_contains_point(box, x, y); return wlr_box_contains_point(box, lx, ly);
} else { } else {
return !!wlr_output_layout_output_at(layout, x, y); return !!wlr_output_layout_output_at(layout, lx, ly);
} }
} }
bool wlr_output_layout_intersects(struct wlr_output_layout *layout, bool wlr_output_layout_intersects(struct wlr_output_layout *layout,
struct wlr_output *reference, const struct wlr_box *target_box) { struct wlr_output *reference, const struct wlr_box *target_lbox) {
struct wlr_box out_box; struct wlr_box out_box;
if (reference == NULL) { if (reference == NULL) {
@ -241,7 +241,7 @@ bool wlr_output_layout_intersects(struct wlr_output_layout *layout,
wl_list_for_each(l_output, &layout->outputs, link) { wl_list_for_each(l_output, &layout->outputs, link) {
struct wlr_box *output_box = struct wlr_box *output_box =
wlr_output_layout_output_get_box(l_output); wlr_output_layout_output_get_box(l_output);
if (wlr_box_intersection(output_box, target_box, &out_box)) { if (wlr_box_intersection(output_box, target_lbox, &out_box)) {
return true; return true;
} }
} }
@ -254,16 +254,16 @@ bool wlr_output_layout_intersects(struct wlr_output_layout *layout,
} }
struct wlr_box *output_box = wlr_output_layout_output_get_box(l_output); struct wlr_box *output_box = wlr_output_layout_output_get_box(l_output);
return wlr_box_intersection(output_box, target_box, &out_box); return wlr_box_intersection(output_box, target_lbox, &out_box);
} }
} }
struct wlr_output *wlr_output_layout_output_at(struct wlr_output_layout *layout, struct wlr_output *wlr_output_layout_output_at(struct wlr_output_layout *layout,
double x, double y) { double lx, double ly) {
struct wlr_output_layout_output *l_output; struct wlr_output_layout_output *l_output;
wl_list_for_each(l_output, &layout->outputs, link) { wl_list_for_each(l_output, &layout->outputs, link) {
struct wlr_box *box = wlr_output_layout_output_get_box(l_output); struct wlr_box *box = wlr_output_layout_output_get_box(l_output);
if (wlr_box_contains_point(box, x, y)) { if (wlr_box_contains_point(box, lx, ly)) {
return l_output->output; return l_output->output;
} }
} }
@ -271,12 +271,12 @@ struct wlr_output *wlr_output_layout_output_at(struct wlr_output_layout *layout,
} }
void wlr_output_layout_move(struct wlr_output_layout *layout, void wlr_output_layout_move(struct wlr_output_layout *layout,
struct wlr_output *output, int x, int y) { struct wlr_output *output, int lx, int ly) {
struct wlr_output_layout_output *l_output = struct wlr_output_layout_output *l_output =
wlr_output_layout_get(layout, output); wlr_output_layout_get(layout, output);
if (l_output) { if (l_output) {
l_output->x = x; l_output->x = lx;
l_output->y = y; l_output->y = ly;
l_output->state->auto_configured = false; l_output->state->auto_configured = false;
wlr_output_layout_reconfigure(layout); wlr_output_layout_reconfigure(layout);
} else { } else {
@ -295,25 +295,25 @@ void wlr_output_layout_remove(struct wlr_output_layout *layout,
} }
void wlr_output_layout_output_coords(struct wlr_output_layout *layout, void wlr_output_layout_output_coords(struct wlr_output_layout *layout,
struct wlr_output *reference, double *x, double *y) { struct wlr_output *reference, double *lx, double *ly) {
assert(layout && reference); assert(layout && reference);
double src_x = *x; double src_x = *lx;
double src_y = *y; double src_y = *ly;
struct wlr_output_layout_output *l_output; struct wlr_output_layout_output *l_output;
wl_list_for_each(l_output, &layout->outputs, link) { wl_list_for_each(l_output, &layout->outputs, link) {
if (l_output->output == reference) { if (l_output->output == reference) {
*x = src_x - (double)l_output->x; *lx = src_x - (double)l_output->x;
*y = src_y - (double)l_output->y; *ly = src_y - (double)l_output->y;
return; return;
} }
} }
} }
void wlr_output_layout_closest_point(struct wlr_output_layout *layout, void wlr_output_layout_closest_point(struct wlr_output_layout *layout,
struct wlr_output *reference, double x, double y, double *dest_x, struct wlr_output *reference, double lx, double ly, double *dest_lx,
double *dest_y) { double *dest_ly) {
if (dest_x == NULL && dest_y == NULL) { if (dest_lx == NULL && dest_ly == NULL) {
return; return;
} }
@ -326,11 +326,11 @@ void wlr_output_layout_closest_point(struct wlr_output_layout *layout,
double output_x, output_y, output_distance; double output_x, output_y, output_distance;
struct wlr_box *box = wlr_output_layout_output_get_box(l_output); struct wlr_box *box = wlr_output_layout_output_get_box(l_output);
wlr_box_closest_point(box, x, y, &output_x, &output_y); wlr_box_closest_point(box, lx, ly, &output_x, &output_y);
// calculate squared distance suitable for comparison // calculate squared distance suitable for comparison
output_distance = output_distance =
(x - output_x) * (x - output_x) + (y - output_y) * (y - output_y); (lx - output_x) * (lx - output_x) + (ly - output_y) * (ly - output_y);
if (!isfinite(output_distance)) { if (!isfinite(output_distance)) {
output_distance = DBL_MAX; output_distance = DBL_MAX;
@ -343,11 +343,11 @@ void wlr_output_layout_closest_point(struct wlr_output_layout *layout,
} }
} }
if (dest_x) { if (dest_lx) {
*dest_x = min_x; *dest_lx = min_x;
} }
if (dest_y) { if (dest_ly) {
*dest_y = min_y; *dest_ly = min_y;
} }
} }
@ -433,7 +433,7 @@ struct wlr_output *wlr_output_layout_get_center_output(
struct wlr_output *wlr_output_layout_adjacent_output( struct wlr_output *wlr_output_layout_adjacent_output(
struct wlr_output_layout *layout, enum wlr_direction direction, struct wlr_output_layout *layout, enum wlr_direction direction,
struct wlr_output *reference, double ref_x, double ref_y) { struct wlr_output *reference, double ref_lx, double ref_ly) {
assert(reference); assert(reference);
struct wlr_box *ref_box = wlr_output_layout_get_box(layout, reference); struct wlr_box *ref_box = wlr_output_layout_get_box(layout, reference);
@ -468,9 +468,9 @@ struct wlr_output *wlr_output_layout_adjacent_output(
// calculate distance from the given reference point // calculate distance from the given reference point
double x, y; double x, y;
wlr_output_layout_closest_point(layout, l_output->output, wlr_output_layout_closest_point(layout, l_output->output,
ref_x, ref_y, &x, &y); ref_lx, ref_ly, &x, &y);
double distance = double distance =
(x - ref_x) * (x - ref_x) + (y - ref_y) * (y - ref_y); (x - ref_lx) * (x - ref_lx) + (y - ref_ly) * (y - ref_ly);
if (distance < min_distance) { if (distance < min_distance) {
min_distance = distance; min_distance = distance;
closest_output = l_output->output; closest_output = l_output->output;