aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Ashworth <RedSoxFan@users.noreply.github.com>2018-08-25 11:00:25 -0400
committerGitHub <noreply@github.com>2018-08-25 11:00:25 -0400
commitc6955fa89c36571bbddc87a7acd589e6cb0fe0a3 (patch)
tree14bc4a89130d74960447e9e5df3a4a4583ac82aa
parent6025fcaa098f8ca668893f29df5a9370804175a3 (diff)
parent5617d2bd6044a27e154ef61caf45896e2131fb3a (diff)
Merge pull request #1199 from apreiml/farthest_output
introduce wlr_output_layout_farthest_output
-rw-r--r--include/wlr/types/wlr_output_layout.h3
-rw-r--r--types/wlr_output_layout.c31
2 files changed, 30 insertions, 4 deletions
diff --git a/include/wlr/types/wlr_output_layout.h b/include/wlr/types/wlr_output_layout.h
index 2ac12a6a..cc9d2328 100644
--- a/include/wlr/types/wlr_output_layout.h
+++ b/include/wlr/types/wlr_output_layout.h
@@ -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
diff --git a/types/wlr_output_layout.c b/types/wlr_output_layout.c
index 5ad0c99e..e634d2b2 100644
--- a/types/wlr_output_layout.c
+++ b/types/wlr_output_layout.c
@@ -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) {
@@ -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);
+}
+