Skip to content
This repository has been archived by the owner on Nov 1, 2021. It is now read-only.

Commit

Permalink
Merge pull request #1199 from apreiml/farthest_output
Browse files Browse the repository at this point in the history
introduce wlr_output_layout_farthest_output
  • Loading branch information
RedSoxFan authored Aug 25, 2018
2 parents 6025fca + 5617d2b commit c6955fa
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
3 changes: 3 additions & 0 deletions include/wlr/types/wlr_output_layout.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,5 +126,8 @@ enum wlr_direction {
struct wlr_output *wlr_output_layout_adjacent_output(
struct wlr_output_layout *layout, enum wlr_direction direction,
struct wlr_output *reference, double ref_lx, double ref_ly);
struct wlr_output *wlr_output_layout_farthest_output(
struct wlr_output_layout *layout, enum wlr_direction direction,
struct wlr_output *reference, double ref_lx, double ref_ly);

#endif
31 changes: 27 additions & 4 deletions types/wlr_output_layout.c
Original file line number Diff line number Diff line change
Expand Up @@ -430,15 +430,20 @@ struct wlr_output *wlr_output_layout_get_center_output(
return wlr_output_layout_output_at(layout, dest_x, dest_y);
}

enum distance_selection_method {
NEAREST,
FARTHEST
};

struct wlr_output *wlr_output_layout_adjacent_output(
struct wlr_output *wlr_output_layout_output_in_direction(
struct wlr_output_layout *layout, enum wlr_direction direction,
struct wlr_output *reference, double ref_lx, double ref_ly) {
struct wlr_output *reference, double ref_lx, double ref_ly,
enum distance_selection_method distance_method) {
assert(reference);

struct wlr_box *ref_box = wlr_output_layout_get_box(layout, reference);

double min_distance = DBL_MAX;
double min_distance = (distance_method == NEAREST) ? DBL_MAX : DBL_MIN;
struct wlr_output *closest_output = NULL;
struct wlr_output_layout_output *l_output;
wl_list_for_each(l_output, &layout->outputs, link) {
Expand Down Expand Up @@ -471,10 +476,28 @@ struct wlr_output *wlr_output_layout_adjacent_output(
ref_lx, ref_ly, &x, &y);
double distance =
(x - ref_lx) * (x - ref_lx) + (y - ref_ly) * (y - ref_ly);
if (distance < min_distance) {

if ((distance_method == NEAREST)
? distance < min_distance
: distance > min_distance) {
min_distance = distance;
closest_output = l_output->output;
}
}
return closest_output;
}

struct wlr_output *wlr_output_layout_adjacent_output(
struct wlr_output_layout *layout, enum wlr_direction direction,
struct wlr_output *reference, double ref_lx, double ref_ly) {
return wlr_output_layout_output_in_direction(layout, direction,
reference, ref_lx, ref_ly, NEAREST);
}

struct wlr_output *wlr_output_layout_farthest_output(
struct wlr_output_layout *layout, enum wlr_direction direction,
struct wlr_output *reference, double ref_lx, double ref_ly) {
return wlr_output_layout_output_in_direction(layout, direction,
reference, ref_lx, ref_ly, FARTHEST);
}

0 comments on commit c6955fa

Please sign in to comment.