|
|
@ -1,16 +1,35 @@
|
|
|
|
#include <wlr/util/log.h>
|
|
|
|
#include <wlr/util/log.h>
|
|
|
|
#include <wlr/types/wlr_output.h>
|
|
|
|
#include <wlr/types/wlr_output.h>
|
|
|
|
#include <wlr/types/wlr_output_layout.h>
|
|
|
|
#include <wlr/types/wlr_output_layout.h>
|
|
|
|
|
|
|
|
#include <wlr/types/wlr_geometry.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct wlr_output_layout_state {
|
|
|
|
|
|
|
|
struct wlr_geometry *_geo;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct wlr_output_layout_output_state {
|
|
|
|
|
|
|
|
struct wlr_geometry *_geo;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct wlr_output_layout *wlr_output_layout_init() {
|
|
|
|
struct wlr_output_layout *wlr_output_layout_init() {
|
|
|
|
struct wlr_output_layout *layout = calloc(1, sizeof(struct wlr_output_layout));
|
|
|
|
struct wlr_output_layout *layout = calloc(1, sizeof(struct wlr_output_layout));
|
|
|
|
|
|
|
|
layout->state = calloc(1, sizeof(struct wlr_output_layout_state));
|
|
|
|
|
|
|
|
layout->state->_geo = calloc(1, sizeof(struct wlr_geometry));
|
|
|
|
wl_list_init(&layout->outputs);
|
|
|
|
wl_list_init(&layout->outputs);
|
|
|
|
return layout;
|
|
|
|
return layout;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void wlr_output_layout_output_destroy(
|
|
|
|
|
|
|
|
struct wlr_output_layout_output *l_output) {
|
|
|
|
|
|
|
|
wl_list_remove(&l_output->link);
|
|
|
|
|
|
|
|
free(l_output->state->_geo);
|
|
|
|
|
|
|
|
free(l_output->state);
|
|
|
|
|
|
|
|
free(l_output);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void wlr_output_layout_destroy(struct wlr_output_layout *layout) {
|
|
|
|
void wlr_output_layout_destroy(struct wlr_output_layout *layout) {
|
|
|
|
if (!layout) {
|
|
|
|
if (!layout) {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
@ -18,20 +37,24 @@ void wlr_output_layout_destroy(struct wlr_output_layout *layout) {
|
|
|
|
|
|
|
|
|
|
|
|
struct wlr_output_layout_output *_output, *temp = NULL;
|
|
|
|
struct wlr_output_layout_output *_output, *temp = NULL;
|
|
|
|
wl_list_for_each_safe(_output, temp, &layout->outputs, link) {
|
|
|
|
wl_list_for_each_safe(_output, temp, &layout->outputs, link) {
|
|
|
|
wl_list_remove(&_output->link);
|
|
|
|
wlr_output_layout_output_destroy(_output);
|
|
|
|
free(_output);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
free(layout->state->_geo);
|
|
|
|
|
|
|
|
free(layout->state);
|
|
|
|
free(layout);
|
|
|
|
free(layout);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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 x, int y) {
|
|
|
|
struct wlr_output_layout_output *layout_output = calloc(1, sizeof(struct wlr_output_layout_output));
|
|
|
|
struct wlr_output_layout_output *l_output;
|
|
|
|
layout_output->output = output;
|
|
|
|
l_output= calloc(1, sizeof(struct wlr_output_layout_output));
|
|
|
|
layout_output->x = x;
|
|
|
|
l_output->state = calloc(1, sizeof(struct wlr_output_layout_output_state));
|
|
|
|
layout_output->y = y;
|
|
|
|
l_output->state->_geo = calloc(1, sizeof(struct wlr_geometry));
|
|
|
|
wl_list_insert(&layout->outputs, &layout_output->link);
|
|
|
|
l_output->output = output;
|
|
|
|
|
|
|
|
l_output->x = x;
|
|
|
|
|
|
|
|
l_output->y = y;
|
|
|
|
|
|
|
|
wl_list_insert(&layout->outputs, &l_output->link);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
struct wlr_output_layout_output *wlr_output_layout_get(
|
|
|
|
struct wlr_output_layout_output *wlr_output_layout_get(
|
|
|
@ -104,11 +127,10 @@ void wlr_output_layout_move(struct wlr_output_layout *layout,
|
|
|
|
|
|
|
|
|
|
|
|
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) {
|
|
|
|
struct wlr_output_layout_output *layout_output =
|
|
|
|
struct wlr_output_layout_output *l_output;
|
|
|
|
wlr_output_layout_get(layout, output);
|
|
|
|
l_output= wlr_output_layout_get(layout, output);
|
|
|
|
if (layout_output) {
|
|
|
|
if (l_output) {
|
|
|
|
wl_list_remove(&layout_output->link);
|
|
|
|
wlr_output_layout_output_destroy(l_output);
|
|
|
|
free(layout_output);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -179,3 +201,46 @@ void wlr_output_layout_closest_boundary(struct wlr_output_layout *layout,
|
|
|
|
*dest_x = min_x;
|
|
|
|
*dest_x = min_x;
|
|
|
|
*dest_y = min_y;
|
|
|
|
*dest_y = min_y;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct wlr_geometry *wlr_output_layout_get_geometry(
|
|
|
|
|
|
|
|
struct wlr_output_layout *layout, struct wlr_output *reference) {
|
|
|
|
|
|
|
|
struct wlr_output_layout_output *l_output;
|
|
|
|
|
|
|
|
if (reference) {
|
|
|
|
|
|
|
|
// output extents
|
|
|
|
|
|
|
|
l_output= wlr_output_layout_get(layout, reference);
|
|
|
|
|
|
|
|
l_output->state->_geo->x = l_output->x;
|
|
|
|
|
|
|
|
l_output->state->_geo->y = l_output->y;
|
|
|
|
|
|
|
|
wlr_output_effective_resolution(reference,
|
|
|
|
|
|
|
|
&l_output->state->_geo->width, &l_output->state->_geo->height);
|
|
|
|
|
|
|
|
return l_output->state->_geo;
|
|
|
|
|
|
|
|
} 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) {
|
|
|
|
|
|
|
|
int width, height;
|
|
|
|
|
|
|
|
wlr_output_effective_resolution(l_output->output, &width, &height);
|
|
|
|
|
|
|
|
if (l_output->x < min_x) {
|
|
|
|
|
|
|
|
min_x = l_output->x;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (l_output->y < min_y) {
|
|
|
|
|
|
|
|
min_y = l_output->y;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (l_output->x + width > max_x) {
|
|
|
|
|
|
|
|
max_x = l_output->x + width;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (l_output->y + height > max_y) {
|
|
|
|
|
|
|
|
max_y = l_output->y + height;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
layout->state->_geo->x = min_x;
|
|
|
|
|
|
|
|
layout->state->_geo->y = min_y;
|
|
|
|
|
|
|
|
layout->state->_geo->width = max_x - min_x;
|
|
|
|
|
|
|
|
layout->state->_geo->height = max_y - min_y;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return layout->state->_geo;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// not reached
|
|
|
|
|
|
|
|
}
|
|
|
|