|
|
@ -12,7 +12,14 @@ struct wlr_output_layout_state {
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct wlr_output_layout_output_state {
|
|
|
|
struct wlr_output_layout_output_state {
|
|
|
|
|
|
|
|
struct wlr_output_layout *layout;
|
|
|
|
|
|
|
|
struct wlr_output_layout_output *l_output;
|
|
|
|
|
|
|
|
|
|
|
|
struct wlr_box *_box;
|
|
|
|
struct wlr_box *_box;
|
|
|
|
|
|
|
|
bool auto_configured;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct wl_listener resolution;
|
|
|
|
|
|
|
|
struct wl_listener output_destroy;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct wlr_output_layout *wlr_output_layout_init() {
|
|
|
|
struct wlr_output_layout *wlr_output_layout_init() {
|
|
|
@ -26,6 +33,8 @@ struct wlr_output_layout *wlr_output_layout_init() {
|
|
|
|
|
|
|
|
|
|
|
|
static void wlr_output_layout_output_destroy(
|
|
|
|
static void wlr_output_layout_output_destroy(
|
|
|
|
struct wlr_output_layout_output *l_output) {
|
|
|
|
struct wlr_output_layout_output *l_output) {
|
|
|
|
|
|
|
|
wl_list_remove(&l_output->state->resolution.link);
|
|
|
|
|
|
|
|
wl_list_remove(&l_output->state->output_destroy.link);
|
|
|
|
wl_list_remove(&l_output->link);
|
|
|
|
wl_list_remove(&l_output->link);
|
|
|
|
free(l_output->state->_box);
|
|
|
|
free(l_output->state->_box);
|
|
|
|
free(l_output->state);
|
|
|
|
free(l_output->state);
|
|
|
@ -47,16 +56,105 @@ void wlr_output_layout_destroy(struct wlr_output_layout *layout) {
|
|
|
|
free(layout);
|
|
|
|
free(layout);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void wlr_output_layout_add(struct wlr_output_layout *layout,
|
|
|
|
static struct wlr_box *wlr_output_layout_output_get_box(
|
|
|
|
struct wlr_output *output, int x, int y) {
|
|
|
|
struct wlr_output_layout_output *l_output) {
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
return l_output->state->_box;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* This must be called whenever the layout changes to reconfigure the auto
|
|
|
|
|
|
|
|
* configured outputs.
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* 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) {
|
|
|
|
|
|
|
|
if (l_output->state->auto_configured) {
|
|
|
|
|
|
|
|
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) {
|
|
|
|
|
|
|
|
if (!l_output->state->auto_configured) {
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void handle_output_resolution(struct wl_listener *listener, void *data) {
|
|
|
|
|
|
|
|
struct wlr_output_layout_output_state *state =
|
|
|
|
|
|
|
|
wl_container_of(listener, state, resolution);
|
|
|
|
|
|
|
|
wlr_output_layout_reconfigure(state->layout);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static struct wlr_output_layout_output *wlr_output_layout_output_create(
|
|
|
|
|
|
|
|
struct wlr_output_layout *layout, struct wlr_output *output) {
|
|
|
|
struct wlr_output_layout_output *l_output;
|
|
|
|
struct wlr_output_layout_output *l_output;
|
|
|
|
l_output= calloc(1, sizeof(struct wlr_output_layout_output));
|
|
|
|
l_output= calloc(1, sizeof(struct wlr_output_layout_output));
|
|
|
|
l_output->state = calloc(1, sizeof(struct wlr_output_layout_output_state));
|
|
|
|
l_output->state = calloc(1, sizeof(struct wlr_output_layout_output_state));
|
|
|
|
|
|
|
|
l_output->state->l_output = l_output;
|
|
|
|
l_output->state->_box = calloc(1, sizeof(struct wlr_box));
|
|
|
|
l_output->state->_box = calloc(1, sizeof(struct wlr_box));
|
|
|
|
|
|
|
|
l_output->state->layout = layout;
|
|
|
|
l_output->output = output;
|
|
|
|
l_output->output = output;
|
|
|
|
|
|
|
|
wl_list_insert(&layout->outputs, &l_output->link);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
wl_signal_add(&output->events.resolution, &l_output->state->resolution);
|
|
|
|
|
|
|
|
l_output->state->resolution.notify = handle_output_resolution;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
wl_signal_add(&output->events.destroy, &l_output->state->output_destroy);
|
|
|
|
|
|
|
|
l_output->state->output_destroy.notify = handle_output_destroy;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
}
|
|
|
|
l_output->x = x;
|
|
|
|
l_output->x = x;
|
|
|
|
l_output->y = y;
|
|
|
|
l_output->y = y;
|
|
|
|
wl_list_insert(&layout->outputs, &l_output->link);
|
|
|
|
l_output->state->auto_configured = false;
|
|
|
|
|
|
|
|
wlr_output_layout_reconfigure(layout);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
struct wlr_output_layout_output *wlr_output_layout_get(
|
|
|
|
struct wlr_output_layout_output *wlr_output_layout_get(
|
|
|
@ -70,20 +168,13 @@ struct wlr_output_layout_output *wlr_output_layout_get(
|
|
|
|
return NULL;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static bool output_contains_point( struct wlr_output_layout_output *l_output,
|
|
|
|
|
|
|
|
int x, int y, int width, int height) {
|
|
|
|
|
|
|
|
return x >= l_output->x && x <= l_output->x + width &&
|
|
|
|
|
|
|
|
y >= l_output->y && y <= l_output->y + height;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 x, int y) {
|
|
|
|
if (reference) {
|
|
|
|
if (reference) {
|
|
|
|
struct wlr_output_layout_output *layout_output =
|
|
|
|
struct wlr_output_layout_output *l_output =
|
|
|
|
wlr_output_layout_get(layout, reference);
|
|
|
|
wlr_output_layout_get(layout, reference);
|
|
|
|
int width, height;
|
|
|
|
struct wlr_box *box = wlr_output_layout_output_get_box(l_output);
|
|
|
|
wlr_output_effective_resolution(layout_output->output, &width, &height);
|
|
|
|
return wlr_box_contains_point(box, x, y);
|
|
|
|
return output_contains_point(layout_output, x, y, width, height);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
return !!wlr_output_layout_output_at(layout, x, y);
|
|
|
|
return !!wlr_output_layout_output_at(layout, x, y);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -93,17 +184,17 @@ bool wlr_output_layout_intersects(struct wlr_output_layout *layout,
|
|
|
|
struct wlr_output *reference, int x1, int y1, int x2, int y2) {
|
|
|
|
struct wlr_output *reference, int x1, int y1, int x2, int y2) {
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
|
|
if (!l_output) {
|
|
|
|
if (!l_output) {
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
int width, height;
|
|
|
|
|
|
|
|
wlr_output_effective_resolution(l_output->output, &width, &height);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// the output must contain one of the points
|
|
|
|
// the output box must contain one of the points
|
|
|
|
return output_contains_point(l_output, x1, y1, width, height) ||
|
|
|
|
struct wlr_box *box = wlr_output_layout_output_get_box(l_output);
|
|
|
|
output_contains_point(l_output, x2, y2, width, height) ||
|
|
|
|
return wlr_box_contains_point(box, x1, y1) ||
|
|
|
|
output_contains_point(l_output, x2, y1, width, height) ||
|
|
|
|
wlr_box_contains_point(box, x2, y2) ||
|
|
|
|
output_contains_point(l_output, y2, x1, width, height);
|
|
|
|
wlr_box_contains_point(box, x2, y1) ||
|
|
|
|
|
|
|
|
wlr_box_contains_point(box, y2, x1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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,
|
|
|
@ -111,11 +202,8 @@ struct wlr_output *wlr_output_layout_output_at(struct wlr_output_layout *layout,
|
|
|
|
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) {
|
|
|
|
if (l_output->output) {
|
|
|
|
int width, height;
|
|
|
|
struct wlr_box *box = wlr_output_layout_output_get_box(l_output);
|
|
|
|
wlr_output_effective_resolution(l_output->output, &width, &height);
|
|
|
|
if (wlr_box_contains_point(box, x, y)) {
|
|
|
|
bool has_x = x >= l_output->x && x <= l_output->x + width;
|
|
|
|
|
|
|
|
bool has_y = y >= l_output->y && y <= l_output->y + height;
|
|
|
|
|
|
|
|
if (has_x && has_y) {
|
|
|
|
|
|
|
|
return l_output->output;
|
|
|
|
return l_output->output;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -130,6 +218,10 @@ void wlr_output_layout_move(struct wlr_output_layout *layout,
|
|
|
|
if (l_output) {
|
|
|
|
if (l_output) {
|
|
|
|
l_output->x = x;
|
|
|
|
l_output->x = x;
|
|
|
|
l_output->y = y;
|
|
|
|
l_output->y = y;
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -139,6 +231,7 @@ void wlr_output_layout_remove(struct wlr_output_layout *layout,
|
|
|
|
l_output= wlr_output_layout_get(layout, output);
|
|
|
|
l_output= wlr_output_layout_get(layout, output);
|
|
|
|
if (l_output) {
|
|
|
|
if (l_output) {
|
|
|
|
wlr_output_layout_output_destroy(l_output);
|
|
|
|
wlr_output_layout_output_destroy(l_output);
|
|
|
|
|
|
|
|
wlr_output_layout_reconfigure(layout);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -158,15 +251,6 @@ void wlr_output_layout_output_coords(struct wlr_output_layout *layout,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static struct wlr_box *wlr_output_layout_output_get_box(
|
|
|
|
|
|
|
|
struct wlr_output_layout_output *l_output) {
|
|
|
|
|
|
|
|
l_output->state->_box->x = l_output->x;
|
|
|
|
|
|
|
|
l_output->state->_box->y = l_output->y;
|
|
|
|
|
|
|
|
wlr_output_effective_resolution(l_output->output,
|
|
|
|
|
|
|
|
&l_output->state->_box->width, &l_output->state->_box->height);
|
|
|
|
|
|
|
|
return l_output->state->_box;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 x, double y, double *dest_x,
|
|
|
|
double *dest_y) {
|
|
|
|
double *dest_y) {
|
|
|
@ -202,25 +286,30 @@ struct wlr_box *wlr_output_layout_get_box(
|
|
|
|
if (reference) {
|
|
|
|
if (reference) {
|
|
|
|
// output extents
|
|
|
|
// output extents
|
|
|
|
l_output = wlr_output_layout_get(layout, reference);
|
|
|
|
l_output = wlr_output_layout_get(layout, reference);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (l_output) {
|
|
|
|
return wlr_output_layout_output_get_box(l_output);
|
|
|
|
return wlr_output_layout_output_get_box(l_output);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
// layout extents
|
|
|
|
// layout extents
|
|
|
|
int min_x = INT_MAX, min_y = INT_MAX;
|
|
|
|
int min_x = INT_MAX, min_y = INT_MAX;
|
|
|
|
int max_x = INT_MIN, max_y = INT_MIN;
|
|
|
|
int max_x = INT_MIN, max_y = INT_MIN;
|
|
|
|
wl_list_for_each(l_output, &layout->outputs, link) {
|
|
|
|
wl_list_for_each(l_output, &layout->outputs, link) {
|
|
|
|
int width, height;
|
|
|
|
struct wlr_box *box = wlr_output_layout_output_get_box(l_output);
|
|
|
|
wlr_output_effective_resolution(l_output->output, &width, &height);
|
|
|
|
|
|
|
|
if (l_output->x < min_x) {
|
|
|
|
if (box->x < min_x) {
|
|
|
|
min_x = l_output->x;
|
|
|
|
min_x = box->x;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (l_output->y < min_y) {
|
|
|
|
if (box->y < min_y) {
|
|
|
|
min_y = l_output->y;
|
|
|
|
min_y = box->y;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (l_output->x + width > max_x) {
|
|
|
|
if (box->x + box->width > max_x) {
|
|
|
|
max_x = l_output->x + width;
|
|
|
|
max_x = box->x + box->width;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (l_output->y + height > max_y) {
|
|
|
|
if (box->y + box->height > max_y) {
|
|
|
|
max_y = l_output->y + height;
|
|
|
|
max_y = box->y + box->height;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -234,3 +323,16 @@ struct wlr_box *wlr_output_layout_get_box(
|
|
|
|
|
|
|
|
|
|
|
|
// not reached
|
|
|
|
// not reached
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
l_output->state->auto_configured = true;
|
|
|
|
|
|
|
|
wlr_output_layout_reconfigure(layout);
|
|
|
|
|
|
|
|
}
|
|
|
|