2017-08-24 14:11:57 +00:00
|
|
|
#include <limits.h>
|
2017-08-29 16:32:17 +00:00
|
|
|
#include <float.h>
|
2017-08-16 15:51:22 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <assert.h>
|
2018-02-12 08:12:31 +00:00
|
|
|
#include <wlr/util/log.h>
|
|
|
|
#include <wlr/util/signal.h>
|
|
|
|
#include <wlr/types/wlr_output.h>
|
|
|
|
#include <wlr/types/wlr_output_layout.h>
|
|
|
|
#include <wlr/types/wlr_box.h>
|
2017-08-16 15:51:22 +00:00
|
|
|
|
2017-08-27 21:35:12 +00:00
|
|
|
struct wlr_output_layout_state {
|
2017-10-31 11:01:49 +00:00
|
|
|
struct wlr_box _box; // should never be read directly, use the getter
|
2017-08-27 21:35:12 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct wlr_output_layout_output_state {
|
2017-08-30 14:39:22 +00:00
|
|
|
struct wlr_output_layout *layout;
|
2017-08-30 17:28:50 +00:00
|
|
|
struct wlr_output_layout_output *l_output;
|
|
|
|
|
2017-10-31 11:01:49 +00:00
|
|
|
struct wlr_box _box; // should never be read directly, use the getter
|
2017-08-30 14:39:22 +00:00
|
|
|
bool auto_configured;
|
2017-08-30 17:28:50 +00:00
|
|
|
|
2018-01-06 11:42:32 +00:00
|
|
|
struct wl_listener mode;
|
2017-12-12 20:58:00 +00:00
|
|
|
struct wl_listener scale;
|
|
|
|
struct wl_listener transform;
|
2017-08-30 17:28:50 +00:00
|
|
|
struct wl_listener output_destroy;
|
2017-08-27 21:35:12 +00:00
|
|
|
};
|
|
|
|
|
2017-09-05 21:53:29 +00:00
|
|
|
struct wlr_output_layout *wlr_output_layout_create() {
|
2017-08-29 13:59:03 +00:00
|
|
|
struct wlr_output_layout *layout =
|
|
|
|
calloc(1, sizeof(struct wlr_output_layout));
|
2017-10-31 10:29:53 +00:00
|
|
|
if (layout == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2017-08-27 21:35:12 +00:00
|
|
|
layout->state = calloc(1, sizeof(struct wlr_output_layout_state));
|
2017-10-31 10:29:53 +00:00
|
|
|
if (layout->state == NULL) {
|
|
|
|
free(layout);
|
|
|
|
return NULL;
|
|
|
|
}
|
2017-08-16 15:51:22 +00:00
|
|
|
wl_list_init(&layout->outputs);
|
2017-09-05 11:48:28 +00:00
|
|
|
|
2017-10-29 10:20:11 +00:00
|
|
|
wl_signal_init(&layout->events.add);
|
2017-09-05 11:48:28 +00:00
|
|
|
wl_signal_init(&layout->events.change);
|
|
|
|
wl_signal_init(&layout->events.destroy);
|
|
|
|
|
2017-08-16 15:51:22 +00:00
|
|
|
return layout;
|
|
|
|
}
|
|
|
|
|
2017-08-27 21:35:12 +00:00
|
|
|
static void wlr_output_layout_output_destroy(
|
|
|
|
struct wlr_output_layout_output *l_output) {
|
2018-02-12 08:12:31 +00:00
|
|
|
wlr_signal_emit_safe(&l_output->events.destroy, l_output);
|
2018-01-06 11:42:32 +00:00
|
|
|
wl_list_remove(&l_output->state->mode.link);
|
2017-12-12 20:58:00 +00:00
|
|
|
wl_list_remove(&l_output->state->scale.link);
|
|
|
|
wl_list_remove(&l_output->state->transform.link);
|
2017-08-30 17:28:50 +00:00
|
|
|
wl_list_remove(&l_output->state->output_destroy.link);
|
2017-08-29 13:59:03 +00:00
|
|
|
wl_list_remove(&l_output->link);
|
|
|
|
free(l_output->state);
|
|
|
|
free(l_output);
|
2017-08-27 21:35:12 +00:00
|
|
|
}
|
|
|
|
|
2017-08-16 15:51:22 +00:00
|
|
|
void wlr_output_layout_destroy(struct wlr_output_layout *layout) {
|
|
|
|
if (!layout) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-02-12 08:12:31 +00:00
|
|
|
wlr_signal_emit_safe(&layout->events.destroy, layout);
|
2017-09-05 11:48:28 +00:00
|
|
|
|
2017-10-31 11:01:49 +00:00
|
|
|
struct wlr_output_layout_output *l_output, *temp = NULL;
|
|
|
|
wl_list_for_each_safe(l_output, temp, &layout->outputs, link) {
|
|
|
|
wlr_output_layout_output_destroy(l_output);
|
2017-08-16 15:51:22 +00:00
|
|
|
}
|
|
|
|
|
2017-08-27 21:35:12 +00:00
|
|
|
free(layout->state);
|
2017-08-16 15:51:22 +00:00
|
|
|
free(layout);
|
|
|
|
}
|
|
|
|
|
2017-08-30 14:39:22 +00:00
|
|
|
static struct wlr_box *wlr_output_layout_output_get_box(
|
|
|
|
struct wlr_output_layout_output *l_output) {
|
2018-01-07 17:40:58 +00:00
|
|
|
l_output->state->_box.x = l_output->x;
|
|
|
|
l_output->state->_box.y = l_output->y;
|
|
|
|
int width, height;
|
|
|
|
wlr_output_effective_resolution(l_output->output, &width, &height);
|
|
|
|
l_output->state->_box.width = width;
|
|
|
|
l_output->state->_box.height = height;
|
2017-10-31 11:01:49 +00:00
|
|
|
return &l_output->state->_box;
|
2017-08-30 14:39:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This must be called whenever the layout changes to reconfigure the auto
|
2017-09-05 11:48:28 +00:00
|
|
|
* configured outputs and emit the `changed` event.
|
2017-08-30 14:39:22 +00:00
|
|
|
*
|
|
|
|
* Auto configured outputs are placed to the right of the north east corner of
|
|
|
|
* the rightmost output in the layout in a horizontal line.
|
|
|
|
*/
|
|
|
|
static void wlr_output_layout_reconfigure(struct wlr_output_layout *layout) {
|
|
|
|
int max_x = INT_MIN;
|
|
|
|
int max_x_y = INT_MIN; // y value for the max_x output
|
|
|
|
|
|
|
|
// find the rightmost x coordinate occupied by a manually configured output
|
|
|
|
// in the layout
|
|
|
|
struct wlr_output_layout_output *l_output;
|
|
|
|
wl_list_for_each(l_output, &layout->outputs, link) {
|
2018-01-07 17:40:58 +00:00
|
|
|
if (l_output->state->auto_configured) {
|
2017-08-30 14:39:22 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct wlr_box *box = wlr_output_layout_output_get_box(l_output);
|
|
|
|
if (box->x + box->width > max_x) {
|
|
|
|
max_x = box->x + box->width;
|
|
|
|
max_x_y = box->y;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (max_x == INT_MIN) {
|
|
|
|
// there are no manually configured outputs
|
|
|
|
max_x = 0;
|
|
|
|
max_x_y = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
wl_list_for_each(l_output, &layout->outputs, link) {
|
2018-01-07 17:40:58 +00:00
|
|
|
if (!l_output->state->auto_configured) {
|
2017-08-30 14:39:22 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
struct wlr_box *box = wlr_output_layout_output_get_box(l_output);
|
|
|
|
l_output->x = max_x;
|
|
|
|
l_output->y = max_x_y;
|
|
|
|
max_x += box->width;
|
|
|
|
}
|
2017-09-05 11:48:28 +00:00
|
|
|
|
2017-10-19 16:57:45 +00:00
|
|
|
wl_list_for_each(l_output, &layout->outputs, link) {
|
|
|
|
wlr_output_set_position(l_output->output, l_output->x, l_output->y);
|
|
|
|
}
|
|
|
|
|
2018-02-12 08:12:31 +00:00
|
|
|
wlr_signal_emit_safe(&layout->events.change, layout);
|
2017-08-30 14:39:22 +00:00
|
|
|
}
|
|
|
|
|
2018-01-06 11:42:32 +00:00
|
|
|
static void handle_output_mode(struct wl_listener *listener, void *data) {
|
2017-08-30 14:39:22 +00:00
|
|
|
struct wlr_output_layout_output_state *state =
|
2018-01-06 11:42:32 +00:00
|
|
|
wl_container_of(listener, state, mode);
|
2017-08-30 14:39:22 +00:00
|
|
|
wlr_output_layout_reconfigure(state->layout);
|
|
|
|
}
|
|
|
|
|
2017-12-12 20:58:00 +00:00
|
|
|
static void handle_output_scale(struct wl_listener *listener, void *data) {
|
|
|
|
struct wlr_output_layout_output_state *state =
|
|
|
|
wl_container_of(listener, state, scale);
|
|
|
|
wlr_output_layout_reconfigure(state->layout);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void handle_output_transform(struct wl_listener *listener, void *data) {
|
|
|
|
struct wlr_output_layout_output_state *state =
|
|
|
|
wl_container_of(listener, state, transform);
|
|
|
|
wlr_output_layout_reconfigure(state->layout);
|
|
|
|
}
|
|
|
|
|
2017-08-30 17:28:50 +00:00
|
|
|
static void handle_output_destroy(struct wl_listener *listener, void *data) {
|
|
|
|
struct wlr_output_layout_output_state *state =
|
|
|
|
wl_container_of(listener, state, output_destroy);
|
|
|
|
struct wlr_output_layout *layout = state->layout;
|
|
|
|
wlr_output_layout_output_destroy(state->l_output);
|
|
|
|
wlr_output_layout_reconfigure(layout);
|
|
|
|
}
|
|
|
|
|
2017-08-30 14:39:22 +00:00
|
|
|
static struct wlr_output_layout_output *wlr_output_layout_output_create(
|
|
|
|
struct wlr_output_layout *layout, struct wlr_output *output) {
|
2017-10-31 10:29:53 +00:00
|
|
|
struct wlr_output_layout_output *l_output =
|
|
|
|
calloc(1, sizeof(struct wlr_output_layout_output));
|
|
|
|
if (l_output == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2017-08-27 21:35:12 +00:00
|
|
|
l_output->state = calloc(1, sizeof(struct wlr_output_layout_output_state));
|
2017-10-31 10:29:53 +00:00
|
|
|
if (l_output->state == NULL) {
|
|
|
|
free(l_output);
|
|
|
|
return NULL;
|
|
|
|
}
|
2017-08-30 17:28:50 +00:00
|
|
|
l_output->state->l_output = l_output;
|
2017-08-30 14:39:22 +00:00
|
|
|
l_output->state->layout = layout;
|
2017-08-27 21:35:12 +00:00
|
|
|
l_output->output = output;
|
2017-10-29 10:20:11 +00:00
|
|
|
wl_signal_init(&l_output->events.destroy);
|
2017-08-30 14:39:22 +00:00
|
|
|
wl_list_insert(&layout->outputs, &l_output->link);
|
|
|
|
|
2018-01-06 11:42:32 +00:00
|
|
|
wl_signal_add(&output->events.mode, &l_output->state->mode);
|
|
|
|
l_output->state->mode.notify = handle_output_mode;
|
2017-12-12 20:58:00 +00:00
|
|
|
wl_signal_add(&output->events.scale, &l_output->state->scale);
|
|
|
|
l_output->state->scale.notify = handle_output_scale;
|
|
|
|
wl_signal_add(&output->events.transform, &l_output->state->transform);
|
|
|
|
l_output->state->transform.notify = handle_output_transform;
|
2017-08-30 17:28:50 +00:00
|
|
|
wl_signal_add(&output->events.destroy, &l_output->state->output_destroy);
|
|
|
|
l_output->state->output_destroy.notify = handle_output_destroy;
|
|
|
|
|
2017-08-30 14:39:22 +00:00
|
|
|
return l_output;
|
|
|
|
}
|
|
|
|
|
|
|
|
void wlr_output_layout_add(struct wlr_output_layout *layout,
|
|
|
|
struct wlr_output *output, int x, int y) {
|
|
|
|
struct wlr_output_layout_output *l_output =
|
|
|
|
wlr_output_layout_get(layout, output);
|
|
|
|
if (!l_output) {
|
|
|
|
l_output = wlr_output_layout_output_create(layout, output);
|
2017-10-31 10:29:53 +00:00
|
|
|
if (!l_output) {
|
|
|
|
wlr_log(L_ERROR, "Failed to create wlr_output_layout_output");
|
|
|
|
return;
|
|
|
|
}
|
2017-08-30 14:39:22 +00:00
|
|
|
}
|
2017-08-27 21:35:12 +00:00
|
|
|
l_output->x = x;
|
|
|
|
l_output->y = y;
|
2017-08-30 14:39:22 +00:00
|
|
|
l_output->state->auto_configured = false;
|
|
|
|
wlr_output_layout_reconfigure(layout);
|
2018-01-23 16:40:12 +00:00
|
|
|
wlr_output_create_global(output);
|
2018-02-12 08:12:31 +00:00
|
|
|
wlr_signal_emit_safe(&layout->events.add, l_output);
|
2017-08-16 15:51:22 +00:00
|
|
|
}
|
|
|
|
|
2017-08-16 19:00:15 +00:00
|
|
|
struct wlr_output_layout_output *wlr_output_layout_get(
|
2017-08-16 15:51:22 +00:00
|
|
|
struct wlr_output_layout *layout, struct wlr_output *reference) {
|
2017-08-29 13:59:03 +00:00
|
|
|
struct wlr_output_layout_output *l_output;
|
|
|
|
wl_list_for_each(l_output, &layout->outputs, link) {
|
|
|
|
if (l_output->output == reference) {
|
|
|
|
return l_output;
|
2017-08-16 15:51:22 +00:00
|
|
|
}
|
|
|
|
}
|
2017-08-18 01:04:05 +00:00
|
|
|
return NULL;
|
2017-08-16 15:51:22 +00:00
|
|
|
}
|
|
|
|
|
2017-08-17 14:12:36 +00:00
|
|
|
bool wlr_output_layout_contains_point(struct wlr_output_layout *layout,
|
|
|
|
struct wlr_output *reference, int x, int y) {
|
2017-08-28 00:10:46 +00:00
|
|
|
if (reference) {
|
2017-08-30 15:11:31 +00:00
|
|
|
struct wlr_output_layout_output *l_output =
|
2017-08-29 13:59:03 +00:00
|
|
|
wlr_output_layout_get(layout, reference);
|
2017-08-30 15:11:31 +00:00
|
|
|
struct wlr_box *box = wlr_output_layout_output_get_box(l_output);
|
|
|
|
return wlr_box_contains_point(box, x, y);
|
2017-08-28 00:10:46 +00:00
|
|
|
} else {
|
|
|
|
return !!wlr_output_layout_output_at(layout, x, y);
|
|
|
|
}
|
2017-08-17 14:12:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool wlr_output_layout_intersects(struct wlr_output_layout *layout,
|
2017-12-31 11:49:06 +00:00
|
|
|
struct wlr_output *reference, const struct wlr_box *target_box) {
|
|
|
|
struct wlr_box out_box;
|
|
|
|
|
|
|
|
if (reference == NULL) {
|
|
|
|
struct wlr_output_layout_output *l_output;
|
|
|
|
wl_list_for_each(l_output, &layout->outputs, link) {
|
|
|
|
struct wlr_box *output_box =
|
|
|
|
wlr_output_layout_output_get_box(l_output);
|
|
|
|
if (wlr_box_intersection(output_box, target_box, &out_box)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2017-08-17 14:12:36 +00:00
|
|
|
return false;
|
2017-12-31 11:49:06 +00:00
|
|
|
} else {
|
|
|
|
struct wlr_output_layout_output *l_output =
|
|
|
|
wlr_output_layout_get(layout, reference);
|
|
|
|
if (!l_output) {
|
|
|
|
return false;
|
|
|
|
}
|
2017-10-10 18:05:10 +00:00
|
|
|
|
2017-12-31 11:49:06 +00:00
|
|
|
struct wlr_box *output_box = wlr_output_layout_output_get_box(l_output);
|
|
|
|
return wlr_box_intersection(output_box, target_box, &out_box);
|
|
|
|
}
|
2017-08-17 14:12:36 +00:00
|
|
|
}
|
|
|
|
|
2017-08-16 15:51:22 +00:00
|
|
|
struct wlr_output *wlr_output_layout_output_at(struct wlr_output_layout *layout,
|
|
|
|
double x, double y) {
|
2017-08-29 13:59:03 +00:00
|
|
|
struct wlr_output_layout_output *l_output;
|
|
|
|
wl_list_for_each(l_output, &layout->outputs, link) {
|
2017-12-31 11:49:06 +00:00
|
|
|
struct wlr_box *box = wlr_output_layout_output_get_box(l_output);
|
|
|
|
if (wlr_box_contains_point(box, x, y)) {
|
|
|
|
return l_output->output;
|
2017-08-16 15:51:22 +00:00
|
|
|
}
|
|
|
|
}
|
2017-08-18 01:04:05 +00:00
|
|
|
return NULL;
|
2017-08-16 15:51:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void wlr_output_layout_move(struct wlr_output_layout *layout,
|
|
|
|
struct wlr_output *output, int x, int y) {
|
2017-08-29 13:59:03 +00:00
|
|
|
struct wlr_output_layout_output *l_output =
|
|
|
|
wlr_output_layout_get(layout, output);
|
|
|
|
if (l_output) {
|
|
|
|
l_output->x = x;
|
|
|
|
l_output->y = y;
|
2017-08-30 14:39:22 +00:00
|
|
|
l_output->state->auto_configured = false;
|
|
|
|
wlr_output_layout_reconfigure(layout);
|
|
|
|
} else {
|
|
|
|
wlr_log(L_ERROR, "output not found in this layout: %s", output->name);
|
2017-08-16 15:51:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void wlr_output_layout_remove(struct wlr_output_layout *layout,
|
|
|
|
struct wlr_output *output) {
|
2017-10-31 10:29:53 +00:00
|
|
|
struct wlr_output_layout_output *l_output =
|
|
|
|
wlr_output_layout_get(layout, output);
|
2017-08-27 21:35:12 +00:00
|
|
|
if (l_output) {
|
|
|
|
wlr_output_layout_output_destroy(l_output);
|
2017-08-30 14:39:22 +00:00
|
|
|
wlr_output_layout_reconfigure(layout);
|
2017-08-16 15:51:22 +00:00
|
|
|
}
|
2018-01-23 16:40:12 +00:00
|
|
|
wlr_output_destroy_global(output);
|
2017-08-16 15:51:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void wlr_output_layout_output_coords(struct wlr_output_layout *layout,
|
2017-08-24 15:46:40 +00:00
|
|
|
struct wlr_output *reference, double *x, double *y) {
|
2017-08-16 15:51:22 +00:00
|
|
|
assert(layout && reference);
|
2017-08-24 15:46:40 +00:00
|
|
|
double src_x = *x;
|
|
|
|
double src_y = *y;
|
2017-08-16 15:51:22 +00:00
|
|
|
|
2017-08-29 13:59:03 +00:00
|
|
|
struct wlr_output_layout_output *l_output;
|
|
|
|
wl_list_for_each(l_output, &layout->outputs, link) {
|
|
|
|
if (l_output->output == reference) {
|
|
|
|
*x = src_x - (double)l_output->x;
|
|
|
|
*y = src_y - (double)l_output->y;
|
2017-08-16 15:51:22 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-08-24 14:11:57 +00:00
|
|
|
|
2017-08-29 16:32:17 +00:00
|
|
|
void wlr_output_layout_closest_point(struct wlr_output_layout *layout,
|
2017-08-24 16:30:34 +00:00
|
|
|
struct wlr_output *reference, double x, double y, double *dest_x,
|
|
|
|
double *dest_y) {
|
2017-08-29 16:32:17 +00:00
|
|
|
double min_x = DBL_MAX, min_y = DBL_MAX, min_distance = DBL_MAX;
|
2017-08-24 14:11:57 +00:00
|
|
|
struct wlr_output_layout_output *l_output;
|
|
|
|
wl_list_for_each(l_output, &layout->outputs, link) {
|
2017-08-24 16:30:34 +00:00
|
|
|
if (reference != NULL && reference != l_output->output) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
double output_x, output_y, output_distance;
|
2017-08-29 16:32:17 +00:00
|
|
|
struct wlr_box *box = wlr_output_layout_output_get_box(l_output);
|
|
|
|
wlr_box_closest_point(box, x, y, &output_x, &output_y);
|
2017-08-24 14:11:57 +00:00
|
|
|
|
2017-08-29 16:32:17 +00:00
|
|
|
// calculate squared distance suitable for comparison
|
|
|
|
output_distance =
|
|
|
|
(x - output_x) * (x - output_x) + (y - output_y) * (y - output_y);
|
2017-08-24 14:11:57 +00:00
|
|
|
|
2018-02-01 19:29:03 +00:00
|
|
|
if (!isfinite(output_distance)) {
|
|
|
|
output_distance = DBL_MAX;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (output_distance <= min_distance) {
|
2017-08-24 14:11:57 +00:00
|
|
|
min_x = output_x;
|
|
|
|
min_y = output_y;
|
|
|
|
min_distance = output_distance;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*dest_x = min_x;
|
|
|
|
*dest_y = min_y;
|
|
|
|
}
|
2017-08-27 21:35:12 +00:00
|
|
|
|
2017-08-29 16:08:49 +00:00
|
|
|
struct wlr_box *wlr_output_layout_get_box(
|
2017-08-27 21:35:12 +00:00
|
|
|
struct wlr_output_layout *layout, struct wlr_output *reference) {
|
|
|
|
struct wlr_output_layout_output *l_output;
|
|
|
|
if (reference) {
|
|
|
|
// output extents
|
2017-08-30 15:11:31 +00:00
|
|
|
l_output = wlr_output_layout_get(layout, reference);
|
|
|
|
|
|
|
|
if (l_output) {
|
|
|
|
return wlr_output_layout_output_get_box(l_output);
|
|
|
|
} else {
|
|
|
|
return NULL;
|
|
|
|
}
|
2017-08-27 21:35:12 +00:00
|
|
|
} else {
|
|
|
|
// layout extents
|
|
|
|
int min_x = INT_MAX, min_y = INT_MAX;
|
|
|
|
int max_x = INT_MIN, max_y = INT_MIN;
|
|
|
|
wl_list_for_each(l_output, &layout->outputs, link) {
|
2017-08-30 15:11:31 +00:00
|
|
|
struct wlr_box *box = wlr_output_layout_output_get_box(l_output);
|
|
|
|
|
|
|
|
if (box->x < min_x) {
|
|
|
|
min_x = box->x;
|
2017-08-27 21:35:12 +00:00
|
|
|
}
|
2017-08-30 15:11:31 +00:00
|
|
|
if (box->y < min_y) {
|
|
|
|
min_y = box->y;
|
2017-08-27 21:35:12 +00:00
|
|
|
}
|
2017-08-30 15:11:31 +00:00
|
|
|
if (box->x + box->width > max_x) {
|
|
|
|
max_x = box->x + box->width;
|
2017-08-27 21:35:12 +00:00
|
|
|
}
|
2017-08-30 15:11:31 +00:00
|
|
|
if (box->y + box->height > max_y) {
|
|
|
|
max_y = box->y + box->height;
|
2017-08-27 21:35:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-31 11:01:49 +00:00
|
|
|
layout->state->_box.x = min_x;
|
|
|
|
layout->state->_box.y = min_y;
|
|
|
|
layout->state->_box.width = max_x - min_x;
|
|
|
|
layout->state->_box.height = max_y - min_y;
|
2017-08-27 21:35:12 +00:00
|
|
|
|
2017-10-31 11:01:49 +00:00
|
|
|
return &layout->state->_box;
|
2017-08-27 21:35:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// not reached
|
|
|
|
}
|
2017-08-30 14:39:22 +00:00
|
|
|
|
|
|
|
void wlr_output_layout_add_auto(struct wlr_output_layout *layout,
|
|
|
|
struct wlr_output *output) {
|
|
|
|
struct wlr_output_layout_output *l_output =
|
|
|
|
wlr_output_layout_get(layout, output);
|
|
|
|
if (!l_output) {
|
|
|
|
l_output = wlr_output_layout_output_create(layout, output);
|
2017-10-31 10:29:53 +00:00
|
|
|
if (!l_output) {
|
|
|
|
wlr_log(L_ERROR, "Failed to create wlr_output_layout_output");
|
|
|
|
return;
|
|
|
|
}
|
2017-08-30 14:39:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
l_output->state->auto_configured = true;
|
|
|
|
wlr_output_layout_reconfigure(layout);
|
2018-01-23 16:40:12 +00:00
|
|
|
wlr_output_create_global(output);
|
2018-02-12 08:12:31 +00:00
|
|
|
wlr_signal_emit_safe(&layout->events.add, l_output);
|
2017-08-30 14:39:22 +00:00
|
|
|
}
|
2017-10-16 18:35:16 +00:00
|
|
|
|
|
|
|
struct wlr_output *wlr_output_layout_get_center_output(
|
|
|
|
struct wlr_output_layout *layout) {
|
|
|
|
if (wl_list_empty(&layout->outputs)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct wlr_box *extents = wlr_output_layout_get_box(layout, NULL);
|
|
|
|
double center_x = extents->width / 2 + extents->x;
|
|
|
|
double center_y = extents->height / 2 + extents->y;
|
|
|
|
|
|
|
|
double dest_x = 0, dest_y = 0;
|
|
|
|
wlr_output_layout_closest_point(layout, NULL, center_x, center_y,
|
|
|
|
&dest_x, &dest_y);
|
|
|
|
|
|
|
|
return wlr_output_layout_output_at(layout, dest_x, dest_y);
|
|
|
|
}
|